class ServerInterface(resource2.Resource): resource_key = 'interfaceAttachment' resources_key = 'interfaceAttachments' base_path = '/servers/%(server_id)s/os-interface' service = compute_service.ComputeService() # capabilities allow_create = True allow_get = False allow_update = False allow_delete = True allow_list = True #: Fixed IP addresses with subnet IDs. fixed_ips = resource2.Body('fixed_ips') #: The MAC address. mac_addr = resource2.Body('mac_addr') #: The network ID. net_id = resource2.Body('net_id') #: The ID of the port for which you want to create an interface. port_id = resource2.Body('port_id', alternate_id=True) #: The port state. port_state = resource2.Body('port_state') #: The ID for the server. server_id = resource2.URI('server_id')
class DefaultQuota(resource2.Resource): resource_key = "quota_set" resources_key = "quota_sets" base_path = '/os-quota-sets/%(tenant_id)s/defaults' service = compute_service.ComputeService() allow_get = True tenant_id = resource2.URI("tenant_id") cores = resource2.Body("cores", int) fixed_ips = resource2.Body("fixed_ips", int) id = resource2.Body("id") injected_file_content_bytes = resource2.Body("injected_file_content_bytes", int) injected_file_path_bytes = resource2.Body("injected_file_path_bytes", int) injected_files = resource2.Body("injected_files", int) instances = resource2.Body("instances", int) key_pairs = resource2.Body("key_pairs", int) metadata_items = resource2.Body("metadata_items", int) ram = resource2.Body("ram", int) security_group_rules = resource2.Body("security_group_rules", int) security_groups = resource2.Body("security_groups", int) server_group_members = resource2.Body("server_group_members", int) server_groups = resource2.Body("server_groups", int) def get(self, session, requires_id=False): return super(DefaultQuota, self).get(session, False)
class Volume(resource2.Resource): resource_key = 'volume' resources_key = 'volumes' base_path = '/os-volumes' service = compute_service.ComputeService() # capabilities allow_create = True allow_get = True allow_delete = True allow_list = True allow_update = True id = resource2.Body("id") name = resource2.Body("displayName") description = resource2.Body("displayDescription") size = resource2.Body("size") volume_type = resource2.Body("volumeType") metadata = resource2.Body("metadata", dict) availability_zone = resource2.Body("availabilityZone") snapshot_id = resource2.Body("snapshotId") attachments = resource2.Body("attachments", list) created_at = resource2.Body("createdAt") status = resource2.Body('status') bootable = resource2.Body('bootable')
def test_service(self): sot = compute_service.ComputeService() self.assertEqual('compute', sot.service_type) self.assertEqual('public', sot.interface) self.assertIsNone(sot.region) self.assertIsNone(sot.service_name) self.assertEqual(1, len(sot.valid_versions)) self.assertEqual('v2', sot.valid_versions[0].module) self.assertEqual('v2', sot.valid_versions[0].path)
def __init__(self, plugins=None): """User preference for each service. :param list plugins: List of entry point namespaces to load. Create a new :class:`~ecl.profile.Profile` object with no preferences defined, but knowledge of the services. Services are identified by their service type, e.g.: 'identity', 'compute', etc. """ self._services = {} self._add_service(compute_service.ComputeService(version="v2")) self._add_service( connectivity_service.ConnectivityService(version="v1")) self._add_service(identity_service.IdentityService(version="v3")) self._add_service(image_service.ImageService(version="v2")) self._add_service(network_service.NetworkService(version="v2")) self._add_service(sss_service.SssService(version="v1")) self._add_service( orchestration_service.OrchestrationService(version="v1")) self._add_service( provider_connectivity_service.ProviderConnectivityService( version="v2")) self._add_service(telemetry_service.TelemetryService(version="v2")) self._add_service(block_store_service.BlockStoreService(version="v2")) self._add_service(storage_service.StorageService(version="v1")) self._add_service( security_order_service.SecurityOrderService(version="v2")) self._add_service( security_portal_service.SecurityPortalService(version="v2")) ## This section will be deleted if MSS v1 API is not available self._add_service( security_order_service_v1.SecurityOrderService(version="v1")) self._add_service( security_portal_service_v1.SecurityPortalService(version="v1")) ## end of the section self._add_service(rca_service.RcaService(version="v1")) self._add_service(baremetal_service.BaremetalService(version="v2")) self._add_service( dedicated_hypervisor_service.DedicatedHypervisorService( version="v1")) self._add_service(dns_service.DnsService(version="v2")) self._add_service( virtual_network_appliance_service.VirtualNetworkApplianceService( version="v1")) self._add_service(mvna_service.MVNAService(version="v1")) # NOTE: The Metric service is not added here as it currently # only retrieves the /capabilities API. if plugins: for plugin in plugins: self._load_plugin(plugin) self.service_keys = sorted(self._services.keys())
class AvailabilityZone(resource2.Resource): resources_key = 'availabilityZoneInfo' base_path = '/os-availability-zone' service = compute_service.ComputeService() # capabilities allow_list = True # Properties #: name of availability zone name = resource2.Body('zoneName', alternate_id=True) #: state of availability zone state = resource2.Body('zoneState') #: hosts of availability zone hosts = resource2.Body('hosts') @classmethod def find(cls, session, name_or_id, ignore_missing=False, **params): """Find a resource by its name or id. :param session: The session to use for making this request. :type session: :class:`~ecl.session.Session` :param name_or_id: This resource's identifier, if needed by the request. The default is ``None``. :param bool ignore_missing: When set to ``False`` :class:`~ecl.exceptions.ResourceNotFound` will be raised when the resource does not exist. When set to ``True``, None will be returned when attempting to find a nonexistent resource. :param dict params: Any additional parameters to be passed into underlying methods, such as to :meth:`~ecl.resource2.Resource.existing` in order to pass on URI parameters. :return: The :class:`Resource` object matching the given name or id or None if nothing matches. :raises: :class:`ecl.exceptions.DuplicateResource` if more than one resource is found for this request. :raises: :class:`ecl.exceptions.ResourceNotFound` if nothing is found and ignore_missing is ``False``. """ # Try to short-circuit by looking directly for a matching ID. data = cls.list(session, **params) result = cls._get_one_match(name_or_id, data) if result is not None: return result if ignore_missing: return None raise exceptions.ResourceNotFound("No %s found for %s" % (cls.__name__, name_or_id))
class Version(resource.Resource): resource_key = 'version' resources_key = 'versions' base_path = '/' service = compute_service.ComputeService( version=compute_service.ComputeService.UNVERSIONED) # capabilities allow_list = True # Properties links = resource.prop('links') status = resource.prop('status') updated = resource.prop('updated')
class TenantUsage(resource2.Resource): resource_key = "tenant_usage" resources_key = "tenant_usages" base_path = '/os-simple-tenant-usage' service = compute_service.ComputeService() allow_get = True server_usages = resource2.Body("server_usages") start = resource2.Body("start") stop = resource2.Body("stop") tenant_id = resource2.Body("tenant_id") total_hours = resource2.Body("total_hours") total_local_gb_usage = resource2.Body("total_local_gb_usage") total_memory_mb_usage = resource2.Body("total_memory_mb_usage") total_vcpus_usage = resource2.Body("total_vcpus_usage")
class Keypair(resource2.Resource): resource_key = 'keypair' resources_key = 'keypairs' base_path = '/os-keypairs' service = compute_service.ComputeService() # capabilities allow_create = True allow_get = True allow_delete = True allow_list = True # Properties #: The short fingerprint associated with the ``public_key`` for #: this keypair. fingerprint = resource2.Body('fingerprint') # NOTE: There is in fact an 'id' field. However, it's not useful # because all operations use the 'name' as an identifier. # Additionally, the 'id' field only appears *after* creation, # so suddenly you have an 'id' field filled in after the fact, # and it just gets in the way. We need to cover this up by having # the name be both our id and name. #: The id identifying the keypair id = resource2.Body('name') #: A name identifying the keypair name = resource2.Body('name', alternate_id=True) #: The private key for the keypair private_key = resource2.Body('private_key') #: The SSH public key that is paired with the server. public_key = resource2.Body('public_key') user_id = resource2.Body('user_id') @classmethod def list(cls, session, paginated=False): resp = session.get(cls.base_path, endpoint_filter=cls.service, headers={"Accept": "application/json"}) resp = resp.json() resp = resp[cls.resources_key] for data in resp: value = cls.existing(**data[cls.resource_key]) yield value
class Image(resource2.Resource, metadata.MetadataMixin): resource_key = 'image' resources_key = 'images' base_path = '/images' service = compute_service.ComputeService() # capabilities allow_get = True allow_delete = True allow_list = True _query_mapping = resource2.QueryParameters("server", "name", "status", "type", min_disk="minDisk", min_ram="minRam", changes_since="changes-since") # Properties #: Links pertaining to this image. This is a list of dictionaries, #: each including keys ``href`` and ``rel``, and optionally ``type``. links = resource2.Body('links') #: The name of this image. name = resource2.Body('name') #: Timestamp when the image was created. created_at = resource2.Body('created') #: Metadata pertaining to this image. *Type: dict* metadata = resource2.Body('metadata', type=dict) #: The mimimum disk size. *Type: int* min_disk = resource2.Body('minDisk', type=int) #: The minimum RAM size. *Type: int* min_ram = resource2.Body('minRam', type=int) #: If this image is still building, its progress is represented here. #: Once an image is created, progres will be 100. *Type: int* progress = resource2.Body('progress', type=int) #: The status of this image. status = resource2.Body('status') #: Timestamp when the image was updated. updated_at = resource2.Body('updated') #: Size of the image in bytes. *Type: int* size = resource2.Body('OS-EXT-IMG-SIZE:size', type=int)
class Limits(resource2.Resource): base_path = "/limits" resource_key = "limits" service = compute_service.ComputeService() allow_get = True absolute = resource2.Body("absolute", type=AbsoluteLimits) rate = resource2.Body("rate", type=list) def get(self, session, requires_id=False): """Get the Limits resource. :param session: The session to use for making this request. :type session: :class:`~ecl.session.Session` :returns: A Limits instance :rtype: :class:`~ecl.compute.v2.limits.Limits` """ request = self._prepare_request(requires_id=False, prepend_key=False) response = session.get(request.uri, endpoint_filter=self.service) body = response.json() body = body[self.resource_key] absolute_body = self._filter_component(body["absolute"], AbsoluteLimits._body_mapping()) self.absolute = AbsoluteLimits.existing(**absolute_body) rates_body = body["rate"] rates = [] for rate_body in rates_body: rate_body = self._filter_component(rate_body, RateLimit._body_mapping()) rates.append(RateLimit(**rate_body)) self.rate = rates return self
class ServerVolume(resource2.Resource): resource_key = 'volumeAttachment' resources_key = 'volumeAttachments' base_path = '/servers/%(serverId)s/os-volume_attachments' service = compute_service.ComputeService() # capabilities allow_create = True allow_get = False allow_update = False allow_delete = True allow_list = True #: Device name device = resource2.Body('device') #: Attachment ID id = resource2.Body('id') #: The ID of the server serverId = resource2.URI('serverId') #: The ID of the volume volumeId = resource2.Body('volumeId')
class Flavor(resource2.Resource): resource_key = 'flavor' resources_key = 'flavors' base_path = '/flavors' service = compute_service.ComputeService() # capabilities allow_create = True allow_get = True allow_delete = True allow_list = True _query_mapping = resource2.QueryParameters("sort_key", "sort_dir", min_disk="minDisk", min_ram="minRam") # Properties #: Links pertaining to this flavor. This is a list of dictionaries, #: each including keys ``href`` and ``rel``. links = resource2.Body('links') #: The name of this flavor. name = resource2.Body('name') #: Size of the disk this flavor offers. *Type: int* disk = resource2.Body('disk', type=int) #: ``True`` if this is a publicly visible flavor. ``False`` if this is #: a private image. *Type: bool* is_public = resource2.Body('os-flavor-access:is_public', type=bool) #: The amount of RAM (in MB) this flavor offers. *Type: int* ram = resource2.Body('ram', type=int) #: The number of virtual CPUs this flavor offers. *Type: int* vcpus = resource2.Body('vcpus', type=int) #: Size of the swap partitions. swap = resource2.Body('swap') #: Size of the ephemeral data disk attached to this server. *Type: int* ephemeral = resource2.Body('OS-FLV-EXT-DATA:ephemeral', type=int) #: ``True`` if this flavor is disabled, ``False`` if not. *Type: bool* is_disabled = resource2.Body('OS-FLV-DISABLED:disabled', type=bool) #: The bandwidth scaling factor this flavor receives on the network. rxtx_factor = resource2.Body('rxtx_factor', type=float)
class Quota(resource2.Resource): resource_key = "quota_set" resources_key = "quota_sets" base_path = '/os-quota-sets' service = compute_service.ComputeService() # capabilities allow_get = True cores = resource2.Body("cores", int) fixed_ips = resource2.Body("fixed_ips", int) id = resource2.Body("id") injected_file_content_bytes = resource2.Body("injected_file_content_bytes", int) injected_file_path_bytes = resource2.Body("injected_file_path_bytes", int) injected_files = resource2.Body("injected_files", int) instances = resource2.Body("instances", int) key_pairs = resource2.Body("key_pairs", int) metadata_items = resource2.Body("metadata_items", int) ram = resource2.Body("ram", int) security_group_rules = resource2.Body("security_group_rules", int) security_groups = resource2.Body("security_groups", int) server_group_members = resource2.Body("server_group_members", int) server_groups = resource2.Body("server_groups", int)