class InstanceParameter(_rdsresource.Resource):

    base_path = 'instances/%(instance_id)s/configurations'
    resources_key = "restart_required"
    service = rds_service.RDSServiceV3()
    restart_required = resource.Body('restart_required')

    def set_params(self, session, **params):
        uri = self.base_path % params
        params.pop('instance_id')
        body = {'values': params}
        endpoint_override = self.service.get_endpoint_override()
        if endpoint_override is None:
            uri = self._get_custom_url(session, uri)
        else:
            endpoint_override = self._get_custom_override(endpoint_override)
        response = session.put(uri,
                               endpoint_filter=self.service,
                               endpoint_override=endpoint_override,
                               raise_exc=False,
                               headers={
                                   "Accept": "application/json",
                                   "Content-type": "application/json",
                                   "X-Language": "en-us"
                               },
                               json=body)
        if response.status_code >= 400:
            return ErrorResponse.make_response(response)

        self._translate_response(response)
        return self
class InstanceSlowLog(_rdsresource.Resource):

    base_path = 'instances/%(instance_id)s/slowlog'
    resources_key = 'slow_log_list'
    service = rds_service.RDSServiceV3()

    _query_mapping = resource.QueryParameters('start_date', 'end_date',
                                              'offset', 'limit', 'type')

    # capabilities
    allow_list = True
    # Properties
    # instanceId
    instanceId = resource.URI('instance_id')
    # Execuation count
    count = resource.Body('count')
    # Average time
    time = resource.Body('time')
    # Average time for waiting lock
    lockTime = resource.Body('lockTime')
    # Average sent rows
    rowsSent = resource.Body('rowsSent')
    # Average examined rows
    rowsExamined = resource.Body('rowsExamined')
    # Database belonged
    database = resource.Body('database')
    # User account
    users = resource.Body('users')
    # Query sample
    querySample = resource.Body('querySample')
Beispiel #3
0
class Parameter(_rdsresource.Resource):

    base_path = '/datastores/versions/%(datastore_version_id)s/parameters'
    resources_key = 'configuration-parameters'
    service = rds_service.RDSServiceV3()

    # capabilities
    allow_list = True
    allow_get = True

    # Properties
    #: Parameter name
    name = resource.Body('name', alternate_id=True)
    #: Minimum value of the parameter
    #: *Type: int*
    min = resource.Body('min', type=int)
    #: Maximum value of the parameter
    #: *Type: int*
    max = resource.Body('max', type=int)
    #: Parameter type
    type = resource.Body('type')
    #: Value range
    value_range = resource.Body('value_range')
    #: Description
    description = resource.Body('description')
    #: Require restart or not
    #: *Type: bool*
    restart_required = resource.Body('restart_required', type=bool)
    #: Datastore version id
    datastore_version_id = resource.URI('datastore_version_id')
Beispiel #4
0
class Backup(_rdsresource.Resource):

    base_path = '/backups'
    resource_key = 'backup'
    resources_key = 'backups'
    service = rds_service.RDSServiceV3()
    error_key = 'error_code'
    base_files_path = '/backup-files'

    _query_mapping = resource.QueryParameters('instance_id', 'backup_id',
                                              'backup_type', 'offset', 'limit',
                                              'begin_time', 'end_time')

    # capabilities
    allow_create = True
    allow_delete = True
    allow_list = True

    # Properties
    #: Backup id
    id = resource.Body('id')
    #: Instance id
    instance_id = resource.Body('instance_id')
    #: Instance id alt
    instance = resource.Body('instance')
    #: Backup created time
    created = resource.Body('created')
    #: Data store information
    #: *Type: dict*
    dataStore = resource.Body('dataStore', type=dict)
    #: Data backup description
    description = resource.Body('description')
    #: Back file name
    name = resource.Body('name')
    #: Back file size in GB
    #: *Type:int*
    size = resource.Body('size', type=int)
    #: Backup status
    status = resource.Body('status')
    #: Finished time
    updated = resource.Body('updated')
    #: Backup type
    backuptype = resource.Body('backuptype')

    def create(self, session, prepend_key=True):
        endpoint_override = self.service.get_endpoint_override()
        request = self._prepare_request(requires_id=False, prepend_key=False)
        if endpoint_override is None:
            request.uri = self._get_custom_url(session, request.uri)
        response = session.post(request.uri,
                                endpoint_filter=self.service,
                                endpoint_override=endpoint_override,
                                json=request.body,
                                headers=request.headers,
                                raise_exc=False)
        if response.status_code >= 400:
            return ErrorResponse.make_response(response)
        self._translate_response(response)
        return self
