Beispiel #1
0
class InstanceSlowLog(_rdsresource.Resource):

    base_path = 'instances/%(instanceId)s/slowlog'
    resources_key = 'slowLogList'
    service = rds_service.RDSService()

    _query_mapping = resource.QueryParameters('sftype', 'top')

    # capabilities
    allow_list = True
    # Properties
    # instanceId
    instanceId = resource.URI('instanceId')
    # 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 #2
0
class BackupPolicy(_rdsresource.Resource):

    base_path = '/instances/%(instanceId)s/backups/policy'
    resource_key = 'policy'
    service = rds_service.RDSService()

    # capabilities
    allow_create = True
    allow_get = True

    # Properties
    #: instaceId
    instanceId = resource.URI('instanceId')
    #: Policy keep days
    #: *Type: int*
    keepday = resource.Body('keepday', type=int)
    #: Start time
    starttime = resource.Body('starttime')

    # use put to create, but we don't require id
    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)

        self._translate_response(response)
        return self
Beispiel #3
0
class Flavor(_rdsresource.Resource):

    base_path = '/flavors'
    resource_key = 'flavor'
    resources_key = 'flavors'
    service = rds_service.RDSService()

    # capabilities
    allow_get = True
    allow_list = True

    # Properties
    #: Flavor id
    id = resource.Body('id')
    #: Flavor name
    name = resource.Body('name')
    #: Ram size in MB.
    #: *Type:int*
    ram = resource.Body('ram', type=int)
    #: Instance created time
    specCode = resource.Body('specCode')
    #: Links
    #: *Type:list*
    links = resource.Body('links', type=list)
    #: String id
    str_id = resource.Body('str_id')
    #: Flavor detail
    #: *Type:list*
    flavor_detail = resource.Body('flavor_detail', type=list)
    #: Flavor
    #: *Type:dict*
    flavor = resource.Body('flavor', type=dict)
    #: Price detail
    #: *Type:list*
    price_detail = resource.Body('price_detail', type=list)
Beispiel #4
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 Parameter(_rdsresource.Resource):

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

    # 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.Body('datastore_version_id')
 def test_service(self):
     sot = rds_service.RDSService()
     self.assertEqual('rds', 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)
     self.assertTrue(sot.requires_project_id)
Beispiel #7
0
class InstanceParameter(_rdsresource.Resource):

    base_path = 'instances/%(instanceId)s/parameters'

    service = rds_service.RDSService()
    # Properties
    #: These Parameters requires restart
    #: *Type: int*
    shouldRestart = resource.Body('shouldRestart', type=int)
    #: Set parameter result, 1, master success; 0; all success
    #: *Type: int*
    setParameteResult = resource.Body('setParameteResult', type=int)

    @classmethod
    def set_params(cls, session, **params):
        uri = cls.base_path % params
        params.pop('instanceId')
        body = {'values': params}
        endpoint_override = cls.service.get_endpoint_override()
        if endpoint_override is None:
            uri = cls._get_custom_url(session, uri)
        else:
            endpoint_override = cls._get_custom_override(endpoint_override)
        resp = session.put(uri,
                           endpoint_filter=cls.service,
                           endpoint_override=endpoint_override,
                           headers={
                               "Accept": "application/json",
                               "Content-type": "application/json",
                               "X-Language": "en-us"
                           },
                           json=body)
        resp = resp.json()
        return cls.existing(**resp)

    @classmethod
    def reset_params(cls, session, **params):
        uri = utils.urljoin(cls.base_path % params, 'default')
        body = {}
        endpoint_override = cls.service.get_endpoint_override()

        if endpoint_override is None:
            uri = cls._get_custom_url(session, uri)
        else:
            endpoint_override = cls._get_custom_override(endpoint_override)
        resp = session.put(uri,
                           endpoint_filter=cls.service,
                           endpoint_override=endpoint_override,
                           headers={"X-Language": "en-us"},
                           json=body)
        resp = resp.json()
        return cls.existing(**resp)
