def creat_cluster_by_template(self, templateId, adminPassword, logUri=None, steps=None): """ create cluster by template :param templateId: templateid :type templateId: string :param adminPassword: the adminPassword of cluster :type adminPassword: string ,ep: bmrtest@123 :param logUri: start cluster's loguri :type logUri: string :param steps: step of cluster :type steps: list :return: baidubce.bce_response.BceResponse """ params = None body = {'templateId': templateId} if adminPassword is not None: secret_access_key = self.config.credentials.secret_access_key body['adminPassword'] = aes128_encrypt_16char_key( adminPassword, secret_access_key) if logUri is not None: body['logUri'] = logUri if steps is not None: body['steps'] = steps path = '/cluster/create' return self._send_request(http_methods.POST, path, params=params, body=json.dumps(body))
def modify_instance_password(self, instance_id, admin_pass, config=None): """ Modifying the password of the instance. You can change the instance password only when the instance is Running or Stopped , otherwise, it's will get 409 errorCode. This is an asynchronous interface. :param instance_id: The id of instance. :type instance_id: string :param admin_pass: The new password to update. The adminPass will be encrypted in AES-128 algorithm with the substring of the former 16 characters of user SecretKey. :type admin_pass: string :return: :rtype baidubce.bce_response.BceResponse """ secret_access_key = self.config.credentials.secret_access_key cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key) instance_id = compat.convert_to_bytes(instance_id) path = b'/instance/%s' % instance_id body = {'adminPass': cipher_admin_pass} params = {'changePass': None} return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
def create_cluster(self, image_type, image_version, instance_groups, client_token=None, applications=None, auto_terminate=None, log_uri=None, name=None, steps=None, service_ha_enabled=None, safe_mode_enabled=None, admin_pass=None, vpc_id=None, subnet_id=None, security_group=None, availability_zone=None, templateType=None): """ Create cluster :param image_type: the type of virtual machine image :type image_type: string :param image_version: the version of virtual machine image :type image_version: string :param instance_groups: instance groups for cluster :type instance_groups: array :return: :rtype baidubce.bce_response.BceResponse """ path = '/cluster' params = None if client_token is not None: params = {'clientToken': client_token} body = { 'imageType': compat.convert_to_string(image_type), 'imageVersion': compat.convert_to_string(image_version), 'instanceGroups': instance_groups } if applications is not None: body['applications'] = applications if auto_terminate is not None: body['autoTerminate'] = auto_terminate if name is not None: body['name'] = name if log_uri is not None: body['logUri'] = log_uri if steps is not None: body['steps'] = steps if service_ha_enabled is not None: body['serviceHaEnabled'] = service_ha_enabled if safe_mode_enabled is not None: body['safeModeEnabled'] = safe_mode_enabled if admin_pass is not None and self.config is not None: secret_access_key = self.config.credentials.secret_access_key body['adminPassword'] = aes128_encrypt_16char_key( admin_pass, secret_access_key) if vpc_id is not None: body['vpcId'] = vpc_id if subnet_id is not None: body['subnetId'] = subnet_id if security_group is not None: body['securityGroup'] = security_group if availability_zone is not None: body['availabilityZone'] = availability_zone if templateType is not None: body['templateType'] = templateType return self._send_request(http_methods.POST, path, params=params, body=json.dumps(body))
def create_instance(self, flavor_id, image_id, raid_id, root_disk_size_in_gb=20, purchase_count=1, zone_name=None, subnet_id=None, billing=None, name=None, admin_pass=None, auto_renew_time_unit=None, auto_renew_time=0, deploy_set_id=None, security_group_id=None, client_token=None, config=None): """ Create a bbc instance with the specified options. You must fill the field of clientToken, which is especially for keeping idempotent. This is an asynchronous interface. :param flavor_id: The id of flavor, list all available flavors in BbcClient.list_flavors. :type flavor_id: string :param image_id: The id of image, list all available images in BbcClient.list_images. :type image_id: string :param raid_id: The id of raid, list all available raids in BbcClient.get_flavor_raid. :type raid_id: string :param root_disk_size_in_gb: System disk size of the physical machine to be created :type root_disk_size_in_gb: int :param purchase_count: The number of instances to buy, the default value is 1. :type purchase_count: int :param zone_name: The optional parameter to specify the available zone for the instance. See more detail through list_zones method :type zone_name: string :param subnet_id: The optional parameter to specify the id of subnet from vpc, optional param default value is default subnet from default vpc :type subnet_id: string :param billing: Billing information. :type billing: bbc_model.Billing :param name: The optional parameter to desc the instance that will be created. :type name: string :param admin_pass: The optional parameter to specify the password for the instance. If specify the adminPass,the adminPass must be a 8-16 characters String which must contains letters, numbers and symbols. The symbols only contains "!@#$%^*()". The adminPass will be encrypted in AES-128 algorithm with the substring of the former 16 characters of user SecretKey. If not specify the adminPass, it will be specified by an random string. See more detail on https://cloud.baidu.com/doc/BBC/s/3jwvxu9iz#%E5%AF%86%E7%A0%81%E5%8A%A0%E5%AF%86%E4%BC%A0%E8%BE%93%E8%A7%84%E8%8C%83 :type admin_pass: string :param auto_renew_time_unit The parameter to specify the unit of the auto renew time. The auto renew time unit can be "month" or "year". The default value is "month". :type auto_renew_time_unit: string :param auto_renew_time The parameter to specify the auto renew time, the default value is 0. :type auto_renew_time: string :deploy_set_id: The id of the deploy set :type deploy_set_id: string :param security_group_id: The optional parameter to specify the securityGroupId of the instance vpcId of the securityGroupId must be the same as the vpcId of subnetId :type security_group_id: string :param client_token: An ASCII string whose length is less than 64. The request will be idempotent if client token is provided. If the clientToken is not specified by the user, a random String generated by default algorithm will be used. See more detail at https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7 :type client_token: string :return: :rtype baidubce.bce_response.BceResponse """ path = b'/instance' params = {} if client_token is None: params['clientToken'] = generate_client_token() else: params['clientToken'] = client_token if root_disk_size_in_gb == 0: root_disk_size_in_gb = 20 if purchase_count < 1: purchase_count = 1 if billing is None: billing = default_billing_to_purchase_created body = { 'flavorId': flavor_id, 'imageId': image_id, 'raidId': raid_id, 'rootDiskSizeInGb': root_disk_size_in_gb, 'purchaseCount': purchase_count, 'billing': billing.__dict__ } if zone_name is not None: body['zoneName'] = zone_name if subnet_id is not None: body['subnetId'] = subnet_id if security_group_id is not None: body['securityGroupId'] = security_group_id if name is not None: body['name'] = name if deploy_set_id is not None: body['deploySetId'] = deploy_set_id if admin_pass is not None: secret_access_key = self.config.credentials.secret_access_key cipher_admin_pass = aes128_encrypt_16char_key( admin_pass, secret_access_key) body['adminPass'] = cipher_admin_pass if auto_renew_time_unit is None: body['autoRenewTimeUnit'] = "month" else: body['autoRenewTimeUnit'] = auto_renew_time_unit if auto_renew_time != 0: body['autoRenewTime'] = auto_renew_time return self._send_request(http_methods.POST, path, json.dumps(body), params=params, config=config)
def rebuild_instance(self, instance_id, image_id, admin_pass, is_preserve_data=True, raid_id=None, sys_root_size=20, config=None): """ Rebuilding the instance owned by the user. After rebuilding the instance, all of snapshots created from original instance system disk will be deleted, all of customized images will be saved for using in the future. This is an asynchronous interface :param instance_id: The id of instance. :type instance_id: string :param image_id: The id of the image which is used to rebuild the instance. :type image_id: string :param admin_pass: The admin password to login the instance. The admin password will be encrypted in AES-128 algorithm with the substring of the former 16 characters of user SecretKey. See more detail on https://cloud.baidu.com/doc/BBC/s/3jwvxu9iz#%E5%AF%86%E7%A0%81%E5%8A%A0%E5%AF%86%E4%BC%A0%E8%BE%93%E8%A7%84%E8%8C%83 :type admin_pass: string :param is_preserve_data: Whether or not to retain data, the default is true. The raid_id and sys_root_size fields do not take effect when the value is true :type is_preserve_data: bool :param raid_id: The id of raid. See more details on https://cloud.baidu.com/doc/BBC/s/Bjwvxu9ul#%E6%9F%A5%E8%AF%A2raid :type raid_id: string :param sys_root_size: System root partition size, default is 20G, value range is 20-100 :type sys_root_size: int :return: :rtype baidubce.bce_response.BceResponse """ secret_access_key = self.config.credentials.secret_access_key cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key) instance_id = compat.convert_to_bytes(instance_id) path = b'/instance/%s' % instance_id body = { 'imageId': image_id, 'adminPass': cipher_admin_pass, 'isPreserveData': is_preserve_data, 'raidId': raid_id, 'sysRootSize': sys_root_size } params = {'rebuild': None} return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)