class Extension(resource.Resource):
    resource_key = 'extension'
    resources_key = 'extensions'
    base_path = '/extensions'
    service = compute_service.ComputeService()
    id_attribute = "alias"

    # capabilities
    allow_retrieve = True
    allow_list = True

    # Properties
    #: A short name by which this extension is also known.
    alias = resource.prop('alias')
    #: Text describing this extension's purpose.
    description = resource.prop('description')
    #: Links pertaining to this extension. This is a list of dictionaries,
    #: each including keys ``href`` and ``rel``.
    links = resource.prop('links')
    #: The name of the extension.
    name = resource.prop('name')
    #: A URL pointing to the namespace for this extension.
    namespace = resource.prop('namespace')
    #: Timestamp when this extension was last updated.
    #: *Type: datetime object parsed from ISO 8601 formatted string*
    updated_at = resource.prop('updated', type=format.ISO8601)
class VolumeAttachment(resource.Resource):
    resource_key = 'volumeAttachment'
    resources_key = 'volumeAttachments'
    base_path = '/servers/%(server_id)s/os-volume_attachments'
    service = compute_service.ComputeService()

    # capabilities
    allow_create = True
    allow_fetch = True
    allow_commit = False
    allow_delete = True
    allow_list = True

    _query_mapping = resource.QueryParameters("limit", "offset")

    #: Name of the device such as, /dev/vdb.
    device = resource.Body('device')
    #: The ID of the attachment.
    id = resource.Body('id')
    #: The ID for the server.
    server_id = resource.URI('server_id')
    #: The ID of the attached volume.
    volume_id = resource.Body('volumeId')
    #: The ID of the attachment you want to delete or update.
    attachment_id = resource.Body('attachment_id', alternate_id=True)
