Esempio n. 1
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 ServerAction(resource2.Resource):
    base_path = "/cloudservers/action"

    service = ecs_service.EcsService()

    allow_create = True
    # action name
    os_start = resource2.Body('os-start', type=dict)
    # action name
    reboot = resource2.Body('reboot', type=dict)
    # action name
    os_stop = resource2.Body('os-stop', type=dict)
    # server reboot type like soft hard
    type = resource2.Body('type')
    # ecs server id list
    servers = resource2.Body('servers')
    # ecs server id
    id = resource2.Body('id')

    # task id
    job_id = resource2.Body('job_id')
    order_id = resource2.Body('order_id')
    error = resource2.Body('error')
    message = resource2.Body('message')
    code = resource2.Body('code')
Esempio n. 3
0
class ChangeOs(resource2.Resource):
    base_path = "/cloudservers/batch-changeos"
    resource_key = "os-change"

    service = ecs_service.EcsService()

    allow_create = True
    # key name
    keyname = resource2.Body('keyname')
    # image id
    imageid = resource2.Body('imageid')
    # user id
    userid = resource2.Body('userid')
    # adminpass
    adminpass = resource2.Body('adminpass')
    # metadata for ces server
    metadata = resource2.Body('metadata', type=dict)
    # ecs server id list
    servers = resource2.Body('servers', type=list)
    # mode
    mode = resource2.Body('mode')

    # task id
    job_id = resource2.Body('job_id')
    # order id
    order_id = resource2.Body('order_id')
    error = resource2.Body('error')
    message = resource2.Body('message')
    code = resource2.Body('code')
Esempio n. 4
0
class Job(resource2.Resource):
    base_path = '/jobs'
    service = ecs_service.EcsService()
    allow_get = True

    # job's status
    status = resource2.Body('status')
    # job's operation object
    entities = resource2.Body('entities', type=dict)
    # job's id
    job_id = resource2.Body('job_id')
    # job's type
    job_type = resource2.Body('job_type')
    # begin time
    begin_time = resource2.Body('begin_time')
    # end time
    end_time = resource2.Body('end_time')
    # the error code when the job execution failed
    error_code = resource2.Body('error_code')
    # the fail reason when the job execution failed
    fail_reason = resource2.Body('fail_reason')
    # the error message returned when an error occurs
    message = resource2.Body('message')
    # the error code returned when an error occurs
    code = resource2.Body('code')
    # number of subtasks
    sub_jobs_total = resource2.Body('sub_jobs_total', type=int)
    # execution information for each subtask
    sub_jobs = resource2.Body('sub_jobs', type=list)
 def test_service(self):
     sot = ecs_service.EcsService()
     self.assertEqual('ecs', 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)
Esempio n. 6
0
class Servers(resource2.Resource):
    base_path = "/cloudservers"
    resource_key = "server"
    resources_key = 'servers'
    service = ecs_service.EcsService()
    allow_create = True

    # string type ECS server name
    name = resource2.Body('name')
    # availability zone name
    availability_zone = resource2.Body('availability_zone')
    # server size
    flavorRef = resource2.Body('flavorRef')
    # image id for create ecs server
    imageRef = resource2.Body('imageRef')
    # system volume
    root_volume = resource2.Body('root_volume', type=dict)
    # data volume
    data_volumes = resource2.Body('data_volumes', type=list)
    # file inspect for personal
    personality = resource2.Body('personality', type=list)
    # vpc id used for ecs server
    vpcid = resource2.Body('vpcid')
    # user data inspect to create ecs server
    user_data = resource2.Body('user_data')
    # project id
    project_id = resource2.Body('tenant_id')
    # subnet id used for ecs server
    nics = resource2.Body('nics')
    # eip configed for ecs server
    publicip = resource2.Body('publicip')
    # use Cloud-init or Cloudbase-init to set user password
    admin_password = resource2.Body('adminPass')
    # whether server name will be renamed
    isAutoRename = resource2.Body('isAutoRename')
    # ssh key name to login ecs server
    key_name = resource2.Body('key_name')
    # created server number
    count = resource2.Body('count', type=int)
    # metadata for ces server
    metadata = resource2.Body('metadata', type=dict)
    # extend server info
    extendparam = resource2.Body('extendparam', type=dict)
    # security groups id
    security_groups = resource2.Body('security_groups', type=list)
    # info for schedule server based host
    scheduler_hints = resource2.Body('os:scheduler_hints', type=dict)
    # tags for identify ecs servers
    tags = resource2.Body('tags')
    # task id
    job_id = resource2.Body('job_id')
    # order id
    order_id = resource2.Body('order_id')
    error = resource2.Body('error')
    message = resource2.Body('message')
    code = resource2.Body('code')