class InstanceRestoreTime(_rdsresource.Resource):

    base_path = 'instances/%(instance_id)s/restore-time'
    resources_key = 'errorLogList'
    service = rds_service.RDSServiceV3()

    _query_mapping = resource.QueryParameters('date')

    # capabilities
    allow_list = True
    # Properties
    # instanceId
    instanceId = resource.URI('instanceId')
    # Error log data time
    datetime = resource.Body('datetime')
    #: Error log content
    content = resource.Body('content')
class Configurations(_rdsresource.Resource):
    base_path = '/configurations'
    resources_key = 'configurations'
    service = rds_service.RDSServiceV3()

    # capabilities
    allow_list = True

    id = resource.Body('id')
    spec_code = resource.Body('spec_code')
    name = resource.Body('name')
    description = resource.Body('description')
    datastore_version_name = resource.Body('datastore_version_name')
    datastore_name = resource.Body('datastore_name')
    created = resource.Body('created')
    updated = resource.Body('updated')
    user_defined = resource.Body('user_defined', type=bool)
class InstanceErrorLog(_rdsresource.Resource):

    base_path = 'instances/%(instance_id)s/errorlog'
    resources_key = 'error_log_list'
    service = rds_service.RDSServiceV3()

    _query_mapping = resource.QueryParameters('start_date', 'end_date',
                                              'offset', 'limit', 'level')

    # capabilities
    allow_list = True
    # Properties
    # instanceId
    instanceId = resource.URI('instance_id')
    # Error log data time
    datetime = resource.Body('datetime')
    #: Error log content
    content = resource.Body('content')
Beispiel #8
0
class Flavor(_rdsresource.Resource):

    base_path = '/flavors/%(database_name)s'
    resource_key = 'flavor'
    resources_key = 'flavors'
    service = rds_service.RDSServiceV3()

    _query_mapping = resource.QueryParameters('version_name')

    # capabilities
    allow_get = True
    allow_list = True

    # Properties
    ram = resource.Body('ram', type=int)
    vcpus = resource.Body('vcpus')
    instance_mode = resource.Body('instance_mode')
    spec_code = resource.Body('spec_code')
Beispiel #9
0
class Database(_rdsresource.Resource):
    base_path = 'instances/%(instance_id)s/database'
    resources_key = 'databases'
    service = rds_service.RDSServiceV3()

    _query_mapping = resource.QueryParameters('page', 'limit')

    # capabilities
    allow_create = True
    allow_delete = True
    allow_list = True

    # Properties
    # instanceId
    instance_id = resource.URI('instance_id')
    # database name
    name = resource.Body("name")
    # database character_set
    character_set = resource.Body("character_set")
Beispiel #10
0
class BackupPolicy(_rdsresource.Resource):
    base_path = '/instances/%(instance_id)s/backups/policy'
    resource_key = 'backup_policy'
    service = rds_service.RDSServiceV3()

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

    # Properties
    #: instaceId
    instance_id = resource.URI('instance_id')
    #: Policy keep days
    #: *Type: int*
    keep_days = resource.Body('keep_days', type=int)
    #: Start time
    start_time = resource.Body('start_time')
    period = resource.Body('period')

    def create(self, session, prepend_key=True):
        endpoint_override = self.service.get_endpoint_override()
        request = self._prepare_request(requires_id=False,
                                        prepend_key=prepend_key)
        if endpoint_override is None:
            request.uri = self._get_custom_url(session, request.uri)
        response = session.put(request.uri,
                               endpoint_filter=self.service,
                               endpoint_override=endpoint_override,
                               json=request.body,
                               headers=request.headers,
                               raise_exc=False)

        if response.status_code >= 400:
            return ErrorResponse.make_response(response)
        self._translate_response(response)
        return self