Example #3
0
class ServerInterface(resource.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 = True
    allow_update = False
    allow_delete = True
    allow_list = True

    #: Fixed IP addresses with subnet IDs.
    fixed_ips = resource.Body('fixed_ips')
    #: The MAC address.
    mac_addr = resource.Body('mac_addr')
    #: The network ID.
    net_id = resource.Body('net_id')
    #: The ID of the port for which you want to create an interface.
    port_id = resource.Body('port_id', alternate_id=True)
    #: The port state.
    port_state = resource.Body('port_state')
    #: The ID for the server.
    server_id = resource.URI('server_id')
Example #4
0
class Extension(resource2.Resource):
    resource_key = 'extension'
    resources_key = 'extensions'
    base_path = '/extensions'
    service = compute_service.ComputeService()
    id_attribute = "alias"

    # capabilities
    allow_get = True
    allow_list = True

    # Properties
    #: A short name by which this extension is also known.
    alias = resource2.Body('alias', alternate_id=True)
    #: Text describing this extension's purpose.
    description = resource2.Body('description')
    #: Links pertaining to this extension. This is a list of dictionaries,
    #: each including keys ``href`` and ``rel``.
    links = resource2.Body('links')
    #: The name of the extension.
    name = resource2.Body('name')
    #: A URL pointing to the namespace for this extension.
    namespace = resource2.Body('namespace')
    #: Timestamp when this extension was last updated.
    updated_at = resource2.Body('updated')
Example #5
0
    def __init__(self, plugins=None):
        """User preference for each service.

        :param plugins: List of entry point namespaces to load.

        Create a new :class:`~openstack.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(baremetal_service.BaremetalService(version="v1"))
        self._add_service(
            block_storage_service.BlockStorageService(version="v2"))
        self._add_service(clustering_service.ClusteringService(version="v1"))
        self._add_service(compute_service.ComputeService(version="v2"))
        self._add_service(database_service.DatabaseService(version="v1"))
        self._add_service(identity_service.IdentityService(version="v3"))
        self._add_service(image_service.ImageService(version="v2"))
        self._add_service(key_manager_service.KeyManagerService(version="v1"))
        self._add_service(lb_service.LoadBalancerService(version="v2"))
        self._add_service(message_service.MessageService(version="v1"))
        self._add_service(network_service.NetworkService(version="v2"))
        self._add_service(
            object_store_service.ObjectStoreService(version="v1"))
        self._add_service(
            orchestration_service.OrchestrationService(version="v1"))
        self._add_service(workflow_service.WorkflowService(version="v2"))

        self.service_keys = sorted(self._services.keys())
class ServerOS(resource2.Resource):
    base_path = "/cloudservers"
    allow_create = True

    service = compute_service.ComputeService()

    # admin password
    adminpass = resource2.Body("adminpass")
    # key name
    keyname = resource2.Body("keyname")
    # user id
    userid = resource2.Body("userid")
    # metadata
    metadata = resource2.Body("metadata", type=dict)

    def reinstall(self, session, server_id):
        url = utils.urljoin(self.base_path, server_id, 'reinstallos')
        headers = {'Accept': ''}
        endpoint_override = self.service.get_endpoint_override()
        service = self.get_service_filter(self, session)
        body = {"os-reinstall": self._body.dirty}
        return session.post(url,
                            endpoint_filter=self.service,
                            microversion=service.microversion,
                            json=body,
                            headers=headers,
                            endpoint_override=endpoint_override).json()
Example #7
0
    def __init__(self, plugins=None):
        """User preference for each service.

        :param list plugins: List of entry point namespaces to load.

        Create a new :class:`~openstack.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._preferences = {}
        self._services = {}
        self._add_service(cluster_service.ClusterService())
        self._add_service(compute_service.ComputeService())
        self._add_service(database_service.DatabaseService())
        self._add_service(identity_service.IdentityService())
        self._add_service(image_service.ImageService())
        self._add_service(metric_service.MetricService())
        self._add_service(network_service.NetworkService())
        self._add_service(object_store_service.ObjectStoreService())
        self._add_service(orchestration_service.OrchestrationService())
        self._add_service(key_management_service.KeyManagementService())
        self._add_service(telemetry_service.TelemetryService())
        self._add_service(block_store_service.BlockStoreService())
        self._add_service(message_service.MessageService())

        if plugins:
            for plugin in plugins:
                self._load_plugin(plugin)
        self.service_names = sorted(self._services.keys())
Example #8
0
class ServerIP(resource.Resource):
    id_attribute = 'addr'
    resource_key = 'server_ip'
    resources_key = 'server_ips'
    base_path = '/servers/%(server_id)s/ips'
    service = compute_service.ComputeService()

    # capabilities
    allow_list = True

    # Properties
    #: The IP address. The format of the address depends on :attr:`version`
    addr = resource.prop('addr')
    #: The network label, such as public or private.
    network_label = resource.prop('network_label')
    #: The UUID for the server.
    server_id = resource.prop('server_id')
    # Version of the IP protocol. Currently either 4 or 6.
    version = resource.prop('version')

    @classmethod
    def list(cls, session, path_args=None, **params):
        url = cls._get_url(path_args)
        resp = session.get(url, service=cls.service, params=params)
        ray = []
        for network_label, addresses in six.iteritems(resp.body['addresses']):
            for address in addresses:
                record = {
                    'server_id': path_args['server_id'],
                    'network_label': network_label,
                    'version': address['version'],
                    'addr': address['addr'],
                }
                ray.append(cls.existing(**record))
        return ray
Example #9
0
    def __init__(self, plugins=None):
        """User preference for each service.

        :param plugins: List of entry point namespaces to load.

        Create a new :class:`~openstack.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(anti_ddos_service.AntiDDosService(version="v1"))
        self._add_service(block_store_service.BlockStoreService(version="v2"))
        self._add_service(compute_service.ComputeService(version="v2"))
        self._add_service(cts_service.CTSService(version="v1"))
        self._add_service(dms_service.DMSService(version="v1"))
        self._add_service(identity_service.IdentityService(version="v3"))
        self._add_service(image_service.ImageService(version="v2"))
        self._add_service(kms_service.KMSService(version="v1"))
        self._add_service(maas_service.MaaSService(version="v1"))
        self._add_service(network_service.NetworkService(version="v2.0"))
        self._add_service(
            orchestration_service.OrchestrationService(version="v1"))
        self._add_service(smn_service.SMNService(version="v2"))
        # QianBiao.NG HuaWei Services
        self._add_service(dns_service.DNSService(version="v2"))
        self._add_service(cloud_eye_service.CloudEyeService(version="v1"))
        ass = auto_scaling_service.AutoScalingService(version="v1")
        self._add_service(ass)
        vbs_v2 = volume_backup_service.VolumeBackupService(version="v2")
        self._add_service(vbs_v2)
        self._add_service(map_reduce_service.MapReduceService(version="v1"))
        self._add_service(evs_service.EvsServiceV2_1(version='v2.1'))
        self._add_service(evs_service.EvsService(version='v2'))
        self._add_service(ecs_service.EcsService(version='v1'))
        self._add_service(ecs_service.EcsServiceV1_1(version='v1.1'))
        self._add_service(vpc_service.VpcService(version='v2.0'))
        self._add_service(bms_service.BmsService(version='v1'))
        self._add_service(lb_service.LoadBalancerService(version='v1'))
        # not support below service
        # self._add_service(message_service.MessageService(version="v1"))
        # self._add_service(cluster_service.ClusterService(version="v1"))
        # self._add_service(database_service.DatabaseService(version="v1"))
        # self._add_service(alarm_service.AlarmService(version="v2"))
        # self._add_service(bare_metal_service.BareMetalService(version="v1"))
        # self._add_service(key_manager_service.KeyManagerService(version="v1"))
        # self._add_service(
        # object_store_service.ObjectStoreService(version="v1"))

        self._add_service(rds_service.RDSService(version="v1"))
        self._add_service(cdn_service.CDNService(version='v1'))

        # self._add_service(rds_os_service.RDSService(version="v1"))
        # self._add_service(telemetry_service.TelemetryService(version="v2"))
        # self._add_service(workflow_service.WorkflowService(version="v2"))
        if plugins:
            for plugin in plugins:
                self._load_plugin(plugin)
        self.service_keys = sorted(self._services.keys())
class Image(resource.Resource):
    resource_key = 'image'
    resources_key = 'images'
    base_path = '/images'
    service = compute_service.ComputeService()

    # capabilities
    allow_retrieve = True
    allow_delete = True
    allow_list = True

    # Properties
    #: Links pertaining to this image. This is a list of dictionaries,
    #: each including keys ``href`` and ``rel``, and optionally ``type``.
    links = resource.prop('links')
    #: The name of this image.
    name = resource.prop('name')
    #: Timestamp when the image was created.
    created_at = resource.prop('created')
    #: Metadata pertaining to this image. *Type: dict*
    metadata = resource.prop('metadata', type=dict)
    #: The mimimum disk size. *Type: int*
    min_disk = resource.prop('minDisk', type=int)
    #: The minimum RAM size. *Type: int*
    min_ram = resource.prop('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 = resource.prop('progress', type=int)
    #: The status of this image.
    status = resource.prop('status')
    #: Timestamp when the image was updated.
    updated_at = resource.prop('updated')
    #: Size of the image in bytes. *Type: int*
    size = resource.prop('OS-EXT-IMG-SIZE:size', type=int)
Example #11
0
class ServerIP(resource.Resource):
    id_attribute = 'addr'
    resource_key = 'server_ip'
    resources_key = 'server_ips'
    base_path = '/servers/%(server_id)s/ips'
    service = compute_service.ComputeService()

    # capabilities
    allow_list = True

    # Properties
    addr = resource.prop('addr')
    network_label = resource.prop('network_label')
    server_id = resource.prop('server_id')
    version = resource.prop('version')

    @classmethod
    def list(cls, session, path_args=None, **params):
        url = cls.base_path % path_args
        resp = session.get(url, service=cls.service, params=params)
        ray = []
        for network_label, addresses in six.iteritems(resp.body['addresses']):
            for address in addresses:
                record = {
                    'server_id': path_args['server_id'],
                    'network_label': network_label,
                    'version': address['version'],
                    'addr': address['addr'],
                }
                ray.append(cls.existing(**record))
        return ray
Example #12
0
class ExtraSpecs(resource2.Resource):
    base_path = '/flavors/%(flavor_id)s/os-extra_specs'
    service = compute_service.ComputeService()
    # capabilities
    allow_get = True
    # flavor id used in the uri
    flavor_id = resource2.URI("flavor_id")
    #: A dictionary of the flavor's extra-specs key-and-value pairs.
    extra_specs = resource2.Body('extra_specs', type=dict)
 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)
class ServerMeta(resource.Resource):
    resource_key = 'meta'
    id_attribute = 'key'
    base_path = '/servers/%(server_id)s/metadata'
    service = compute_service.ComputeService()

    # capabilities
    allow_create = True
    allow_retrieve = True
    allow_update = True
    allow_delete = True
    allow_list = True

    # Properties
    #: The metadata key.
    key = resource.prop('key')
    #: The ID of a server.
    server_id = resource.prop('server_id')
    #: The metadata value.
    value = resource.prop('value')

    @classmethod
    def create_by_id(cls, session, attrs, resource_id=None, path_args=None):
        url = cls.base_path % path_args
        url = utils.urljoin(url, resource_id)
        body = {cls.resource_key: {attrs['key']: attrs['value']}}
        resp = session.put(url, service=cls.service, json=body).body
        return {'key': resource_id,
                'value': resp[cls.resource_key][resource_id]}

    @classmethod
    def get_data_by_id(cls, session, resource_id, path_args=None,
                       include_headers=False):
        url = cls.base_path % path_args
        url = utils.urljoin(url, resource_id)
        resp = session.get(url, service=cls.service).body
        return {'key': resource_id,
                'value': resp[cls.resource_key][resource_id]}

    @classmethod
    def update_by_id(cls, session, resource_id, attrs, path_args=None):
        return cls.create_by_id(session, attrs, resource_id, path_args)

    @classmethod
    def delete_by_id(cls, session, resource_id, path_args=None):
        url = cls.base_path % path_args
        url = utils.urljoin(url, resource_id)
        session.delete(url, service=cls.service, accept=None)

    @classmethod
    def list(cls, session, path_args=None, **params):
        url = '/servers/%(server_id)s/metadata' % path_args
        resp = session.get(url, service=cls.service, params=params).body
        resp = resp['metadata']
        return [cls.existing(server_id=path_args['server_id'], key=key,
                             value=value)
                for key, value in six.iteritems(resp)]
Example #15
0
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')
    #: The type of keypair.
    type = resource2.Body('type')
    #: Create time of the keypair.
    created_at = resource2.Body('created_at')
    #: Keypair deletion tag.*Type: bool*.
    deleted = resource2.Body('deleted', type=bool)
    #: Delete time of the keypair.
    deleted_at = resource2.Body('deleted_at')
    #: Update time of the keypair.
    updated_at = resource2.Body('updated_at')
    #: User information to which the keypair belongs.
    user_id = resource2.Body('user_id')

    @classmethod
    def list(cls, session, paginated=False):
        endpoint_override = cls.service.get_endpoint_override()
        resp = session.get(cls.base_path,
                           endpoint_filter=cls.service,
                           headers={"Accept": "application/json"},
                           endpoint_override=endpoint_override)
        resp = resp.json()
        resp = resp[cls.resources_key]

        for data in resp:
            value = cls.existing(**data[cls.resource_key])
            yield value
Example #16
0
    def __init__(self):
        """Preferences for each service.

        Create a new :class:`~openstack.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._preferences = {}
        self._services = {}
        """
        NOTE(thowe): We should probably do something more clever here rather
        than brute force create all the services.  Maybe use entry points
        or something, but I'd like to leave that work for another commit.
        """
        serv = cluster_service.ClusterService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = compute_service.ComputeService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = database_service.DatabaseService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = identity_service.IdentityService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = image_service.ImageService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = metric_service.MetricService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = network_service.NetworkService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = object_store_service.ObjectStoreService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = orchestration_service.OrchestrationService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = keystore_service.KeystoreService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = telemetry_service.TelemetryService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = block_store_service.BlockStoreService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv
        serv = message_service.MessageService()
        serv.set_visibility(None)
        self._services[serv.service_type] = serv

        self.service_names = sorted(self._services.keys())
 def test_get_versions(self):
     sot = catalog.ServiceCatalog(common.TEST_SERVICE_CATALOG_V3)
     service = compute_service.ComputeService()
     self.assertEqual(['v1.1', 'v1', 'v2.0'], sot.get_versions(service))
     service = identity_service.IdentityService()
     self.assertEqual(['v1.1'], sot.get_versions(service))
     service = image_service.ImageService()
     self.assertEqual(['v2'], sot.get_versions(service))
     service = network_service.NetworkService()
     self.assertEqual(None, sot.get_versions(service))
     service = object_store_service.ObjectStoreService()
     self.assertEqual([], sot.get_versions(service))
Example #18
0
class QuotaDefault(resource2.Resource):
    resource_key = 'quota_set'
    base_path = '/os-quota-sets'
    service = compute_service.ComputeService()
    # capabilities
    allow_get = True

    # Vpcu quantity quota
    cores = resource2.Body("cores", type=int)
    # Fixed IP quantity quota, this parameter is currently not supported
    fixed_ips = resource2.Body("fixed_ips", type=int)
    # Floating IP quantity quota, this parameter is currently not supported
    floating_ips = resource2.Body("floating_ips", type=int)
    # project UUID
    id = resource2.Body("id")
    # File size quota for injecting files, in bytes
    injected_file_content_bytes = resource2.Body("injected_file_content_bytes",
                                                 type=int)
    # Path size quota for injecting files, in bytes
    injected_file_path_bytes = resource2.Body("injected_file_path_bytes",
                                              type=int)
    # Inject file quota
    injected_files = resource2.Body("injected_files", type=int)
    # Cloud server quota
    instances = resource2.Body("instances", type=int)
    # Key pair quantity quota, this parameter is currently not supported
    key_pairs = resource2.Body("key_pairs", type=int)
    # Metadata quota
    metadata_items = resource2.Body("metadata_items", type=int)
    # Memory quota, in MB
    ram = resource2.Body("ram", type=int)
    # Quota for each security group rule, currently does not support this parameter
    security_group_rules = resource2.Body("security_group_rules", type=int)
    # Security group quantity quota, this parameter is currently not supported
    security_groups = resource2.Body("security_groups", type=int)
    # Cloud server group size quota
    server_group_members = resource2.Body("server_group_members", type=int)
    # Cloud server group quota
    server_groups = resource2.Body("server_groups", type=int)

    def _prepare_request(self, requires_id=True, prepend_key=False):
        body = self._body.dirty
        if prepend_key and self.resource_key is not None:
            body = {self.resource_key: body}

        headers = self._header.dirty

        if requires_id:
            if self.id is None:
                raise exceptions.InvalidRequest(
                    "Request requires an ID but none was found")
            uri = utils.urljoin(self.base_path, self.id, "defaults")
        return _Request(uri, body, headers)
Example #19
0
class Version(resource.Resource):
    resource_key = 'version'
    resources_key = 'versions'
    base_path = '/'
    service = compute_service.ComputeService()

    # capabilities
    allow_list = True

    # Properties
    links = resource.prop('links')
    status = resource.prop('status')
    updated = resource.prop('updated')
Example #20
0
class Keypair(resource.Resource):
    id_attribute = 'name'
    name_attribute = 'fingerprint'
    resource_key = 'keypair'
    resources_key = 'keypairs'
    base_path = '/os-keypairs'
    service = compute_service.ComputeService()

    # capabilities
    allow_create = True
    allow_retrieve = True
    allow_update = True
    allow_delete = True
    allow_list = True

    # Properties
    #: The short fingerprint associated with the ``public_key`` for
    #: this keypair.
    fingerprint = resource.prop('fingerprint')
    #: A name identifying the keypair
    name = resource.prop('name')
    #: The private key for the keypair
    private_key = resource.prop('private_key')
    #: The SSH public key that is paired with the server.
    public_key = resource.prop('public_key')

    def __init__(self, attrs=None, loaded=False):
        if attrs is not None:
            if 'keypair' in attrs:
                attrs = attrs['keypair']
        super(Keypair, self).__init__(attrs, loaded)

    def create(self, session):
        """Create a new keypair from this instance.

        This is needed because the name is the id, but we can't create one
        with a PUT.  That and we need the private_key out of the response.
        """
        resp = self.create_by_id(session, self._attrs, None, path_args=self)
        self._attrs = resp
        self._reset_dirty()
        return self

    @classmethod
    def find(cls, session, name_or_id, path_args=None):
        """Find a keypair by name because list filtering does not work."""
        try:
            return cls.get_by_id(session, name_or_id)
        except exceptions.HttpException:
            pass
        return None
Example #21
0
class Hypervisor(resource2.Resource):
    resource_key = 'hypervisor'
    resources_key = 'hypervisors'
    base_path = '/os-hypervisors'

    service = compute_service.ComputeService()

    # capabilities
    allow_get = True
    allow_list = True

    # Properties
    #: Status of hypervisor
    status = resource2.Body('status')
    #: State of hypervisor
    state = resource2.Body('state')
    #: Name of hypervisor
    name = resource2.Body('hypervisor_hostname')
    #: Service details
    service_details = resource2.Body('service')
    #: Count of the VCPUs in use
    vcpus_used = resource2.Body('vcpus_used')
    #: Count of all VCPUs
    vcpus = resource2.Body('vcpus')
    #: Count of the running virtual machines
    running_vms = resource2.Body('running_vms')
    #: The type of hypervisor
    hypervisor_type = resource2.Body('hypervisor_type')
    #: Version of the hypervisor
    hypervisor_version = resource2.Body('hypervisor_version')
    #: The amount, in gigabytes, of local storage used
    local_disk_used = resource2.Body('local_gb_used')
    #: The amount, in gigabytes, of the local storage device
    local_disk_size = resource2.Body('local_gb')
    #: The amount, in gigabytes, of free space on the local storage device
    local_disk_free = resource2.Body('free_disk_gb')
    #: The amount, in megabytes, of memory
    memory_used = resource2.Body('memory_mb_used')
    #: The amount, in megabytes, of total memory
    memory_size = resource2.Body('memory_mb')
    #: The amount, in megabytes, of available memory
    memory_free = resource2.Body('free_ram_mb')
    #: Measurement of the hypervisor's current workload
    current_workload = resource2.Body('current_workload')
    #: Information about the hypervisor's CPU
    cpu_info = resource2.Body('cpu_info')
    #: IP address of the host
    host_ip = resource2.Body('host_ip')
    #: Disk space available to the scheduler
    disk_available = resource2.Body("disk_available_least")
Example #22
0
class FlavorExtraSpecs(resource.Resource):
    resources_key = 'os-extra_specs'
    base_path = '/flavors/%(flavor_id)s/os-extra_specs'
    service = compute_service.ComputeService()

    #: The ID for the flavor.
    flavor_id = resource.URI('flavor_id')

    # capabilities
    allow_create = True
    allow_get = True
    allow_delete = True
    allow_list = True

    extra_specs = resource.Body('extra_specs')
Example #23
0
class VncAddress(resource2.Resource):
    base_path = '/servers/%(server_id)s/remote-consoles'

    service = compute_service.ComputeService()

    allow_create = True

    server_id = resource2.URI('server_id')

    # The total number of lists of elastic cloud servers.
    remote_console = resource2.Body('remote_console')
    # Elastic cloud server details list.
    type = resource2.Body('type')
    protocol = resource2.Body('protocol')
    url = resource2.Body('url')
Example #24
0
class Keypair(resource.Resource):
    resource_key = 'keypair'
    resources_key = 'keypairs'
    base_path = '/os-keypairs'
    service = compute_service.ComputeService()

    # capabilities
    allow_create = True
    allow_fetch = True
    allow_delete = True
    allow_list = True

    # Properties
    #: The short fingerprint associated with the ``public_key`` for
    #: this keypair.
    fingerprint = resource.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 listing
    # name as alternate_id and listing id as coming from name.
    #: The id identifying the keypair
    id = resource.Body('name')
    #: A name identifying the keypair
    name = resource.Body('name', alternate_id=True)
    #: The private key for the keypair
    private_key = resource.Body('private_key')
    #: The SSH public key that is paired with the server.
    public_key = resource.Body('public_key')

    def _consume_attrs(self, mapping, attrs):
        # TODO(mordred) This should not be required. However, without doing
        # it **SOMETIMES** keypair picks up id and not name. This is a hammer.
        if 'id' in attrs:
            attrs.setdefault('name', attrs.pop('id'))
        return super(Keypair, self)._consume_attrs(mapping, attrs)

    @classmethod
    def list(cls, session, paginated=False):
        resp = session.get(cls.base_path,
                           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
Example #25
0
class Extension(resource.Resource):
    resource_key = 'extension'
    resources_key = 'extensions'
    base_path = '/extensions'
    service = compute_service.ComputeService()

    # capabilities
    allow_list = True

    # Properties
    alias = resource.prop('alias')
    description = resource.prop('description')
    links = resource.prop('links')
    name = resource.prop('name')
    namespace = resource.prop('namespace')
    updated = resource.prop('updated')
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')
    #: state of availability zone
    state = resource2.Body('zoneState')
    #: hosts of availability zone
    hosts = resource2.Body('hosts')
Example #27
0
class Keypairs(resource.Resource):
    id_attribute = 'fingerprint'
    resource_key = 'keypairs'
    resources_key = 'keypairs'
    base_path = '/os-keypairs'
    service = compute_service.ComputeService()

    # capabilities
    allow_create = True
    allow_retrieve = True
    allow_update = True
    allow_delete = True
    allow_list = True

    # Properties
    fingerprint = resource.prop('fingerprint')
    name = resource.prop('name')
    public_key = resource.prop('public_key')
Example #28
0
class Flavor(resource.Resource):
    resource_key = 'flavor'
    resources_key = 'flavors'
    base_path = '/flavors'
    service = compute_service.ComputeService()

    # capabilities
    allow_create = True
    allow_fetch = True
    allow_delete = True
    allow_list = True

    _query_mapping = resource.QueryParameters("sort_key",
                                              "sort_dir",
                                              "is_public",
                                              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 = resource.Body('links')
    #: The name of this flavor.
    name = resource.Body('name')
    #: The description of the flavor.
    description = resource.Body('description')
    #: Size of the disk this flavor offers. *Type: int*
    disk = resource.Body('disk', type=int)
    #: ``True`` if this is a publicly visible flavor. ``False`` if this is
    #: a private image. *Type: bool*
    is_public = resource.Body('os-flavor-access:is_public', type=bool)
    #: The amount of RAM (in MB) this flavor offers. *Type: int*
    ram = resource.Body('ram', type=int)
    #: The number of virtual CPUs this flavor offers. *Type: int*
    vcpus = resource.Body('vcpus', type=int)
    #: Size of the swap partitions.
    swap = resource.Body('swap')
    #: Size of the ephemeral data disk attached to this server. *Type: int*
    ephemeral = resource.Body('OS-FLV-EXT-DATA:ephemeral', type=int)
    #: ``True`` if this flavor is disabled, ``False`` if not. *Type: bool*
    is_disabled = resource.Body('OS-FLV-DISABLED:disabled', type=bool)
    #: The bandwidth scaling factor this flavor receives on the network.
    rxtx_factor = resource.Body('rxtx_factor', type=float)
Example #29
0
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:`~openstack.session.Session`

        :returns: A Limits instance
        :rtype: :class:`~openstack.compute.v2.limits.Limits`
        """
        request = self._prepare_request(requires_id=False, prepend_key=False)
        endpoint_override = self.service.get_endpoint_override()
        response = session.get(request.uri,
                               endpoint_filter=self.service,
                               endpoint_override=endpoint_override)

        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
Example #30
0
class ServerIP(resource2.Resource):
    resources_key = 'addresses'
    base_path = '/servers/%(server_id)s/ips'
    service = compute_service.ComputeService()

    # capabilities
    allow_list = True

    # Properties
    #: The IP address. The format of the address depends on :attr:`version`
    address = resource2.Body('addr')
    #: The network label, such as public or private.
    network_label = resource2.URI('network_label')
    #: The ID for the server.
    server_id = resource2.URI('server_id')
    # Version of the IP protocol. Currently either 4 or 6.
    version = resource2.Body('version')

    @classmethod
    def list(cls,
             session,
             paginated=False,
             server_id=None,
             network_label=None,
             **params):
        url = cls.base_path % {"server_id": server_id}

        if network_label is not None:
            url = utils.urljoin(url, network_label)
        endpoint_override = cls.service.get_endpoint_override()
        resp = session.get(url,
                           endpoint_filter=cls.service,
                           endpoint_override=endpoint_override)
        resp = resp.json()

        if network_label is None:
            resp = resp[cls.resources_key]

        for label, addresses in resp.items():
            for address in addresses:
                yield cls.existing(network_label=label,
                                   address=address["addr"],
                                   version=address["version"])