class Database(resource2.Resource): resource_key = "database" resources_key = "databases" base_path = '/instances/%(instance_id)s/databases' service = database_service.DatabaseService() # Capabilities allow_create = True allow_delete = True allow_list = True allow_update = False allow_get = False # Properties #: Name of Database. name = resource2.Body('name', alternate_id=True) #: Character set of Database. character_set = resource2.Body('character_set') #: Collate of Database. collate = resource2.Body('collate') #: ID of instance associated with this database instance_id = resource2.URI('instance_id') def create(self, session, instance_id, **attrs): base = self.base_path % {"instance_id": instance_id} body = {"databases": [attrs]} resp = session.post(base, endpoint_filter=self.service, json=body, headers={"Accept": "application/json"}) self._translate_response(resp, has_body=False) return self
class User(resource2.Resource): resource_key = "user" resources_key = "users" base_path = '/instances/%(instance_id)s/users' service = database_service.DatabaseService() # _query_mapping = resource2.QueryParameters() # Capabilities allow_create = True allow_delete = True allow_list = True allow_update = True allow_get = True # Properties #: User's name of Database instance. name = resource2.Body('name', alternate_id=True) #: Allowed access host of user. host = resource2.Body('host') #: Relevant database of this user. databases = resource2.Body('databases', type=list) #: User's password of Database instance. #: This parameter is only used in instance creation. password = resource2.Body('password') #: ID of instance associated with this user instance_id = resource2.URI('instance_id') def create(self, session, instance_id, **attrs): base = self.base_path % {"instance_id": instance_id} body = {"users": [attrs]} resp = session.post(base, endpoint_filter=self.service, json=body, headers={"Accept": "application/json"}) self._translate_response(resp, has_body=False) return self def grant(self, session, instance_id, user, databases): base = self.base_path % {"instance_id": instance_id} uri = "%s/%s/databases" % (base, user) resp = session.put(uri, endpoint_filter=self.service, json={"databases": databases}) self._translate_response(resp, has_body=False) return self def revoke(self, session, instance_id, user, database): base = self.base_path % {"instance_id": instance_id} uri = uri = "%s/%s/databases/%s" % (base, user, database) resp = session.delete(uri, endpoint_filter=self.service) self._translate_response(resp, has_body=False) return self
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( object_store_service.ObjectStoreService(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="v1")) self._add_service( security_portal_service.SecurityPortalService(version="v1")) 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(database_service.DatabaseService(version="v1")) self._add_service(dns_service.DnsService(version="v2")) self._add_service( virtual_network_appliance_service.VirtualNetworkApplianceService( 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 Version(resource2.Resource): resource_key = 'version' resources_key = 'versions' base_path = '' service = database_service.DatabaseService( version=database_service.DatabaseService.UNVERSIONED) # capabilities allow_list = True allow_get = True # Properties #: Version identifier included in API URL. id = resource2.Body('id') #: List of API endpoint link. links = resource2.Body('links') #: Version support status. Valid values are CURRENT or SUPPORTED. #: CURRENT is newest stable version. SUPPORTED is old supported version. status = resource2.Body('status') def get_version(self, session): url = self.base_path + '/v1.0' resp = session.get(url, headers={"Accept": "application/json"}, endpoint_filter=self.service) self._translate_response(resp, has_body=True) return self def list_version(self, session): url = self.base_path resp = session.get(url, headers={"Accept": "application/json"}, endpoint_filter=self.service) resp = resp.json()[self.resources_key] for data in resp: version = self.existing(**data) yield version
class Datastore(resource2.Resource): resource_key = None resources_key = 'datastores' base_path = '/datastores' service = database_service.DatabaseService() # capabilities allow_list = True _query_mapping = resource2.QueryParameters() # Properties #: The ID of this datastore id = resource2.Body('id') #: The name of this datastore. name = resource2.Body('name') #: Size of the disk this datastore offers. *Type: int* default_version = resource2.Body('default_version') #: The amount of RAM (in MB) this datastore offers. *Type: int* versions = resource2.Body('versions') #: Links pertaining to this datastore. This is a list of dictionaries, #: each including keys ``href`` and ``rel``. links = resource2.Body('links')
class Flavor(resource2.Resource): resource_key = 'flavor' resources_key = 'flavors' base_path = '/flavors' service = database_service.DatabaseService() # capabilities allow_get = True allow_list = True _query_mapping = resource2.QueryParameters() # 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('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) #: ID str_id = resource2.Body('str_id', alternate_id=True)
class Instance(resource2.Resource): resource_key = 'instance' resources_key = 'instances' base_path = '/instances' service = database_service.DatabaseService() # capabilities allow_create = True allow_get = True allow_delete = True allow_list = True allow_update = False _query_mapping = resource2.QueryParameters() #: ID of the server id = resource2.Body('id') #: Timestamp of when the instance was created. created_at = resource2.Body('created') #: The datastore property returned as instence property. datastore = resource2.Body('datastore', type=dict) #: The flavor property returned from instance. flavor = resource2.Body('flavor', type=dict) #: The flavor reference, as a ID or full URL, #: in case create instane. flavor_id = resource2.Body('flavorRef') #: An ID representing the host of this instance. hostname = resource2.Body('hostname') #: A list of dictionaries holding links relevant to this instance. links = resource2.Body('links', type=list) #: Name of the instance name = resource2.Body('name') #: Region of the instance region = resource2.Body('region') #: The state this instance is in. status = resource2.Body('status') #: Timestamp of when this instance was last updated. updated_at = resource2.Body('updated') #: The volume property returned from instance. volume = resource2.Body('volume', type=dict) #: A nic definition object. Required parameter when there are multiple #: networks defined for the tenant. nics = resource2.Body('nics', type=dict) #: Databases list of instance. databases = resource2.Body('databases', type=list) #: Users list of instance. users = resource2.Body('users', type=list) #: Backup window of instance. backup_window = resource2.Body('backup_window') #: Maintenance window of instance. maintenance_window = resource2.Body('maintenance_window') #: Backup retension period of this instance. backup_retention_period = resource2.Body('backup_retention_period', type=int) #: Restore Point restore_point = resource2.Body('restorePoint', type=dict) #: Restoreable Time restorable_time = resource2.Body('restorable_time') #: Endpoints endpoints = resource2.Body('endpoints', type=list) #: Availability Zone availability_zone = resource2.Body('availability_zone') @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))