Esempio n. 1
0
def _destroy_cvm():
    _describe_instances()

    client = _get_cvm_client()
    instance_ids = list(TOTAL_CVM_INSTANCES.keys())
    if len(instance_ids) == 0:
        return

    iter = len(instance_ids) / ITEM_UNIT
    left = len(instance_ids) % ITEM_UNIT

    count = 0
    while (count <= iter):
        req = models.TerminateInstancesRequest()
        if count < iter:
            req.InstanceIds = instance_ids[count * ITEM_UNIT:(count + 1) *
                                           ITEM_UNIT]
        elif left:
            req.InstanceIds = instance_ids[-left:]
        else:
            break

        resp = client.TerminateInstances(req)
        if not _succeed(resp):
            logging.warning("Fail to TerminateInstances, need retry manually")
        count = count + 1
        time.sleep(0.1)
Esempio n. 2
0
def del_cvm(cvm_id):
    try:
        del_params = {"InstanceIds": [cvm_id]}
        req = cvm_models.TerminateInstancesRequest()
        req.from_json_string(json.dumps(del_params))

        resp = cvm_client.TerminateInstances(req)
        return json.loads(resp.to_json_string())
    except TencentCloudSDKException as err:
        print(err)
Esempio n. 3
0
    def del_cvm(self, InstanceId):
        """
        通过instanceid查询实例信息
        :return:
        """

        del_req = cvm_models.TerminateInstancesRequest()
        del_req.InstanceIds = [InstanceId]
        try:
            response = self.cvm_helper.TerminateInstances(del_req)
            result_content = response.to_json_string()
            return True
        except TencentCloudSDKException as err:
            print(err)
Esempio n. 4
0
def destroy(name, call=None):
    """
    Destroy a Tencent Cloud instance

    CLI Example:

    .. code-block:: bash

        salt-cloud -a destroy myinstance
        salt-cloud -d myinstance
    """
    if call == "function":
        raise SaltCloudSystemExit(
            "The destroy action must be called with -d, --destroy, -a or --action."
        )

    __utils__["cloud.fire_event"](
        "event",
        "destroying instance",
        "salt/cloud/{}/destroying".format(name),
        args={
            "name": name
        },
        sock_dir=__opts__["sock_dir"],
        transport=__opts__["transport"],
    )

    node = _get_node(name)

    client = get_provider_client("cvm_client")
    req = cvm_models.TerminateInstancesRequest()
    req.InstanceIds = [node.InstanceId]
    resp = client.TerminateInstances(req)

    __utils__["cloud.fire_event"](
        "event",
        "destroyed instance",
        "salt/cloud/{}/destroyed".format(name),
        args={
            "name": name
        },
        sock_dir=__opts__["sock_dir"],
        transport=__opts__["transport"],
    )

    return resp
Esempio n. 5
0
def destroy(name, call=None):
    '''
    Destroy a Tencent Cloud instance

    CLI Example:

    .. code-block:: bash

        salt-cloud -a destroy myinstance
        salt-cloud -d myinstance
    '''
    if call == 'function':
        raise SaltCloudSystemExit(
            'The destroy action must be called with -d, --destroy, -a or --action.'
        )

    __utils__['cloud.fire_event']('event',
                                  'destroying instance',
                                  'salt/cloud/{0}/destroying'.format(name),
                                  args={
                                      'name': name
                                  },
                                  sock_dir=__opts__['sock_dir'],
                                  transport=__opts__['transport'])

    node = _get_node(name)

    client = get_provider_client("cvm_client")
    req = cvm_models.TerminateInstancesRequest()
    req.InstanceIds = [node.InstanceId]
    resp = client.TerminateInstances(req)

    __utils__['cloud.fire_event']('event',
                                  'destroyed instance',
                                  'salt/cloud/{0}/destroyed'.format(name),
                                  args={
                                      'name': name
                                  },
                                  sock_dir=__opts__['sock_dir'],
                                  transport=__opts__['transport'])

    return resp
Esempio n. 6
0
    def destroy_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.TerminateInstancesRequest()
            req_config = json.dumps(dict(InstanceIds=[server_id], ))
            req.from_json_string(req_config)

            try:
                client.TerminateInstances(req)
            except Exception as e:
                logging.warning(e)
                result = False
            else:
                result = True
                break
        return result
Esempio n. 7
0
def deleteInstance(InstanceId):
    req = models.TerminateInstancesRequest()
    req.InstanceIds = [InstanceId]
    resp = client.TerminateInstances(req)
    return resp