cloud-8.x-2.0-beta1/modules/cloud_service_providers/openstack/src/Entity/Instance.php
modules/cloud_service_providers/openstack/src/Entity/Instance.php
<?php
namespace Drupal\openstack\Entity;
use Drupal\cloud\Entity\CloudContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Defines the OpenStack Cloud Instance entity.
*
* @ingroup openstack
*
* @ContentEntityType(
* id = "openstack_cloud_instance",
* label = @Translation("OpenStack Cloud Instance"),
* handlers = {
* "view_builder" = "Drupal\openstack\Entity\InstanceViewBuilder",
* "list_builder" = "Drupal\openstack\InstanceListBuilder",
* "views_data" = "Drupal\openstack\Entity\InstanceViewsData",
*
* "form" = {
* "default" = "Drupal\openstack\Form\InstanceEditForm",
* "edit" = "Drupal\openstack\Form\InstanceEditForm",
* "delete" = "Drupal\openstack\Form\InstanceDeleteForm",
* },
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
* },
* "access" = "Drupal\openstack\InstanceAccessControlHandler",
* },
* base_table = "openstack_cloud_instance",
* admin_permission = "administer openstack cloud instance entities",
* fieldable = TRUE,
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* "uid" = "uid",
* },
* links = {
* "canonical" = "/clouds/openstack_cloud/{cloud_context}/instance/{openstack_cloud_instance}",
* "add-form" = "/admin/structure/openstack_cloud_instance/add",
* "edit-form" = "/clouds/openstack_cloud/{cloud_context}/instance/{openstack_cloud_instance}/edit",
* "delete-form" = "/clouds/openstack_cloud/{cloud_context}/instance/{openstack_cloud_instance}/delete",
* "collection" = "/clouds/openstack_cloud/{cloud_context}/instance",
* },
* field_ui_base_route = "openstack_cloud_instance.settings"
* )
*/
class Instance extends CloudContentEntityBase implements InstanceInterface {
use EntityChangedTrait;
/**
* {@inheritdoc}
*/
public function getCreatedTime() {
return $this->get('created')->value;
}
/**
* {@inheritdoc}
*/
public function setCreatedTime($timestamp) {
$this->set('created', $timestamp);
return $this;
}
/**
* {@inheritdoc}
*/
public function setInstanceId($instance_id = '') {
$this->set('instance_id', $instance_id);
}
/**
* {@inheritdoc}
*/
public function getInstanceId() {
return $this->get('instance_id')->value;
}
/**
* {@inheritdoc}
*/
public function setInstanceState($state = '') {
$this->set('instance_state', $state);
}
/**
* {@inheritdoc}
*/
public function getInstanceState() {
return $this->get('instance_state')->value;
}
/**
* {@inheritdoc}
*/
public function setInstanceType($type = '') {
$this->set('instance_type', $type);
}
/**
* {@inheritdoc}
*/
public function getInstanceType() {
return $this->get('instance_type')->value;
}
/**
* {@inheritdoc}
*/
public function setReservation($reservation = '') {
$this->set('reservation', $reservation);
}
/**
* {@inheritdoc}
*/
public function getReservation() {
return $this->get('reservation')->value;
}
/**
* {@inheritdoc}
*/
public function setImageId($image_id = '') {
$this->set('image_id', $image_id);
}
/**
* {@inheritdoc}
*/
public function getImageId() {
return $this->get('image_id')->value;
}
/**
* {@inheritdoc}
*/
public function setImageName($image_name = '') {
$this->set('image_name', $image_name);
}
/**
* {@inheritdoc}
*/
public function getImageName() {
return $this->get('image_name')->value;
}
/**
* {@inheritdoc}
*/
public function setAccountId($account_id = '') {
$this->set('account_id', $account_id);
}
/**
* {@inheritdoc}
*/
public function getAccountId() {
return $this->get('account_id')->value;
}
/**
* {@inheritdoc}
*/
public function setLaunchTime($launch_time = '') {
$this->set('launch_time', $launch_time);
}
/**
* {@inheritdoc}
*/
public function getLaunchTime() {
return $this->get('launch_time')->value;
}
/**
* {@inheritdoc}
*/
public function setPublicDns($dns = '') {
$this->set('public_dns', $dns);
}
/**
* {@inheritdoc}
*/
public function getPublicDns() {
return $this->get('public_dns')->value;
}
/**
* {@inheritdoc}
*/
public function getPrivateDns() {
return $this->get('private_dns')->value;
}
/**
* {@inheritdoc}
*/
public function setPrivateDns($private_dns = '') {
$this->set('private_dns', $private_dns);
}
/**
* {@inheritdoc}
*/
public function getPrivateIps() {
return $this->get('private_ips')->value;
}
/**
* {@inheritdoc}
*/
public function setPrivateIps($private_ips = '') {
$this->set('private_ips', $private_ips);
}
/**
* {@inheritdoc}
*/
public function getSecurityGroups() {
return $this->get('security_groups')->getValue();
}
/**
* {@inheritdoc}
*/
public function setSecurityGroups(array $security_groups) {
$this->set('security_groups', $security_groups);
}
/**
* {@inheritdoc}
*/
public function setKeyPairName($key_pair = '') {
$this->set('key_pair_name', $key_pair);
}
/**
* {@inheritdoc}
*/
public function getKeyPairName() {
return $this->get('key_pair_name')->value;
}
/**
* {@inheritdoc}
*/
public function setAvailabilityZone($zone = '') {
$this->set('availability_zone', $zone);
}
/**
* {@inheritdoc}
*/
public function getAvailabilityZone() {
return $this->get('availability_zone')->value;
}
/**
* {@inheritdoc}
*/
public function setRootDeviceType($type = '') {
$this->set('root_device_type', $type);
}
/**
* {@inheritdoc}
*/
public function getRootDeviceType() {
return $this->get('root_device_type')->value;
}
/**
* {@inheritdoc}
*/
public function setRootDevice($device = '') {
$this->set('root_device', $device);
}
/**
* {@inheritdoc}
*/
public function getRootDevice() {
return $this->get('root_device')->value;
}
/**
* {@inheritdoc}
*/
public function setAmiLaunchIndex($launch_index = '') {
$this->set('ami_launch_index', $launch_index);
}
/**
* {@inheritdoc}
*/
public function getAmiLaunchIndex() {
return $this->get('ami_launch_index')->value;
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the OpenStack Cloud Instance entity.'))
->setSettings([
'max_length' => 50,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -17,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -17,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
$fields['instance_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Instance ID'))
->setDescription(t('The Instance ID.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -16,
])
->setReadOnly(TRUE);
$fields['instance_state'] = BaseFieldDefinition::create('string')
->setLabel(t('Instance State'))
->setDescription(t('The state of the instance; for example, running, pending, or terminated.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -15,
])
->setReadOnly(TRUE);
$fields['instance_type'] = BaseFieldDefinition::create('string')
->setLabel(t('Instance Type'))
->setDescription(t("The type of instance determines your instance's CPU capacity, memory, and storage (e.g., m1.small, c1.xlarge)."))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -14,
])
->setReadOnly(TRUE);
$fields['reservation'] = BaseFieldDefinition::create('string')
->setLabel(t('Reservation'))
->setDescription(t('The reservation ID used to launch the instance.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -13,
])
->setReadOnly(TRUE);
$fields['image_id'] = BaseFieldDefinition::create('string')
->setLabel(t('AMI Image'))
->setDescription(t('The ID of the AMI with which the instance was launched.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -12,
])
->setReadOnly(TRUE);
$fields['image_name'] = BaseFieldDefinition::create('string')
->setLabel(t('AMI Image Name'))
->setDescription(t('The name of the AMI with which the instance was launched.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -12,
])
->setReadOnly(TRUE);
$fields['account_id'] = BaseFieldDefinition::create('string')
->setLabel(t('OpenStack Account ID'))
->setDescription(t('The OpenStack account number of the instance owner, without dashes.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -11,
])
->setReadOnly(TRUE);
$fields['launch_time'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Launch Time'))
->setDescription(t('The time the instance launched.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'timestamp',
'weight' => -10,
'settings' => [
'date_format' => 'short',
],
])
->setReadOnly(TRUE);
$fields['public_dns'] = BaseFieldDefinition::create('string')
->setLabel(t('Public DNS'))
->setDescription(t('The public hostname of the instance, which resolves to the public IP address or Elastic IP address of the instance.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -9,
])
->setReadOnly(TRUE);
$fields['private_dns'] = BaseFieldDefinition::create('string')
->setLabel(t('Private DNS'))
->setDescription(t("The private, internal hostname of the instance, which resolves to the instance's private IP address."))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -8,
])
->setReadOnly(TRUE);
$fields['private_ips'] = BaseFieldDefinition::create('string')
->setLabel(t('Private IPs'))
->setDescription(t('The private IP address of the instance (multiple IP addresses are listed if there is more than one network interface to the instance).'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -7,
])
->setReadOnly(TRUE);
$fields['security_groups'] = BaseFieldDefinition::create('string')
->setLabel(t('Security Groups'))
->setDescription(t('The security groups to which the instance belongs. A security group is a collection of firewall rules that restrict the network traffic for the instance. Click View rules to see the rules for the specific group.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -6,
])
->setReadOnly(TRUE);
$fields['key_pair_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Key Pair Name'))
->setDescription(t('The name of the key pair that you must use to log in to the instance securely.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -5,
])
->setReadOnly(TRUE);
$fields['availability_zone'] = BaseFieldDefinition::create('string')
->setLabel(t('Availability Zone'))
->setDescription(t('The availability zone in which the instance is located. Availability Zones are distinct locations within a region that are engineered to be insulated from failures in other Availability Zones.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -4,
])
->setReadOnly(TRUE);
$fields['root_device_type'] = BaseFieldDefinition::create('string')
->setLabel(t('Root Device Type'))
->setDescription(t('The root volume is either an EBS volume or instance store volume. The Create Image, Start and Stop actions only apply to instances with an EBS root device type.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -3,
])
->setReadOnly(TRUE);
$fields['root_device'] = BaseFieldDefinition::create('string')
->setLabel(t('Root Device'))
->setDescription(t('System device name that contains the boot volume (e.g., /dev/sda1).'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -2,
])
->setReadOnly(TRUE);
$fields['ami_launch_index'] = BaseFieldDefinition::create('string')
->setLabel(t('AMI Launch Index'))
->setDescription(t('A number indicating the order in which the instance was launched. The first or only instance has an index of 0.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -1,
])
->setReadOnly(TRUE);
$fields['cloud_context'] = BaseFieldDefinition::create('string')
->setRequired(TRUE)
->setLabel(t('Cloud Service Provider ID'))
->setDescription(t('A unique machine name for the cloud service provider.'))
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => 0,
])
->setReadOnly(TRUE);
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID of author of the OpenStack Cloud Instance entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'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);
$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.'));
return $fields;
}
}