Esempio n. 7
0
class ProjectTag(resource2.Resource):
    resources_key = "tags"
    base_path = "/cloudservers/tags"

    service = ecs_service.EcsService()

    allow_list = True

    key = resource2.Body("key")
    values = resource2.Body("values", type=list)
Esempio n. 8
0
class ServerTag(resource2.Resource):
    resources_key = "tags"
    base_path = "/cloudservers/%(server_id)s/tags"

    service = ecs_service.EcsService()

    allow_list = True

    server_id = resource2.URI("server_id")
    key = resource2.Body("key")
    value = resource2.Body("value")
Esempio n. 9
0
class Quota(resource2.Resource):
    resource_key = "absolute"
    base_path = "/cloudservers/limits"
    service = ecs_service.EcsService()

    allow_get = True

    # Maximum number of cloud server applications
    maxtotalinstances = resource2.Body("maxTotalInstances", type=int)
    # CPU core maximum number of applications
    maxtotalcores = resource2.Body("maxTotalCores", type=int)
    # Maximum memory application capacity Unit: MB
    maxtotalramsize = resource2.Body("maxTotalRAMSize", type=int)
    # The maximum number of SSH key pairs that can be applied
    maxtotalkeypairs = resource2.Body("maxTotalKeypairs", type=int)
    # The maximum length of metadata that can be entered
    maxservermeta = resource2.Body("maxServerMeta", type=int)
    # The maximum number of files that can be injected
    maxpersonality = resource2.Body("maxPersonality", type=int)
    # Maximum length of injected file content Unit: Byte
    maxpersonalitysize = resource2.Body("maxPersonalitySize", type=int)
    # The maximum number of server groups
    maxservergroups = resource2.Body("maxServerGroups", type=int)
    # Maximum number of elastic cloud servers in the server group
    maxservergroupmembers = resource2.Body("maxServerGroupMembers", type=int)
    # Number of server groups used
    totalservergroupsused = resource2.Body("totalServerGroupsUsed", type=int)
    # The maximum number of security groups used.
    # Description:
    # The specific quota limit is subject to the VPC quota limit.
    maxsecuritygroups = resource2.Body("maxSecurityGroups", type=int)
    # The maximum number of configurations of security group rules in a security group.
    # Description:
    # The specific quota limit is subject to the VPC quota limit.
    maxsecuritygrouprules = resource2.Body("maxSecurityGroupRules", type=int)
    # The maximum number of floating IPs used
    maxtotalfloatingips = resource2.Body("maxTotalFloatingIps", type=int)
    # Maximum length of mirrored metadata
    maximagemeta = resource2.Body("maxImageMeta", type=int)
    # Current cloud server usage
    totalinstancesused = resource2.Body("totalInstancesUsed", type=int)
    # The number of CPU cores currently used
    totalcoresused = resource2.Body("totalCoresUsed", type=int)
    # Current memory usage unit: MB
    totalramused = resource2.Body("totalRAMUsed", type=int)
    # Current security group usage
    totalsecuritygroupsused = resource2.Body("totalSecurityGroupsUsed",
                                             type=int)
    # Current floating IP usage
    totalfloatingipsused = resource2.Body("totalFloatingIpsUsed", type=int)
Esempio n. 10
0
class VncAddress(resource2.Resource):
    base_path = '/cloudservers/%(server_id)s/remote_console'

    service = ecs_service.EcsService()

    allow_create = True

    server_id = resource2.URI('server_id')

    # The total number of lists of elastic cloud servers.
    remote_console = resource2.Body('remote_console')
    # Elastic cloud server details list.
    type = resource2.Body('type')
    protocol = resource2.Body('protocol')
    url = resource2.Body('url')
