def reboot_instance(self): """ 重启cvm :return: """ # 设置参数 request = models.RebootInstancesRequest() request.InstanceIds=self.instance_list # 发起请求 response = self.clentoper.RebootInstances(request) self.logger.info("public ecs vpn reboot successful!") self.logger.info(response.to_json_string()) print(response.to_json_string())
def reboot(name, call=None): """ Reboot a Tencent Cloud instance CLI Examples: .. code-block:: bash salt-cloud -a reboot myinstance """ if call != "action": raise SaltCloudSystemExit("The stop action must be called with -a or --action.") node = _get_node(name) client = get_provider_client("cvm_client") req = cvm_models.RebootInstancesRequest() req.InstanceIds = [node.InstanceId] resp = client.RebootInstances(req) return resp
def reboot_server(self, server_id, *args, **kwargs) -> bool: regions_list = self.get_available_regions_list() for region in regions_list: region_code = region["region_code"] client = cvm_client.CvmClient(self.isp, region_code) req = tc_models.RebootInstancesRequest() req_config = json.dumps( dict( InstanceIds=[server_id], ForceReboot=True, )) req.from_json_string(req_config) try: client.RebootInstances(req) except Exception as e: logging.warning(e) rebooted = False else: rebooted = True break return rebooted
def rebootInstance(InstanceId): req = models.RebootInstancesRequest() req.InstanceIds = [InstanceId] resp = client.RebootInstances(req) return resp
ssl._create_default_https_context = ssl._create_unverified_context try: # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey cred = credential.Credential("AKIDylMjqkOq7Azay9Nq8D5kCSVM1Sfft4Sd", "K8lBONAk7IEzXt30kGXcS5UfbJm0zkG4") httpProfile = HttpProfile() httpProfile.endpoint = "cvm.api3.test.403a.tcecqpoc.fsphere.cn" clientProfile = ClientProfile() clientProfile.httpProfile = httpProfile # 实例化要请求产品(以cvm为例)的client对象,clientProfile是可选的。 client = cvm_client.CvmClient(cred, "shanghai", clientProfile) # 实例化一个cvm实例信息查询请求对象,每个接口都会对应一个request对象。 req = models.RebootInstancesRequest() # 这里还支持以标准json格式的string来赋值请求参数的方式。下面的代码跟上面的参数赋值是等效的。 params = '{"InstanceIds":["ins-i4ekkudx","ins-gwggvy39"]}' req.from_json_string(params) # 通过client对象调用DescribeInstances方法发起请求。注意请求方法名与请求对象是对应的。 # 返回的resp是一个DescribeInstancesResponse类的实例,与请求对象对应。 resp = client.RebootInstances(req) # 输出json格式的字符串回包 print(resp.to_json_string()) # 也可以取出单个值。 # 你可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义。