Beispiel #8
0
class Configuration(_rdsresource.Resource):

    base_path = 'instances/%(instanceId)s/configuration'
    resource_key = 'instance'
    service = rds_service.RDSService()

    # capabilities
    allow_get = True

    # Properties
    # Instance of the configuration
    instanceId = resource.URI("instanceId")
    #: Configuration list, key value pairs
    #: *Type:dict*
    configuration = resource.Body('configuration', type=dict)
Beispiel #9
0
class Version(resource.Resource):
    resources_key = 'version'
    resources_key = 'versions'
    base_path = '/'
    service = rds_service.RDSService(
        version=rds_service.RDSService.UNVERSIONED)

    # capabilities
    allow_list = True

    # Properties
    id = resource.Body('id')
    links = resource.Body('links', type=dict)
    status = resource.Body('status')
    updated = resource.Body('updated')
Beispiel #10
0
class InstanceErrorLog(_rdsresource.Resource):

    base_path = 'instances/%(instanceId)s/errorlog'
    resources_key = 'errorLogList'
    service = rds_service.RDSService()

    _query_mapping = resource.QueryParameters('startDate', 'endDate',
                                              'curPage', 'perPage')

    # 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')
Beispiel #11
0
class rdsverion(_rdsresource.Resource):

    resource_key = 'version'
    resources_key = 'versions'
    base_path = '/'
    _version_str = '/rds'
    _need_project_id = False
    service = rds_service.RDSService()

    # capabilities
    allow_get = True
    allow_list = True

    # Properties
    id = resource.Body('id')
    links = resource.Body('links', type=dict)
    status = resource.Body('status')
    updated = resource.Body('updated')

    @classmethod
    def _get_custom_url(cls, session, url):
        key = (cls.service.service_type, cls.service.interface)

        #if key in session.endpoint_cache:
        #    base_url = session.endpoint_cache[key]
        #else:
        base_url = session.get_endpoint(interface=cls.service.interface,
                                        service_type=cls.service.service_type)

        # IAM only returns rds base url, as we need to hack
        # this to support both hw rds and openstack rds
        # provide custom url per resource type
        return base_url.rsplit('/', 2)[0]

    @classmethod
    def _get_custom_override(cls, endpoint_override):
        if cls._need_project_id:
            return endpoint_override
        else:
            return endpoint_override.rsplit('/', 2)[0]
Beispiel #12
0
class Flavor(_rdsresource.Resource):

    base_path = '/flavors'
    resource_key = 'flavor'
    resources_key = 'flavors'
    service = rds_service.RDSService()

    _query_mapping = resource.QueryParameters('dbId', 'region')

    # capabilities
    allow_get = True
    allow_list = True

    # Properties
    #: Flavor id
    id = resource.Body('id')
    #: Flavor name
    name = resource.Body('name')
    #: Ram size in MB.
    #: *Type:int*
    ram = resource.Body('ram', type=int)
    #: Instance created time
    specCode = resource.Body('specCode')
Beispiel #13
0
class Backup(_rdsresource.Resource):

    base_path = '/backups'
    resource_key = 'backup'
    resources_key = 'backups'
    service = rds_service.RDSService()

    # 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')
class Version(_rdsresource.Resource):
    base_path = '/datastores/%(datastore_name)s/versions'
    resources_key = 'dataStores'
    service = rds_service.RDSService()

    # 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
    datastore = resource.Body('datastore')
    #: 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 #15