Esempio n. 11
0
class Flavor(resource2.Resource):
    base_path = "/cloudservers/flavors"
    resource_key = "flavors"
    resources_key = "flavors"
    service = ecs_service.EcsService()

    _query_mapping = resource2.QueryParameters("availability_zone")

    allow_list = True
    # Cloud server specification name
    name = resource2.Body("name")
    # The number of CPU cores corresponding to the cloud server specification
    vcpus = resource2.Body("vcpus")
    # The size of the memory corresponding to the cloud server specification,
    # in MBThe size of the memory corresponding to the cloud server specification, in MB
    ram = resource2.Body("ram", type=int)
    # The cloud server specification corresponds to the required system disk size, and 0 is not limited.
    # This field is invalid in this system
    disk = resource2.Body("disk")
    # Unused
    swap = resource2.Body("swap")
    # Unused
    ephemeral = resource2.Body("OS-FLV-EXT-DATA:ephemeral", type=int)
    # Unused
    disabled = resource2.Body("OS-FLV-DISABLED:disabled", type=bool)
    # Unused
    factor = resource2.Body("rxtx_factor", type=int)
    # Unused
    rxtx_quota = resource2.Body("rxtx_quota")
    # Unused
    rxtx_cap = resource2.Body("rxtx_cap")
    # Unused
    is_public = resource2.Body("os-flavor-access:is_public", type=bool)
    # Specification related quick link address
    # rel: Quick link tag name
    # href: Corresponding quick link
    # type: Shortcut type
    links = resource2.Body("links", type=list)
    # Extension field for cloud server specifications
    # For details:https://support.huaweicloud.com/api-ecs/zh-cn_topic_0020212656.html
    specs = resource2.Body("os_extra_specs", type=dict)
class ResizeServer(resource2.Resource):
    base_path = "/cloudservers/%(server_id)s/resize"
    resource_key = "resize"
    service = ecs_service.EcsService()

    allow_create = True

    server_id = resource2.URI('server_id')
    # # extend server info
    # extendparam = resource2.Body('extendparam', type=dict)
    # optional only support dedicated type host
    dedicated_host_id = resource2.Body('dedicated_host_id')
    # server size
    flavorRef = resource2.Body('flavorRef')
    # task id
    job_id = resource2.Body('job_id')
    # order id
    order_id = resource2.Body('order_id')
    error = resource2.Body('error')
    message = resource2.Body('message')
    code = resource2.Body('code')
class DeleteServer(resource2.Resource):
    base_path = "/cloudservers/delete"

    service = ecs_service.EcsService()

    allow_create = True
    # whether delete server eip
    delete_publicip = resource2.Body('delete_publicip')
    # whether delete server volume disk
    delete_volume = resource2.Body('delete_volume')
    # ecs server id list
    servers = resource2.Body('servers', type=list)
    # ecs server id
    id = resource2.Body('id')

    # task id
    job_id = resource2.Body('job_id')
    # order id
    order_id = resource2.Body('order_id')
    error = resource2.Body('error')
    message = resource2.Body('message')
    code = resource2.Body('code')
Esempio n. 14
0
class ServerTagAction(resource2.Resource):
    base_path = "/cloudservers/%(server_id)s/tags/action"

    service = ecs_service.EcsService()

    allow_create = True

    server_id = resource2.URI("server_id")
    action = resource2.Body('action')
    tags = resource2.Body('tags', type=list)

    def create(self, session, prepend_key=True):
        """Create a remote resource based on this Server Tag Action.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param prepend_key: A boolean indicating whether the resource_key
                            should be prepended in a resource creation
                            request. Default to True.

        :return: This :class:`Resource` instance.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_create` is not set to ``True``.
        """

        endpoint_override = self.service.get_endpoint_override()
        request = self._prepare_request(requires_id=False,
                                        prepend_key=prepend_key)
        response = session.post(request.uri,
                                endpoint_filter=self.service,
                                endpoint_override=endpoint_override,
                                json=request.body,
                                headers=request.headers)

        self._translate_response(response, has_body=False)
        return self
