class Channel(resource2.Resource): resource_key = None resources_key = "channels" base_path = "/channels?get_contracts=%(get_contracts)s" service = sss_service.SssService() #Capabilities allow_list = True #_query_mapping = resource2.QueryParameters("get_contracts") #Properties #: Channel ID. channel_id = resource2.Body("channel_id", alternate_id=True) #: Channel name. channel_name = resource2.Body("channel_name") #: This item setting will relate to language setting of E-mail that will #: send by ECL2.0. Please note that NOT related to user's display language #: setting(That setting is rely on the user browser's language setting.) language = resource2.Body("language") #: Whether this channel_id is the partner management channel(true), or #: not(false). management_channel = resource2.Body("management_channel") #: The parent channel ID means partner's channel ID that belongs the end #: user. parent_channel_id = resource2.Body("parent_channel_id") #: List of contracts has two parameters: #: contract_id: Contract ID. #: status: The status of the contract(enable or deleted). contracts = resource2.Body("contracts") def __init__(self, synchronized=False, **attrs): super(Channel, self).__init__(synchronized=synchronized, **attrs) if "get_contracts" in attrs: attrs.pop("get_contracts")
class Role(resource2.Resource): resource_key = None resources_key = None base_path = '/roles' service = sss_service.SssService() # Capabilities allow_create = True allow_delete = True put_create = False # Properties #: User's id who was attached with the role. user_id = resource2.Body('user_id') #: Region id which the tenant belongs to. region_id = resource2.Body('region_id') #: Region name which the tenant belongs to. region_name = resource2.Body('region_name') #: Tenant's id which is attached with the role. tenant_id = resource2.Body('tenant_id') #: Tenant's name which is attached with the role. tenant_name = resource2.Body('tenant_name') #: Attached role's name. role_name = resource2.Body('role_name', alternate_id=True) def delete(self, session, tenant_id, user_id): """Delete role with given tenant id and user id""" url = '/roles/tenants/%s/users/%s' % (tenant_id, user_id) resp = session.delete(url, endpoint_filter=self.service) self._translate_response(resp, has_body=False) return self
def test_service(self): sot = sss_service.SssService() self.assertEqual('sss', 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('v1', sot.valid_versions[0].module) self.assertEqual('v1', 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 Api_key(resource2.Resource): resource_key = None resources_key = None base_path = '/keys' service = sss_service.SssService() # Capabilities allow_update = True # Properties #: User's id whose API key updated. user_id = resource2.Body('user_id', alternate_id=True) #: New API key(keystone username) keystone_name = resource2.Body('keystone_name') #: New API secret(keystone password) keystone_password = resource2.Body('keystone_password') #: Update status. 'Success' for successful update status = resource2.Body('status') def update(self, session, user_id): url = '/keys/%s' % user_id resp = session.put(url, endpoint_filter=self.service) self._translate_response(resp, has_body=True) return self
class Contract(resource2.Resource): resource_key = None resources_key = None base_path = '/contracts' service = sss_service.SssService() # Capabilities allow_create = True allow_get = True allow_delete = True allow_list = True put_create = False # Properties #: Contract ID. contract_id = resource2.Body('contract_id', alternate_id=True) #: Login ID of user. login_id = resource2.Body('login_id') #: E-mail address of the user. mail_address = resource2.Body('mail_addresss') #: Password of the user. If user set this item as blank, the system #: set initial random password automatically. password = resource2.Body('password') #: By using this item, the partner API user can associate optional #: string to the constract(e.g. The end user management ID in the #: partner user's system). Note that this ID will be NOT used to #: control the contract in ECL2.0 internal system. If the item is #: set as blank, ECL 2.0 system set the end user's contract ID #: automatically external_reference_id = resource2.Body('external_reference_id') #: Setting true or false(default is false). This item designate #: whether the system should send to the login_ID and Password with #: e-mail. notify_password = resource2.Body('notify_password') #: User id. format is ecid[0-9]{10}. user_id = resource2.Body('user_id') #: This user's API key for keystone authentication. keystone_name = resource2.Body('keystone_name') #: This user's API secret for keystone authentication. keystone_password = resource2.Body('keystone_password') #: Keystone address this user can use to get token for SSS API #: request. keystone_endpoint = resource2.Body('keystone_endpoint') #: SSS endpoint recommended for user. sss_endpoint = resource2.Body('sss_endpoint') #: status status = resource2.Body('status') #: customer_name customer_name = resource2.Body('customer_name') #: This ID is equal to external_reference_id. customer_number = resource2.Body('customer_number') #: Channel name. channel_name = resource2.Body('channel_name') #: Channel ID of this contract. channel_id = resource2.Body('channel_id') #: Whether this channel_id is the partner management channel(true), #: or not(false). management_channel = resource2.Body('management_channel') #: The owner user ID in the Contract contract_owner_user_id = resource2.Body('contract_owner_user_id') #: Start time of the contract start_time = resource2.Body('start_time') #: End time of the contract end_time = resource2.Body('end_time') #: Internal use(Login type) login_integration = resource2.Body('login_integration') #: Access point to use APIs in the decided region sss_endpoint = resource2.Body('sss_endpoint') #: keystone_endpoint keystone_endpoint = resource2.Body('keystone_endpoint') #: Internal use company_code = resource2.Body('company_code') #: Internal use glass_customer_id = resource2.Body('glass_customer_id') #: Internal use glass_user_id = resource2.Body('glass_user_id') #: The status of the acquired charge information (estimated: #: undetermined / fixed: Committed) charge_status = resource2.Body('charge_status') #: Period of the acquired charge information(Start time) cycle_start_time = resource2.Body('cycle_start_time') #: Period of the acquired charge information(End time) cycle_end_time = resource2.Body('cycle_end_time') #: The detail of billing information charge_data = resource2.Body('charge_data') #: The designated contract ID by request's target_contract_id. owner_contract_id = resource2.Body('owner_contract_id') def list(self, session, channel_id, include_deleted): """List contracts by channel id""" url = self.base_path + '?channel_id=%s&include_deleted=%s' % ( channel_id, include_deleted) resp = session.get(url, endpoint_filter=self.service) self._translate_response(resp, has_body=True) return self def get_billing_info(self, session, channel_id, target_month): """Get billing information by channel id and target month""" url = self.base_path + '/%s/billing/%s' % (channel_id, target_month) resp = session.get(url, endpoint_filter=self.service) self._translate_response(resp, has_body=True) return self def get_monthly_billing_of_each_contract(self, session, contract_id, target_month, target_contract_id): """Get montly billing for each contract.""" url = self.base_path + "/%s/billing/%s/target_contract/%s" % ( contract_id, target_month, target_contract_id) resp = session.get(url, endpoint_filter=self.service) self._translate_response(resp, has_body=True) return self
class Tenant(resource2.Resource): resources_key = 'tenants' resource_key = None base_path = '/tenants' service = sss_service.SssService() # Capabilities allow_create = True allow_delete = True allow_list = True put_create = False # Properties #: Tenant's id. tenant_id = resource2.Body("tenant_id", alternate_id=True) #: Tenant name. tenant_name = resource2.Body("tenant_name") #: Tenant's description. description = resource2.Body("description") #: Region which the tenant belongs to. region = resource2.Body("region") #: Contract which the tenant belongs to. contract_id = resource2.Body("contract_id") @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))