0
class Instance(_rdsresource.Resource):

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

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

    # Properties
    #: Instance id
    id = resource.Body('id')
    #: Instance status
    status = resource.Body('status')
    #: Instance name
    name = resource.Body('name')
    #: Instance created time
    created = resource.Body('created')
    #: Host name of the instance
    hostname = resource.Body('hostname')
    #: Instance type readreplica/master/slave
    type = resource.Body('type')
    #: Region
    region = resource.Body('region')
    #: Instance updated time
    updated = resource.Body('updated')
    #: Availability Zone
    availability_zone = resource.Body('availability_zone')
    #: Private cloud id
    vpc = resource.Body('vpc')
    #: Nics interface list
    #: *Type:dict*
    nics = resource.Body('nics', type=dict)
    #: Security group
    #: *Type: dict*
    securityGroup = resource.Body('securityGroup', type=dict)
    #: Flavor information
    #: *Type: dict*
    flavor = resource.Body('flavor', type=dict)
    #: Volume information
    #: *Type: dict*
    volume = resource.Body('volume', type=dict)
    #: Data store information
    #: *Type: dict*
    datastore = resource.Body('datastore', type=dict)
    #: Backup Strategy
    #: *Type: dict*
    backupStrategy = resource.Body('backupStrategy', type=dict)
    #: Id of the master
    replica_of = resource.Body('replica_of')
    #: HA information
    #: *Type: dict*
    ha = resource.Body('ha', type=dict)
    #: Restore Point, create new instance from restore
    #: *Type: dict*
    restorePoint = resource.Body("restorePoint", type=dict)
    #: Root password
    dbRtPd = resource.Body("dbRtPd")
    #: Status of configuration
    configurationStatus = resource.Body("configurationStatus")
    #: Id of configuration
    paramsGroupId = resource.Body('paramsGroupId')
    #: Id of subnet
    subnetid = resource.Body('subnetid')
    #: Instance role
    role = resource.Body('role')
    #: Internal subnet id
    internalSubnetId = resource.Body('internalSubnetId')
    #: Group of instance
    group = resource.Body('group')
    #: Secure group id
    securegroup = resource.Body('securegroup')
    #: Az code
    azcode = resource.Body('azcode')
    #: Links
    #: *Type:list*
    links = resource.Body('links', type=list)
    #: Fault, only validate if fault
    #: *Type:dict*
    fault = resource.Body('fault', type=dict)
    #: Configuration
    #: *Type:dict*
    configuration = resource.Body('configuration', type=dict)
    #: Replicas
    #: *Type:dict*
    replicas = resource.Body('replicas', type=dict)
    #: DB user
    dbuser = resource.Body('dbuser')
    #: Storage Engine
    storeEngine = resource.Body('storeEngine')
    #: Pay model
    payModel = resource.Body('payModel')
    #: Cluster ID
    cluster_id = resource.Body('cluster_id')
    #: Slave of instance
    slave_of = resource.Body('slave_of')
    #: Replica of the instance
    replica_count = resource.Body('replica_count')

    def _action(self, session, body):
        """Perform instance action"""
        url = utils.urljoin(self.base_path, self._get_id(self), 'action')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.post(url,
                            endpoint_filter=self.service,
                            endpoint_override=endpoint_override,
                            json=body,
                            headers={
                                "Accept": "application/json",
                                "Content-type": "application/json",
                                "X-Language": "en-us"
                            })

        return resp.json()

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

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

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

    def restore(self, session, backupRef):
        return self._action(session, {"restore": {"backupRef": backupRef}})