Beispiel #11
0
class Version(_rdsresource.Resource):
    base_path = '/datastores/%(datastore_name)s'
    resources_key = 'dataStores'
    service = rds_service.RDSServiceV3()

    # capabilities
    allow_list = True

    # Properties
    #: Data store name
    datastore_name = resource.URI("datastore_name")
    #: Datastore version id
    id = resource.Body('id')
    #: Datastore name
    name = resource.Body('name')
    #: Datastore id
    dataStores = resource.Body('dataStores')
    #: Datastore image id
    image = resource.Body('image')
    #: Datastore version packages
    packages = resource.Body('packages')
    #: Active status, 1/0
    #: *Type: int*
    active = resource.Body('active', type=int)
Beispiel #12
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._services_module = {}

        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(vpc_service.VpcServiceV1(version='v1'))
        self._add_service(bms_service.BmsService(version='v1'))
        self._add_service(deh_service.DehService(version='v1.0'))
        self._add_service(csbs_service.CsbsService(version='v1'))
        self._add_service(ims_service.ImsService(version='v2'))
        self._add_service(nat_service.NatService(version='v2.0'))
        self._add_service(lb_service.LoadBalancerService(version='v1'))
        self._add_service(bss_service.BssService(version='v1'))
        self._add_service(bss_intl_service.BssIntlService(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(rds_service.RDSServiceV3(version="v3"))
        self._add_service(cdn_service.CDNService(version='v1'))
        self._add_service(iam_service.IamService(version='v3.0'))

        # 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"))
        self._add_service(fgs_service.FGSService(version='v2'))

        if plugins:
            for plugin in plugins:
                self._load_plugin(plugin)
        self.service_keys = sorted(self._services.keys())
class Instance(_rdsresource.Resource):

    base_path = '/instances'
    # resource_key = 'instance'
    resources_key = 'instances'
    service = rds_service.RDSServiceV3()

    _query_mapping = resource.QueryParameters('id', 'name', 'type',
                                              'datastore_type', 'vpc_id',
                                              'subnet_id', 'offset', 'limit')

    # capabilities
    allow_create = True
    allow_delete = True
    allow_get = True
    allow_update = True
    allow_list = True
    prepend_key = False

    # Properties
    #: Instance id
    id = resource.Body('id')
    name = resource.Body('name')
    status = resource.Body('status')
    #req
    region = resource.Body('region')
    availability_zone = resource.Body('availability_zone')
    engine = resource.Body('engine', type=dict)
    ha = resource.Body('ha', type=dict)
    # kmsKeyId = resource.Body('kmsKeyId')
    volume = resource.Body('volume', type=dict)
    flavor_ref = resource.Body('flavor_ref')
    vpc_id = resource.Body('vpc_id')
    subnet_id = resource.Body('subnet_id')
    security_group_id = resource.Body('security_group_id')
    backup_strategy = resource.Body('backup_strategy', type=dict)
    dataStoreInfo = resource.Body('datastore', type=dict)
    password = resource.Body('password')
    replica_of_id = resource.Body('replica_of_id')

    nodes = resource.Body('nodes')
    db_user_name = resource.Body('db_user_name')
    private_ips = resource.Body('private_ips', type=[])
    public_ips = resource.Body('public_ips', type=[])
    type = resource.Body('type')
    switch_strategy = resource.Body('switch_strategy')
    maintenance_window = resource.Body('maintenance_window')
    related_instance = resource.Body('related_instance', type=[])
    disk_encryption_id = resource.Body('disk_encryption_id')
    time_zone = resource.Body('time_zone')
    port = resource.Body('port')
    configuration_id = resource.Body('configuration_id')
    enterprise_project_id = resource.Body('enterprise_project_id')
    charge_info = resource.Body('charge_info')
    version = resource.Body('version')
    replication_mode = resource.Body('replication_mode')
    start_time = resource.Body('start_time')
    keep_days = resource.Body('keep_days')
    resize_flavor = resource.Body('resize_flavor', type=dict)
    backup_used_space = resource.Body('backup_used_space')
    storage_used_space = resource.Body('storage_used_space')

    restore_point = resource.Body('restore_point', type=dict)
    job_id = resource.Body("job_id")
    instance = resource.Body("instance")

    def _action(self, session, body, action="action"):
        """Perform instance action"""
        url = utils.urljoin(self.base_path, self._get_id(self), action)
        endpoint_override = self.service.get_endpoint_override()
        if endpoint_override is None:
            url = self._get_custom_url(session, url)
        else:
            endpoint_override = self._get_custom_override(endpoint_override)
        if action == "action":
            response = session.post(url,
                                    endpoint_filter=self.service,
                                    endpoint_override=endpoint_override,
                                    json=body,
                                    raise_exc=False,
                                    headers={
                                        "Accept": "application/json",
                                        "Content-type": "application/json",
                                        "X-Language": "en-us"
                                    })
        else:
            response = session.get(url,
                                   endpoint_filter=self.service,
                                   endpoint_override=endpoint_override,
                                   json=body,
                                   raise_exc=False,
                                   headers={
                                       "Accept": "application/json",
                                       "Content-type": "application/json",
                                       "X-Language": "en-us"
                                   })
        if response.status_code >= 400:
            return ErrorResponse.make_response(response)

        self._translate_response(response)
        return self

    def resize(self, session, flavor_ref):
        return self._action(session,
                            {"resize_flavor": {
                                "spec_code": flavor_ref
                            }})

    def resize_volume(self, session, size):
        return self._action(session, {"enlarge_volume": {"size": size}})

    def restart(self, session):
        return self._action(session, {"restart": {}})

    def single_to_ha(self, session, **single_to_ha_param):
        new_az_code = single_to_ha_param.get("new_az_code")
        password = single_to_ha_param.get("password")
        if password is not None and password != '':
            single_to_ha_req = {
                "single_to_ha": {
                    "az_code_new_node": new_az_code,
                    "password": password
                }
            }
            return self._action(session, single_to_ha_req)
        else:
            single_to_ha_req = {
                "single_to_ha": {
                    "az_code_new_node": new_az_code
                }
            }
            return self._action(session, single_to_ha_req)

    def recovery_instance(self, session, **params):
        endpoint_override = self.service.get_endpoint_override()
        if endpoint_override is None:
            url = self._get_custom_url(session, self.base_path)
        else:
            endpoint_override = self._get_custom_override(endpoint_override)
        response = session.post(url,
                                endpoint_filter=self.service,
                                endpoint_override=endpoint_override,
                                json=params,
                                raise_exc=False,
                                headers={
                                    "Accept": "application/json",
                                    "Content-type": "application/json",
                                    "X-Language": "en-us"
                                })
        if response.status_code >= 400:
            return ErrorResponse.make_response(response)

        self._translate_response(response)
        return self

    def create(self, session, prepend_key=True):
        endpoint_override = self.service.get_endpoint_override()
        request = self._prepare_request(requires_id=False, prepend_key=False)
        if endpoint_override is None:
            request.uri = self._get_custom_url(session, request.uri)
        response = session.post(request.uri,
                                endpoint_filter=self.service,
                                endpoint_override=endpoint_override,
                                json=request.body,
                                headers=request.headers,
                                raise_exc=False)
        if response.status_code >= 400:
            return ErrorResponse.make_response(response)

        self._translate_response(response)
        return self