cloud-8.x-2.0-beta1/modules/cloud_service_providers/k8s/src/Entity/K8sPod.php
modules/cloud_service_providers/k8s/src/Entity/K8sPod.php
<?php
namespace Drupal\k8s\Entity;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Defines the Pod entity.
*
* @ingroup k8s
*
* @ContentEntityType(
* id = "k8s_pod",
* label = @Translation("Kubernetes Pod"),
* handlers = {
* "view_builder" = "Drupal\k8s\Entity\K8sPodViewBuilder",
* "list_builder" = "Drupal\cloud\Controller\CloudContentListBuilder",
* "views_data" = "Drupal\k8s\Entity\K8sPodViewsData",
* "access" = "Drupal\k8s\Controller\K8sPodAccessControlHandler",
* "form" = {
* "add" = "Drupal\k8s\Form\K8sCreateForm",
* "edit" = "Drupal\k8s\Form\K8sEditForm",
* "delete" = "Drupal\k8s\Form\K8sDeleteForm",
* "log" = "Drupal\k8s\Form\K8sPodLogForm",
* "delete-multiple-confirm" = "Drupal\k8s\Form\K8sDeleteMultipleForm",
* },
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
* },
* },
* base_table = "k8s_pod",
* admin_permission = "administer k8s pod",
* fieldable = TRUE,
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* },
* links = {
* "canonical" = "/clouds/k8s/{cloud_context}/pod/{k8s_pod}",
* "collection" = "/clouds/k8s/{cloud_context}/pod",
* "add-form" = "/clouds/k8s/{cloud_context}/pod/add",
* "edit-form" = "/clouds/k8s/{cloud_context}/pod/{k8s_pod}/edit",
* "delete-form" = "/clouds/k8s/{cloud_context}/pod/{k8s_pod}/delete",
* "log-form" = "/clouds/k8s/{cloud_context}/pod/{k8s_pod}/log",
* "delete-multiple-form" = "/clouds/k8s/{cloud_context}/pod/delete_multiple",
* },
* field_ui_base_route = "k8s_pod.settings"
* )
*/
class K8sPod extends K8sEntityBase implements K8sPodInterface {
/**
* {@inheritdoc}
*/
public function getName() {
return $this->get('name')->value;
}
/**
* {@inheritdoc}
*/
public function setName($name) {
return $this->set('name', $name);
}
/**
* {@inheritdoc}
*/
public function getNamespace() {
return $this->get('namespace')->value;
}
/**
* {@inheritdoc}
*/
public function setNamespace($namespace) {
return $this->set('namespace', $namespace);
}
/**
* {@inheritdoc}
*/
public function getLabels() {
return $this->get('labels');
}
/**
* {@inheritdoc}
*/
public function setLabels($labels) {
return $this->set('labels', $labels);
}
/**
* {@inheritdoc}
*/
public function getAnnotations() {
return $this->get('annotations');
}
/**
* {@inheritdoc}
*/
public function setAnnotations($annotations) {
return $this->set('annotations', $annotations);
}
/**
* {@inheritdoc}
*/
public function getStatus() {
return $this->get('status')->value;
}
/**
* {@inheritdoc}
*/
public function setStatus($status) {
return $this->set('status', $status);
}
/**
* {@inheritdoc}
*/
public function getQosClass() {
return $this->get('qos_class')->value;
}
/**
* {@inheritdoc}
*/
public function setQosClass($qos_class) {
return $this->set('qos_class', $qos_class);
}
/**
* {@inheritdoc}
*/
public function getNodeName() {
return $this->get('node_name')->value;
}
/**
* {@inheritdoc}
*/
public function setNodeName($node_name) {
return $this->set('node_name', $node_name);
}
/**
* {@inheritdoc}
*/
public function getPodIp() {
return $this->get('pod_ip')->value;
}
/**
* {@inheritdoc}
*/
public function setPodIp($pod_ip) {
return $this->set('pod_ip', $pod_ip);
}
/**
* {@inheritdoc}
*/
public function getContainers() {
return $this->get('containers')->value;
}
/**
* {@inheritdoc}
*/
public function setContainers($containers) {
return $this->set('containers', $containers);
}
/**
* {@inheritdoc}
*/
public function getRestarts() {
return $this->get('restarts')->value;
}
/**
* {@inheritdoc}
*/
public function setRestarts($restarts) {
return $this->set('restarts', $restarts);
}
/**
* {@inheritdoc}
*/
public function getCpuRequest() {
return $this->get('cpu_request')->value;
}
/**
* {@inheritdoc}
*/
public function setCpuRequest($cpu_request) {
return $this->set('cpu_request', $cpu_request);
}
/**
* {@inheritdoc}
*/
public function getCpuLimit() {
return $this->get('cpu_limit')->value;
}
/**
* {@inheritdoc}
*/
public function setCpuLimit($cpu_limit) {
return $this->set('cpu_limit', $cpu_limit);
}
/**
* {@inheritdoc}
*/
public function getCpuUsage() {
return $this->get('cpu_usage')->value;
}
/**
* {@inheritdoc}
*/
public function setCpuUsage($cpu_usage) {
return $this->set('cpu_usage', $cpu_usage);
}
/**
* {@inheritdoc}
*/
public function getMemoryRequest() {
return $this->get('memory_request')->value;
}
/**
* {@inheritdoc}
*/
public function setMemoryRequest($memory_request) {
return $this->set('memory_request', $memory_request);
}
/**
* {@inheritdoc}
*/
public function getMemoryLimit() {
return $this->get('memory_limit')->value;
}
/**
* {@inheritdoc}
*/
public function setMemoryLimit($memory_limit) {
return $this->set('memory_limit', $memory_limit);
}
/**
* {@inheritdoc}
*/
public function getMemoryUsage() {
return $this->get('memory_usage')->value;
}
/**
* {@inheritdoc}
*/
public function setMemoryUsage($memory_usage) {
return $this->set('memory_usage', $memory_usage);
}
/**
* {@inheritdoc}
*/
public function getDetail() {
return $this->get('detail')->value;
}
/**
* {@inheritdoc}
*/
public function setDetail($detail) {
return $this->set('detail', $detail);
}
/**
* {@inheritdoc}
*/
public function getCreationYaml() {
return $this->get('creation_yaml')->value;
}
/**
* {@inheritdoc}
*/
public function setCreationYaml($creation_yaml) {
return $this->set('creation_yaml', $creation_yaml);
}
/**
* {@inheritdoc}
*/
public function getRefreshed() {
return $this->get('refreshed')->value;
}
/**
* {@inheritdoc}
*/
public function setRefreshed($time) {
return $this->set('refreshed', $time);
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Pod entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Pod entity.'))
->setReadOnly(TRUE);
$fields['cloud_context'] = BaseFieldDefinition::create('string')
->setRequired(TRUE)
->setLabel(t('Cloud ID'))
->setDescription(t('A unique machine name for the cloud provider.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The pod name.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['namespace'] = BaseFieldDefinition::create('string')
->setLabel(t('Namespace'))
->setDescription(t('The namespace of pod.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['labels'] = BaseFieldDefinition::create('key_value')
->setLabel(t('Labels'))
->setDescription(t('Map of string keys and values that can be used to organize and categorize (scope and select) objects.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'type' => 'key_value_formatter',
'weight' => -5,
]);
$fields['annotations'] = BaseFieldDefinition::create('key_value')
->setLabel(t('Annotations'))
->setDescription(t('Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setSetting('max_length', 4096)
->setDisplayOptions('view', [
'type' => 'key_value_formatter',
'weight' => -5,
]);
$fields['status'] = BaseFieldDefinition::create('string')
->setLabel(t('Status'))
->setDescription(t('The status of pod.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['qos_class'] = BaseFieldDefinition::create('string')
->setLabel(t('Qos Class'))
->setDescription(t('The Quality of Service (QOS) classification assigned to the pod based on resource requirements.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['node_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Node'))
->setDescription(t('NodeName is a request to schedule this pod onto a specific node.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['pod_ip'] = BaseFieldDefinition::create('string')
->setLabel(t('Pod IP'))
->setDescription(t('IP address allocated to the pod.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['containers'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Containers'))
->setDescription(t('Containers.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'type' => 'pre_string_formatter',
'weight' => -5,
]);
$fields['restarts'] = BaseFieldDefinition::create('integer')
->setLabel(t('Restarts'))
->setDescription(t('The restarts number of pod.'));
$fields['cpu_request'] = BaseFieldDefinition::create('float')
->setLabel(t('CPU (Request)'))
->setDescription(t('The requested cpu.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['cpu_limit'] = BaseFieldDefinition::create('float')
->setLabel(t('CPU (Limit)'))
->setDescription(t('The limited cpu.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['cpu_usage'] = BaseFieldDefinition::create('float')
->setLabel(t('CPU (Usage)'))
->setDescription(t('The requested cpu.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
]);
$fields['memory_request'] = BaseFieldDefinition::create('float')
->setLabel(t('Memory (Request)'))
->setDescription(t('The requested memory.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'memory_formatter',
'weight' => -5,
]);
$fields['memory_limit'] = BaseFieldDefinition::create('float')
->setLabel(t('Memory (Limit)'))
->setDescription(t('The limited memory.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'memory_formatter',
'weight' => -5,
]);
$fields['memory_usage'] = BaseFieldDefinition::create('float')
->setLabel(t('Memory (Usage)'))
->setDescription(t('The memory usage.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'memory_formatter',
'weight' => -5,
]);
$fields['detail'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Detail'))
->setDescription(t('Pod detail.'))
->setRequired(TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'pre_string_formatter',
'weight' => -5,
])
->setDisplayOptions('form', [
'type' => 'string_textarea',
'settings' => [
'rows' => 20,
],
])
->addConstraint('yaml_array_data');
$fields['creation_yaml'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Creation YAML'))
->setDescription(t('The YAML content was used to create the entity.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'pre_string_formatter',
'weight' => -5,
]);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
$fields['refreshed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Refreshed'))
->setDescription(t('The time that the entity was last refreshed.'));
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID of the Pod entity author.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId')
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'author',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
}
