Пример #1
0
    def prepare_params(self):
        zone = self.resource_config['available_zone_id']
        password = decrypt_password(
            validate_parameter('password', self.resource_config))

        instance_name = self.resource_config.get('instance_name')
        hostname = None
        if not instance_name:
            instance_name, hostname = self.get_instance_names()
        hostname = self.resource_config.get(
            'hostname') or hostname or instance_name

        image_id = validate_parameter('image_id', self.resource_config)
        params_info = {
            'Region': self.resource_config.get('region'),
            'Zone': zone,
            'ImageId': image_id,
            'SubnetId': self.get_subnet(),
            'Password':
            base64.b64encode(password.encode('utf-8')).decode('utf-8'),
            'Name': instance_name,
            'ChargeType': self.resource_config.get('charge_type') or 'Dynamic',
            'LoginMode': self.resource_config.get('login_mode') or 'Password',
            'Disks.0.IsBoot': 'True',
            'Disks.0.Type': constants.UC_VOLUME_TYPE,
            'Disks.0.Size': self.get_size(image_id),
            'MachineType': constants.MachineType,
            'CPU': self.resource_config['cpus'],
            'Memory': self.resource_config['memory']
        }

        return params_info
Пример #2
0
 def __init__(self, **kwargs):
     super(Client, self).__init__()
     self.username = self.connection_config.get('username')
     self.password = decrypt_password(
         self.connection_config.get('password'))
     self.host = self.connection_config.get('host')
     self.port = self.connection_config.get('port')
     self._protocol = self.connection_config.get('protocol')
Пример #3
0
 def __init__(self):
     self.connection_config = get_connection_config()
     self.resource_config = ctx.node.properties['resource_config']
     self.region = validate_parameter('region', self.resource_config)
     self.ks_access_key_id = validate_parameter('access_key_id',
                                                self.connection_config)
     self.ks_secret_access_key = decrypt_password(
         validate_parameter('access_key_secret', self.connection_config))
     self.domain = self.connection_config.get('domain')
Пример #4
0
 def __init__(self, params):
     self.region = validate_parameter('region', params)
     self.g_params = {
         'PublicKey': validate_parameter('access_key_id', params)
     }
     self.private_key = decrypt_password(
         validate_parameter('access_key_secret', params))
     base_url = params.get('base_url', 'https://api.ucloud.cn')
     self.conn = UConnection(base_url)
Пример #5
0
 def __init__(self, **kwargs):
     super(FusionAccessConnect, self).__init__()
     self.host = self.connection_config.get("host")
     self.port = self.connection_config.get("port")
     self.protocol = self.connection_config.get("protocol")
     self.username = self.connection_config.get("username")
     self.password = decrypt_password(
         self.connection_config.get("password"))
     self.basic_uri = "/services/ita"
Пример #6
0
 def __init__(self, params, api_name, api_version):
     self.api_name = api_name
     self.api_version = api_version
     self.key_id = validate_parameter('private_key_id', params)
     self.private_key = decrypt_password(
         validate_parameter('private_key', params)).replace('\\n', '\n')
     self.project = validate_parameter('project_id', params)
     self.client_email = validate_parameter('client_email', params)
     self.client_id = validate_parameter('client_id', params)
     self.key_json = self.generate_key_json()
     self.scope = ['https://www.googleapis.com/auth/' + api_name]
Пример #7
0
    def _get_instances_params(self):

        vm_name = self.resource_config.get('instance_name')
        hostname = None
        if not vm_name:
            vm_name, hostname = self.get_instance_names()
        hostname = self.resource_config.get('hostname') or hostname or vm_name
        password = decrypt_password(self.resource_config.get('password'))
        description = self.resource_config.get('description', '')
        ha = self.resource_config.get('ha', False)
        vcpu = validate_parameter('CPU', self.resource_config, not_empty=True)
        memory = int(
            validate_parameter('Memory', self.resource_config,
                               not_empty=True)) << 20
        image_id = validate_parameter('image_id',
                                      self.resource_config,
                                      not_empty=True)
        nested_virtualization = self.resource_config.get(
            'nested_virtualization', False)
        # nics
        nics, cloud_init_nics, gateway, nameservers = self._get_nics_params()
        cloud_init_data = self._get_cloud_init_data(hostname, password,
                                                    cloud_init_nics,
                                                    nameservers, gateway)

        data = {
            "vm_name": vm_name,
            "status": "stopped",
            "description": description,
            'image_id': image_id,
            'is_full_copy': False,
            "ha": ha,
            "vcpu": vcpu,
            "cpu": {
                "topology": {
                    "cores": vcpu,
                    "sockets": 1
                }
            },
            "memory": memory,
            "nested_virtualization": nested_virtualization,
            "nics": nics,
            "cloud_init": cloud_init_data
        }
        self.set_optional_values(self.resource_config, data, optional_keys)

        return data
Пример #8
0
    def prepare_params(self):
        instance_name = self.resource_config.get('instance_name')
        hostname = None
        if not instance_name:
            instance_name, hostname = self.get_instance_names()
        hostname = self.resource_config.get('hostname') or hostname or instance_name

        system_tags = ["consolePassword::{0}".format(
            decrypt_password(validate_parameter('password', self.resource_config)))]
        if self.get_ip():
            system_tags.append("staticIp::{0}::{1}".format(self.get_subnet(), self.get_ip()))

        params_info = {
            "name": instance_name,
            "instanceOfferingUuid": validate_parameter('flavor', self.resource_config),
            "imageUuid": validate_parameter('image_id', self.resource_config),
            "l3NetworkUuids": self.get_subnets(),
            "strategy": "InstantStart",
            "systemTags": system_tags
        }
        return params_info
