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 ClusterPolicy(resource.Resource): resource_key = 'cluster_policy' resources_key = 'cluster_policies' base_path = '/clusters/%(cluster_id)s/policies' service = clustering_service.ClusteringService() # Capabilities allow_list = True allow_get = True _query_mapping = resource.QueryParameters( 'sort', 'policy_name', 'policy_type', is_enabled='enabled') # Properties #: ID of the policy object. policy_id = resource.Body('policy_id', alternate_id=True) #: Name of the policy object. policy_name = resource.Body('policy_name') #: ID of the cluster object. cluster_id = resource.URI('cluster_id') #: Name of the cluster object. cluster_name = resource.Body('cluster_name') #: Type string of the policy. policy_type = resource.Body('policy_type') #: Whether the policy is enabled on the cluster. *Type: bool* is_enabled = resource.Body('enabled', type=bool) #: Data associated with the cluster-policy binding. data = resource.Body('data', type=dict)
class Action(resource.Resource): resource_key = 'action' resources_key = 'actions' base_path = '/actions' service = clustering_service.ClusteringService() # Capabilities allow_list = True allow_get = True _query_mapping = resource.QueryParameters('name', 'action', 'status', 'sort', 'global_project', target_id='target') # Properties #: Name of the action. name = resource.Body('name') #: ID of the target object, which can be a cluster or a node. target_id = resource.Body('target') #: Built-in type name of action. action = resource.Body('action') #: A string representation of the reason why the action was created. cause = resource.Body('cause') #: The owning engine that is currently running the action. owner_id = resource.Body('owner') #: The ID of the user who created this action. user_id = resource.Body('user') #: The ID of the project this profile belongs to. project_id = resource.Body('project') #: The domain ID of the action. domain_id = resource.Body('domain') #: Interval in seconds between two consecutive executions. interval = resource.Body('interval') #: The time the action was started. start_at = resource.Body('start_time') #: The time the action completed execution. end_at = resource.Body('end_time') #: The timeout in seconds. timeout = resource.Body('timeout') #: Current status of the action. status = resource.Body('status') #: A string describing the reason that brought the action to its current # status. status_reason = resource.Body('status_reason') #: A dictionary containing the inputs to the action. inputs = resource.Body('inputs', type=dict) #: A dictionary containing the outputs to the action. outputs = resource.Body('outputs', type=dict) #: A list of actions that must finish before this action starts execution. depends_on = resource.Body('depends_on', type=list) #: A list of actions that can start only after this action has finished. depended_by = resource.Body('depended_by', type=list) #: Timestamp when the action is created. created_at = resource.Body('created_at') #: Timestamp when the action was last updated. updated_at = resource.Body('updated_at')
def test_service(self): sot = clustering_service.ClusteringService() self.assertEqual('clustering', 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)
class BuildInfo(resource.Resource): base_path = '/build-info' resource_key = 'build_info' service = clustering_service.ClusteringService() # Capabilities allow_get = True # Properties #: String representation of the API build version api = resource.Body('api') #: String representation of the engine build version engine = resource.Body('engine')
class Version(resource.Resource): resource_key = 'version' resources_key = 'versions' base_path = '/' service = clustering_service.ClusteringService( version=clustering_service.ClusteringService.UNVERSIONED) # capabilities allow_list = True # Properties links = resource.prop('links') status = resource.prop('status')
class Receiver(resource.Resource): resource_key = 'receiver' resources_key = 'receivers' base_path = '/receivers' service = clustering_service.ClusteringService() # Capabilities allow_list = True allow_get = True allow_create = True allow_update = True allow_delete = True patch_update = True _query_mapping = resource.QueryParameters('name', 'type', 'cluster_id', 'action', 'sort', 'global_project', user_id='user') # Properties #: The name of the receiver. name = resource.Body('name') #: The type of the receiver. type = resource.Body('type') #: The ID of the user who created the receiver, thus the owner of it. user_id = resource.Body('user') #: The ID of the project this receiver belongs to. project_id = resource.Body('project') #: The domain ID of the receiver. domain_id = resource.Body('domain') #: The ID of the targeted cluster. cluster_id = resource.Body('cluster_id') #: The name of the targeted action. action = resource.Body('action') #: Timestamp of when the receiver was created. created_at = resource.Body('created_at') #: Timestamp of when the receiver was last updated. updated_at = resource.Body('updated_at') #: The credential of the impersonated user. actor = resource.Body('actor', type=dict) #: A dictionary containing key-value pairs that are provided to the #: targeted action. params = resource.Body('params', type=dict) #: The information about the channel through which you can trigger the #: receiver hence the associated action. channel = resource.Body('channel', type=dict)
class PolicyType(resource.Resource): resource_key = 'policy_type' resources_key = 'policy_types' base_path = '/policy-types' service = clustering_service.ClusteringService() # Capabilities allow_list = True allow_get = True # Properties #: Name of policy type. name = resource.Body('name', alternate_id=True) #: The schema of the policy type. schema = resource.Body('schema') #: The support status of the policy type support_status = resource.Body('support_status')
class ClusterAttr(resource.Resource): resources_key = 'cluster_attributes' base_path = '/clusters/%(cluster_id)s/attrs/%(path)s' service = clustering_service.ClusteringService() # capabilities allow_list = True # Properties #: The identity of the cluster cluster_id = resource.URI('cluster_id') #: The json path string for attribute retrieval path = resource.URI('path') #: The id of the node that carries the attribute value. node_id = resource.Body('id') #: The value of the attribute requested. attr_value = resource.Body('value')
class Event(resource.Resource): resource_key = 'event' resources_key = 'events' base_path = '/events' service = clustering_service.ClusteringService() # Capabilities allow_list = True allow_get = True _query_mapping = resource.QueryParameters( 'cluster_id', 'action', 'level', 'sort', 'global_project', obj_id='oid', obj_name='oname', obj_type='otype', ) # Properties #: Timestamp string (in ISO8601 format) when the event was generated. generated_at = resource.Body('timestamp') #: The UUID of the object related to this event. obj_id = resource.Body('oid') #: The name of the object related to this event. obj_name = resource.Body('oname') #: The type name of the object related to this event. obj_type = resource.Body('otype') #: The UUID of the cluster related to this event, if any. cluster_id = resource.Body('cluster_id') #: The event level (priority). level = resource.Body('level') #: The ID of the user. user_id = resource.Body('user') #: The ID of the project (tenant). project_id = resource.Body('project') #: The string representation of the action associated with the event. action = resource.Body('action') #: The status of the associated object. status = resource.Body('status') #: A string description of the reason that brought the object into its #: current status. status_reason = resource.Body('status_reason')
class ProfileType(resource.Resource): resource_key = 'profile_type' resources_key = 'profile_types' base_path = '/profile-types' service = clustering_service.ClusteringService() # Capabilities allow_list = True allow_get = True # Properties #: Name of the profile type. name = resource.Body('name', alternate_id=True) #: The schema of the profile type. schema = resource.Body('schema') #: The support status of the profile type support_status = resource.Body('support_status') def type_ops(self, session): url = utils.urljoin(self.base_path, self.id, 'ops') resp = session.get(url) return resp.json()
class Service(resource.Resource): resource_key = 'service' resources_key = 'services' base_path = '/services' service = clustering_service.ClusteringService() # Capabilities allow_list = True # Properties #: Status of service status = resource.Body('status') #: State of service state = resource.Body('state') #: Name of service binary = resource.Body('binary') #: Disabled reason of service disabled_reason = resource.Body('disabled_reason') #: Host where service runs host = resource.Body('host') #: The timestamp the service was last updated. #: *Type: datetime object parsed from ISO 8601 formatted string* updated_at = resource.Body('updated_at')
class Profile(resource.Resource): resource_key = 'profile' resources_key = 'profiles' base_path = '/profiles' service = clustering_service.ClusteringService() # capabilities allow_create = True allow_fetch = True allow_commit = True allow_delete = True allow_list = True commit_method = 'PATCH' _query_mapping = resource.QueryParameters( 'sort', 'global_project', 'type', 'name') # Bodyerties #: The name of the profile name = resource.Body('name') #: The type of the profile. type = resource.Body('type') #: The ID of the project this profile belongs to. project_id = resource.Body('project') #: The domain ID of the profile. domain_id = resource.Body('domain') #: The ID of the user who created this profile. user_id = resource.Body('user') #: The spec of the profile. spec = resource.Body('spec', type=dict) #: A collection of key-value pairs that are attached to the profile. metadata = resource.Body('metadata', type=dict) #: Timestamp of when the profile was created. created_at = resource.Body('created_at') #: Timestamp of when the profile was last updated. updated_at = resource.Body('updated_at')
class Policy(resource.Resource): resource_key = 'policy' resources_key = 'policies' base_path = '/policies' service = clustering_service.ClusteringService() # Capabilities allow_list = True allow_fetch = True allow_create = True allow_delete = True allow_commit = True commit_method = 'PATCH' _query_mapping = resource.QueryParameters('name', 'type', 'sort', 'global_project') # Properties #: The name of the policy. name = resource.Body('name') #: The type name of the policy. type = resource.Body('type') #: The ID of the project this policy belongs to. project_id = resource.Body('project') # The domain ID of the policy. domain_id = resource.Body('domain') #: The ID of the user who created this policy. user_id = resource.Body('user') #: The timestamp when the policy is created. created_at = resource.Body('created_at') #: The timestamp when the policy was last updated. updated_at = resource.Body('updated_at') #: The specification of the policy. spec = resource.Body('spec', type=dict) #: A dictionary containing runtime data of the policy. data = resource.Body('data', type=dict)
class Node(resource.Resource): resource_key = 'node' resources_key = 'nodes' base_path = '/nodes' service = clustering_service.ClusteringService() # capabilities allow_create = True allow_get = True allow_update = True allow_delete = True allow_list = True patch_update = True _query_mapping = resource.QueryParameters('show_details', 'name', 'sort', 'global_project', 'cluster_id', 'status') # Properties #: The name of the node. name = resource.Body('name') #: The ID of the physical object that backs the node. physical_id = resource.Body('physical_id') #: The ID of the cluster in which this node is a member. #: A node is an orphan node if this field is empty. cluster_id = resource.Body('cluster_id') #: The ID of the profile used by this node. profile_id = resource.Body('profile_id') #: The domain ID of the node. domain_id = resource.Body('domain') #: The ID of the user who created this node. user_id = resource.Body('user') #: The ID of the project this node belongs to. project_id = resource.Body('project') #: The name of the profile used by this node. profile_name = resource.Body('profile_name') #: An integer that is unique inside the owning cluster. #: A value of -1 means this node is an orphan node. index = resource.Body('index', type=int) #: A string indicating the role the node plays in a cluster. role = resource.Body('role') #: The timestamp of the node object's initialization. #: *Type: datetime object parsed from ISO 8601 formatted string* init_at = resource.Body('init_at') #: The timestamp of the node's creation, i.e. the physical object #: represented by this node is also created. #: *Type: datetime object parsed from ISO 8601 formatted string* created_at = resource.Body('created_at') #: The timestamp the node was last updated. #: *Type: datetime object parsed from ISO 8601 formatted string* updated_at = resource.Body('updated_at') #: A string indicating the node's status. status = resource.Body('status') #: A string describing why the node entered its current status. status_reason = resource.Body('status_reason') #: A map containing key-value pairs attached to the node. metadata = resource.Body('metadata', type=dict) #: A map containing some runtime data for this node. data = resource.Body('data', type=dict) #: A map containing the details of the physical object this node #: represents details = resource.Body('details', type=dict) #: A map containing the dependency of nodes dependents = resource.Body('dependents', type=dict) def _action(self, session, body): """Procedure the invoke an action API. :param session: A session object used for sending request. :param body: The body of action to be sent. """ url = utils.urljoin(self.base_path, self.id, 'actions') resp = session.post(url, json=body) return resp.json() def check(self, session, **params): """An action procedure for the node to check its health status. :param session: A session object used for sending request. :returns: A dictionary containing the action ID. """ body = {'check': params} return self._action(session, body) def recover(self, session, **params): """An action procedure for the node to recover. :param session: A session object used for sending request. :returns: A dictionary containing the action ID. """ body = {'recover': params} return self._action(session, body) def op(self, session, operation, **params): """Perform an operation on the specified node. :param session: A session object used for sending request. :param operation: A string representing the operation to be performed. :param dict params: An optional dict providing the parameters for the operation. :returns: A dictionary containing the action ID. """ url = utils.urljoin(self.base_path, self.id, 'ops') resp = session.post(url, json={operation: params}) return resp.json() def adopt(self, session, preview=False, **params): """Adopt a node for management. :param session: A session object used for sending request. :param preview: A boolean indicating whether the adoption is a preview. A "preview" does not create the node object. :param dict params: A dict providing the details of a node to be adopted. """ if preview: path = 'adopt-preview' attrs = { 'identity': params.get('identity'), 'overrides': params.get('overrides'), 'type': params.get('type'), 'snapshot': params.get('snapshot') } else: path = 'adopt' attrs = params url = utils.urljoin(self.base_path, path) resp = session.post(url, json=attrs) if preview: return resp.json() self._translate_response(resp) return self def force_delete(self, session): """Force delete a node.""" body = {'force': True} url = utils.urljoin(self.base_path, self.id) resp = session.delete(url, json=body) self._translate_response(resp) return self
class Cluster(resource.Resource): resource_key = 'cluster' resources_key = 'clusters' base_path = '/clusters' service = clustering_service.ClusteringService() # capabilities allow_create = True allow_get = True allow_update = True allow_delete = True allow_list = True patch_update = True _query_mapping = resource.QueryParameters( 'name', 'status', 'sort', 'global_project') # Properties #: The name of the cluster. name = resource.Body('name') #: The ID of the profile used by this cluster. profile_id = resource.Body('profile_id') #: The ID of the user who created this cluster, thus the owner of it. user_id = resource.Body('user') #: The ID of the project this cluster belongs to. project_id = resource.Body('project') #: The domain ID of the cluster owner. domain_id = resource.Body('domain') #: Timestamp of when the cluster was initialized. #: *Type: datetime object parsed from ISO 8601 formatted string* init_at = resource.Body('init_at') #: Timestamp of when the cluster was created. #: *Type: datetime object parsed from ISO 8601 formatted string* created_at = resource.Body('created_at') #: Timestamp of when the cluster was last updated. #: *Type: datetime object parsed from ISO 8601 formatted string* updated_at = resource.Body('updated_at') #: Lower bound (inclusive) for the size of the cluster. min_size = resource.Body('min_size', type=int) #: Upper bound (inclusive) for the size of the cluster. A value of #: -1 indicates that there is no upper limit of cluster size. max_size = resource.Body('max_size', type=int) #: Desired capacity for the cluster. A cluster would be created at the #: scale specified by this value. desired_capacity = resource.Body('desired_capacity', type=int) #: Default timeout (in seconds) for cluster operations. timeout = resource.Body('timeout') #: A string representation of the cluster status. status = resource.Body('status') #: A string describing the reason why the cluster in current status. status_reason = resource.Body('status_reason') #: A dictionary configuration for cluster. config = resource.Body('config', type=dict) #: A collection of key-value pairs that are attached to the cluster. metadata = resource.Body('metadata', type=dict) #: A dictionary with some runtime data associated with the cluster. data = resource.Body('data', type=dict) #: A list IDs of nodes that are members of the cluster. node_ids = resource.Body('nodes') #: Name of the profile used by the cluster. profile_name = resource.Body('profile_name') #: Specify whether the cluster update should only pertain to the profile. is_profile_only = resource.Body('profile_only', type=bool) #: A dictionary with dependency information of the cluster dependents = resource.Body('dependents', type=dict) def action(self, session, body): url = utils.urljoin(self.base_path, self._get_id(self), 'actions') resp = session.post(url, json=body) return resp.json() def add_nodes(self, session, nodes): body = { 'add_nodes': { 'nodes': nodes, } } return self.action(session, body) def del_nodes(self, session, nodes, **params): data = {'nodes': nodes} data.update(params) body = { 'del_nodes': data } return self.action(session, body) def replace_nodes(self, session, nodes): body = { 'replace_nodes': { 'nodes': nodes, } } return self.action(session, body) def scale_out(self, session, count=None): body = { 'scale_out': { 'count': count, } } return self.action(session, body) def scale_in(self, session, count=None): body = { 'scale_in': { 'count': count, } } return self.action(session, body) def resize(self, session, **params): body = { 'resize': params } return self.action(session, body) def policy_attach(self, session, policy_id, **params): data = {'policy_id': policy_id} data.update(params) body = { 'policy_attach': data } return self.action(session, body) def policy_detach(self, session, policy_id): body = { 'policy_detach': { 'policy_id': policy_id, } } return self.action(session, body) def policy_update(self, session, policy_id, **params): data = {'policy_id': policy_id} data.update(params) body = { 'policy_update': data } return self.action(session, body) def check(self, session, **params): body = { 'check': params } return self.action(session, body) def recover(self, session, **params): body = { 'recover': params } return self.action(session, body) def op(self, session, operation, **params): """Perform an operation on the cluster. :param session: A session object used for sending request. :param operation: A string representing the operation to be performed. :param dict params: An optional dict providing the parameters for the operation. :returns: A dictionary containing the action ID. """ url = utils.urljoin(self.base_path, self.id, 'ops') resp = session.post(url, json={operation: params}) return resp.json() def force_delete(self, session): """Force delete a cluster.""" body = {'force': True} url = utils.urljoin(self.base_path, self.id) resp = session.delete(url, json=body) self._translate_response(resp) return self
class ServicesMixin(object): identity = identity_service.IdentityService(service_type='identity') compute = compute_service.ComputeService(service_type='compute') image = image_service.ImageService(service_type='image') load_balancer = load_balancer_service.LoadBalancerService( service_type='load-balancer') object_store = object_store_service.ObjectStoreService( service_type='object-store') clustering = clustering_service.ClusteringService( service_type='clustering') resource_cluster = clustering cluster = clustering data_processing = service_description.ServiceDescription( service_type='data-processing') baremetal = baremetal_service.BaremetalService(service_type='baremetal') bare_metal = baremetal baremetal_introspection = baremetal_introspection_service.BaremetalIntrospectionService( service_type='baremetal-introspection') key_manager = key_manager_service.KeyManagerService( service_type='key-manager') resource_optimization = service_description.ServiceDescription( service_type='resource-optimization') infra_optim = resource_optimization message = message_service.MessageService(service_type='message') messaging = message application_catalog = service_description.ServiceDescription( service_type='application-catalog') container_infrastructure_management = service_description.ServiceDescription( service_type='container-infrastructure-management') container_infrastructure = container_infrastructure_management container_infra = container_infrastructure_management search = service_description.ServiceDescription(service_type='search') dns = dns_service.DnsService(service_type='dns') workflow = workflow_service.WorkflowService(service_type='workflow') rating = service_description.ServiceDescription(service_type='rating') operator_policy = service_description.ServiceDescription( service_type='operator-policy') policy = operator_policy shared_file_system = service_description.ServiceDescription( service_type='shared-file-system') share = shared_file_system data_protection_orchestration = service_description.ServiceDescription( service_type='data-protection-orchestration') orchestration = orchestration_service.OrchestrationService( service_type='orchestration') block_storage = block_storage_service.BlockStorageService( service_type='block-storage') block_store = block_storage volume = block_storage alarm = service_description.ServiceDescription(service_type='alarm') alarming = alarm meter = service_description.ServiceDescription(service_type='meter') metering = meter telemetry = meter event = service_description.ServiceDescription(service_type='event') events = event application_deployment = service_description.ServiceDescription( service_type='application-deployment') application_deployment = application_deployment multi_region_network_automation = service_description.ServiceDescription( service_type='multi-region-network-automation') tricircle = multi_region_network_automation database = database_service.DatabaseService(service_type='database') application_container = service_description.ServiceDescription( service_type='application-container') container = application_container root_cause_analysis = service_description.ServiceDescription( service_type='root-cause-analysis') rca = root_cause_analysis nfv_orchestration = service_description.ServiceDescription( service_type='nfv-orchestration') network = network_service.NetworkService(service_type='network') backup = service_description.ServiceDescription(service_type='backup') monitoring_logging = service_description.ServiceDescription( service_type='monitoring-logging') monitoring_log_api = monitoring_logging monitoring = service_description.ServiceDescription( service_type='monitoring') monitoring_events = service_description.ServiceDescription( service_type='monitoring-events') placement = service_description.ServiceDescription( service_type='placement') instance_ha = instance_ha_service.InstanceHaService( service_type='instance-ha') ha = instance_ha reservation = service_description.ServiceDescription( service_type='reservation') function_engine = service_description.ServiceDescription( service_type='function-engine') accelerator = accelerator_service.AcceleratorService( service_type='accelerator') admin_logic = service_description.ServiceDescription( service_type='admin-logic') registration = admin_logic