Beispiel #16
0
class Instance(_rdsresource.Resource):

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

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

    # Properties
    #: Instance id
    id = resource.Body('id')
    #: Instance status
    status = resource.Body('status')
    #: Instance name
    name = resource.Body('name')
    #: Instance created time
    created = resource.Body('created')
    #: Host name of the instance
    hostname = resource.Body('hostname')
    #: Instance type readreplica/master/slave
    type = resource.Body('type')
    #: Region
    region = resource.Body('region')
    #: Instance updated time
    updated = resource.Body('updated')
    #: Availability Zone
    availabilityZone = resource.Body('availabilityZone')
    #: Private cloud id
    vpc = resource.Body('vpc')
    #: Nics interface list
    #: *Type:dict*
    nics = resource.Body('nics', type=dict)
    #: Security group
    #: *Type: dict*
    securityGroup = resource.Body('securityGroup', type=dict)
    #: Flavor information
    flavor = resource.Body('flavorRef')
    #: Volume information
    #: *Type: dict*
    volume = resource.Body('volume', type=dict)
    #: Data store information
    #: *Type: dict*
    dataStoreInfo = resource.Body('datastore', type=dict)
    #: Backpassword
    dbRtPd = resource.Body("dbRtPd")
    #: DB port
    dbPort = resource.Body("dbPort")

    # rds instance test
    # ip = '139.9.130.103'
    # dbPort = 3316
    # dbUser = '******'
    # dbRtPd = 'mysql@123'

    def _action(self, session, body):
        """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)
        resp = session.post(url,
                            endpoint_filter=self.service,
                            endpoint_override=endpoint_override,
                            json=body,
                            headers={
                                "Accept": "application/json",
                                "Content-type": "application/json",
                                "X-Language": "en-us"
                            })

        return resp.json()

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

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

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

    def restore(self, session, backupRef):
        return self._action(session, {"restore": {"backupRef": backupRef}})
Beispiel #17
0
class Configurations(_rdsresource.Resource):

    base_path = 'configurations'
    resource_key = 'configuration'
    resources_key = 'configurations'
    service = rds_service.RDSService()

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

    # Properties
    #: Id of the configuration group
    id = resource.Body('id')
    #: Name of the configuration group
    name = resource.Body('name')
    #: Description of the configuration group
    description = resource.Body('description')
    #: Id of Datastore version
    datastore_version_id = resource.Body('datastore_version_id')
    #: name of Datastore version
    datastore_version_name = resource.Body('datastore_version_name')
    #: name of Datastore
    datastore_name = resource.Body('datastore_name')
    #: Date of created
    created = resource.Body('created')
    #: Date of updated
    updated = resource.Body('updated')
    #: Allow update or not, 0 for not allowed
    #: *Type:int*
    allowed_updated = resource.Body('allowed_updated', type=int)
    #: Count of associated instance
    #: *Type:int*
    instance_count = resource.Body('instance_count', type=int)
    #: Params values
    #: *Type:dict*
    values = resource.Body('values', type=dict)
    #: Parameter list
    #: *Type:dict*
    parameters = resource.Body('parameters', type=dict)
    #: Datastore dict
    #: *Type:dict*
    datastore = resource.Body('datastore', type=dict)

    def get_associated_instances(self, session):
        """Get associated instancs"""
        url = utils.urljoin(self.base_path, self._get_id(self), 'instances')
        endpoint_override = self.service.get_endpoint_override()
        # construct full http url for rds_os as rds wont' return correct
        # endpoint for now and work around with get_endpoint()
        if endpoint_override is None:
            url = self._get_custom_url(session, url)

        resp = session.get(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override,
                           headers={
                               "Accept": "application/json",
                               "Content-type": "application/json"
                           })
        resp = resp.json()

        if resp:
            return resp['instances']

    def patch(self, session, **kwargs):
        url = utils.urljoin(self.base_path, self._get_id(self))
        endpoint_override = self.service.get_endpoint_override()
        body = {"configuration": {"values": kwargs}}

        if endpoint_override is None:
            url = self._get_custom_url(session, url)

        resp = session.patch(url,
                             endpoint_filter=self.service,
                             endpoint_override=endpoint_override,
                             headers={
                                 "Accept": "application/json",
                                 "Content-type": "application/json"
                             },
                             json=body)
        resp = resp.json
        if 'errCode' in resp:
            if resp['errorCode'] == 'RDS.0041':
                self._body.attributes.update({"values": kwargs})
                self._body.clean()
                return self

        return resp

    def delete(self, session):
        request = self._prepare_request()
        endpoint_override = self.service.get_endpoint_override()
        if endpoint_override is None:
            request.uri = self._get_custom_url(session, request.uri)

        response = session.delete(request.uri,
                                  endpoint_filter=self.service,
                                  endpoint_override=endpoint_override,
                                  headers=request.headers)

        self._translate_response(response, has_body=False)
        return self