Пример #9
0
 def prepare_connection(self):
     return {
         'url': self.connection['url'],
         'username': self.connection['username'],
         'password': decrypt_password(self.connection['password']),
     }
Пример #10
0
 def _prepare_login_settings(self):
     login_settings = LoginSettings()
     login_settings.Password = decrypt_password(
         self.resource_config.get('password'))
     return login_settings
Пример #11
0
    def prepare_params(self):
        nsg_id = self.get_nsg_id()

        if not nsg_id:
            raise NonRecoverableError(
                "Can not get security group id, please set in environment variable, "
                "the environment variable key is 'KSYUN_NSG'.")

        instance_name = self.resource_config.get('instance_name')
        hostname = None
        if not instance_name:
            instance_name, hostname = self.get_instance_names()
        hostname = self.resource_config.get(
            'hostname') or hostname or instance_name

        if self.resource_config.get('instance_name'):
            instance_name = self.resource_config.get('instance_name')
        else:
            instance_name, hostname = self.get_instance_names()

        params_info = {
            'ImageId':
            validate_parameter('image_id', self.resource_config),
            'InstanceType':
            validate_parameter('flavor', self.resource_config),
            'SubnetId':
            self.get_subnet(),
            'MaxCount':
            1,
            'MinCount':
            1,
            'SecurityGroupId':
            nsg_id,
            'InstancePassword':
            decrypt_password(
                validate_parameter('password', self.resource_config)),
            'InstanceName':
            instance_name,
            'ChargeType':
            self.resource_config.get('charge_type')
            or 'HourlyInstantSettlement',
            'PurchaseTime':
            self.resource_config.get('purchase_time') or 0,
            'SystemDisk.DiskType':
            self.resource_config.get('system_disk_config').get('volume_type'),
            'SystemDisk.DiskSize':
            self.resource_config.get('system_disk_config').get('size')
        }
        if hostname:
            params_info['HostName'] = hostname
        if os.environ.get('KSYUN_SYSTEM_DISK_TYPE'):
            params_info.update({
                'SystemDisk.DiskType':
                os.environ.get('KSYUN_SYSTEM_DISK_TYPE'),
                'SystemDisk.DiskSize':
                int(os.environ.get('KSYUN_SYSTEM_DISK_SIZE'))
            })

        ip_address = self.get_ip()
        if ip_address:
            ip_address_info = {'PrivateIpAddress': ip_address}
            params_info.update(ip_address_info)

        return params_info
Пример #12
0
 def __init__(self, params):
     self.auth_url = validate_parameter('base_url', params)
     self.username = validate_parameter('username', params)
     self.password = decrypt_password(validate_parameter('password', params))
Пример #13
0
    def _prepare_request_params(self):
        default_vm_name, default_hostname = self.get_instance_names()
        vm_name = self.resource_config.get('instance_name', default_vm_name)
        if not vm_name:
            vm_name = ctx.instance.id
        image_id = validate_parameter('image_id',
                                      self.resource_config,
                                      not_empty=True)
        os_type = self.get_os_type(image_id)
        hostname = self.resource_config.get(
            'hostname') or default_hostname or vm_name.replace('_', '-')
        if len(hostname) > 15:
            hostname = vm_name.replace('Compute_', '-')
        password = decrypt_password(self.resource_config.get('password'))
        disk_name = vm_name + '-OS-Disk'
        description = self.resource_config.get('description', '')
        location = self.zone
        is_binding_host = convert2bool(
            self.resource_config.get('is_binding_host', False))
        vm_config = self._prepare_vm_config(image_id, disk_name)

        data = {
            "name": vm_name,
            "description": description,
            "location": location,
            "isBindingHost": is_binding_host,
            "vmConfig": vm_config,
            "autoBoot": False,
            "isTemplate": False,
            "vmCustomization": {
                "osType": os_type,
                "hostname": hostname,
                "password": password,
                "workgroup": "workgroup",
            },
        }
        network_info = self.get_network_info()
        if network_info:
            ctx.logger.info("Using network_info {0}.".format(network_info))
            data['vmCustomization']['nicSpecification'] = [{
                "sequenceNum":
                1,
                "ip":
                network_info['ip'],
                "cidr":
                network_info['cidr'],
                "gateway":
                network_info['gateway'],
                "netmask":
                network_info['netmask']
            }]
            dns_server = network_info.get('dns_servers', [])
            if dns_server:
                back_dns = dns_server[1] if len(
                    dns_server) > 1 else dns_server[0]
                data['vmCustomization']['nicSpecification'][0].update({
                    'setdns':
                    dns_server[0],
                    'adddns':
                    back_dns
                })

        return data
Пример #14
0
 def __init__(self):
     super(Helper, self).__init__()
     self.cred = credential.Credential(
         self.connection_config.get('access_key_id'),
         decrypt_password(self.connection_config.get('access_key_secret')))
     self.region = self.resource_config.get("region")