Esempio n. 15
0
class ResetPassword(resource2.Resource):
    base_path = '/cloudservers/%(server_id)s/os-reset-password'
    service = ecs_service.EcsService()

    server_id = resource2.URI('server_id')
    reset_password = resource2.Body('reset-password', type=dict)
    error = resource2.Body('error')
    message = resource2.Body('message')
    code = resource2.Body('code')
    is_check_password = resource2.Body('is_check_password')
    new_password = resource2.Body('new_password')

    def update(self, session, prepend_key=True, has_body=True):
        request = self._prepare_request(prepend_key=prepend_key, requires_id=False)
        service = self.get_service_filter(self, session)
        endpoint_override = self.service.get_endpoint_override()
        try:
            session.put(request.uri, endpoint_filter=self.service,
                                   microversion=service.microversion,
                                   endpoint_override=endpoint_override,
                                   json=request.body, headers=request.headers)
            return "reset password finish"
        except Exception as e:
            return e
class Servers(resource2.Resource):
    base_path = "/cloudservers"
    resource_key = "server"
    resources_key = 'servers'
    service = ecs_service.EcsService()
    allow_create = True
    allow_get = True

    # string type ECS server name
    name = resource2.Body('name')
    # availability zone name
    availability_zone = resource2.Body('availability_zone')
    # server size
    flavorRef = resource2.Body('flavorRef')
    # image id for create ecs server
    imageRef = resource2.Body('imageRef')
    # system volume
    root_volume = resource2.Body('root_volume', type=dict)
    # data volume
    data_volumes = resource2.Body('data_volumes', type=list)
    # file inspect for personal
    personality = resource2.Body('personality', type=list)
    # vpc id used for ecs server
    vpcid = resource2.Body('vpcid')
    # user data inspect to create ecs server
    user_data = resource2.Body('user_data')
    # project id
    project_id = resource2.Body('tenant_id')
    # subnet id used for ecs server
    nics = resource2.Body('nics')
    # eip configed for ecs server
    publicip = resource2.Body('publicip')
    # use Cloud-init or Cloudbase-init to set user password
    admin_password = resource2.Body('adminPass')
    # whether server name will be renamed
    isAutoRename = resource2.Body('isAutoRename')
    # ssh key name to login ecs server
    key_name = resource2.Body('key_name')
    # created server number
    count = resource2.Body('count', type=int)
    # metadata for ces server
    metadata = resource2.Body('metadata', type=dict)
    # extend server info
    extendparam = resource2.Body('extendparam', type=dict)
    # security groups id
    security_groups = resource2.Body('security_groups', type=list)
    # info for schedule server based host
    scheduler_hints = resource2.Body('os:scheduler_hints', type=dict)
    # tags for identify ecs servers
    tags = resource2.Body('tags', type=list)
    # task id
    job_id = resource2.Body('job_id')
    # order id
    order_id = resource2.Body('order_id')
    error = resource2.Body('error')
    message = resource2.Body('message')
    code = resource2.Body('code')

    # Add fields for get/list server(s).
    # Status of ecs server.
    status = resource2.Body('status')
    # Update time.
    updated = resource2.Body('updated')
    # Host ID of the host where the ECS is located.
    hostId = resource2.Body('hostId')
    # Host name of the host where the ECS is located.
    OS_EXT_SRV_ATTR_host = resource2.Body('OS-EXT-SRV-ATTR:host')
    # Network infomation of ecs server.
    addresses = resource2.Body('addresses', type=dict)
    # The state of the current task of the Elastic Cloud Server.
    OS_EXT_STS_task_state = resource2.Body('OS-EXT-STS:task_state')
    # The current state of the ECS.
    OS_EXT_STS_vm_state = resource2.Body('OS-EXT-STS:vm_state')
    # Elastic cloud server alias.
    OS_EXT_SRV_ATTR_instance_name = resource2.Body('OS-EXT-SRV-ATTR:instance_name')
    # The virtualized host name where the ECS is located.
    OS_EXT_SRV_ATTR_hypervisor_hostname = resource2.Body('OS-EXT-SRV-ATTR:hypervisor_hostname')
    # Elastic cloud server specification information.
    flavor = resource2.Body('flavor', type=dict)
    # Id of ecs server.
    id = resource2.Body('id')
    # The name of the available partition where the ECS is located.
    OS_EXT_AZ_availability_zone = resource2.Body('OS-EXT-AZ:availability_zone')
    # Create a user ID for the ECS.
    user_id = resource2.Body('user_id')
    # Create time.
    created = resource2.Body('created')
    # Type of disk config.
    OS_DCF_diskConfig = resource2.Body('OS-DCF:diskConfig')
    # Reserve attributes.
    accessIPv4 = resource2.Body('accessIPv4')
    # Reserve attributes.
    accessIPv6 = resource2.Body('accessIPv6')
    # Elastic cloud server progress.
    progress = resource2.Body('progress', type=int)
    # Elastic cloud server power status.
    OS_EXT_STS_power_state = resource2.Body('OS-EXT-STS:power_state', type=int)
    # Config drive information.
    config_drive = resource2.Body('config_drive')
    # Elastic cloud server startup time.
    OS_SRV_USG_launched_at = resource2.Body('OS-SRV-USG:launched_at')
    # Elastic cloud server delete time.
    OS_SRV_USG_terminated_at = resource2.Body('OS-SRV-USG:terminated_at')
    # Mount the disk to the Elastic Cloud Server.
    os_extended_volumes_volumes_attached = resource2.Body('os-extended-volumes:volumes_attached', type=list)
    # Description of ecs server.
    description = resource2.Body('description')
    # Nova compute status.
    host_status = resource2.Body('host_status')
    # The host name of the ECS.
    OS_EXT_SRV_ATTR_hostname = resource2.Body('OS-EXT-SRV-ATTR:hostname')
    # The reserved ID of the ECS.
    OS_EXT_SRV_ATTR_reservation_id = resource2.Body('OS-EXT-SRV-ATTR:reservation_id')
    # The startup sequence of the elastic cloud server.
    OS_EXT_SRV_ATTR_launch_index = resource2.Body('OS-EXT-SRV-ATTR:launch_index', type=int)
    # If the image in AMI format is used, it indicates the UUID of the kernel image.
    OS_EXT_SRV_ATTR_kernel_id = resource2.Body('OS-EXT-SRV-ATTR:kernel_id')
    # If the AMI format image is used, it indicates the UUID of the ramdisk image.
    OS_EXT_SRV_ATTR_ramdisk_id = resource2.Body('OS-EXT-SRV-ATTR:ramdisk_id')
    # Device name of the ECS system disk.
    OS_EXT_SRV_ATTR_root_device_name = resource2.Body('OS-EXT-SRV-ATTR:root_device_name')
    # User_data specified when creating an ECS.
    OS_EXT_SRV_ATTR_user_data = resource2.Body('OS-EXT-SRV-ATTR:user_data')
    # Whether the ECS is locked.
    locked = resource2.Body('locked', type=bool)
    # Enterprise project ID to which the ECS belongs.
    enterprise_project_id = resource2.Body('enterprise_project_id')
    # Elastic cloud server system label.
    sys_tags = resource2.Body('sys_tags', type=list)
    # server_tags
    server_tags = resource2.Body("server_tags", type=list)
    # If you need to use a password to log in to the cloud server, you can use the adminPass field to specify the
    # initial login password for the cloud server administrator account. The Linux administrator account is root
    # and the Windows administrator account is Administrator.
    # Password complexity requirements:
    # The length is 8-26 digits.
    # The password must contain at least three of uppercase letters, lowercase letters, numbers,
    # and special characters (!@$%^-_=+[{}]:, ./?).
    # The password cannot contain the reverse of the username or username.
    # The Windows system password cannot contain the reverse order of the username or username, and cannot contain
    # more than two consecutive characters in the username.
    adminPass = resource2.Body("adminPass")

    @classmethod
    def autorecovery(cls, session, server_id, autorecovery):
        url = utils.urljoin(cls.base_path, server_id, 'autorecovery')
        headers = {'Accept': ''}
        endpoint_override = cls.service.get_endpoint_override()
        service = cls.get_service_filter(cls, session)
        session.put(
            url, endpoint_filter=cls.service,
            microversion=service.microversion,
            headers=headers,
            json = {"support_auto_recovery": autorecovery},
            endpoint_override=endpoint_override)

    @classmethod
    def register_server_to_ces(cls, session , server_id):
        url = utils.urljoin("servers", server_id, 'action')
        headers = {'Accept': ''}
        endpoint_override = cls.service.get_endpoint_override()
        service = cls.get_service_filter(cls, session)
        session.post(
            url, endpoint_filter=cls.service,
            microversion=service.microversion,
            headers=headers,
            json={"monitorMetrics": None},
            endpoint_override=endpoint_override)