Beispiel #1
0
    def do_stop(self, region_id, instance_id):
        client = AcsClient(self.aliyun_token['id'], self.aliyun_token['secret'], region_id)

        # check status first
        describeInstanceAttributeRequest = DescribeInstanceAttributeRequest.DescribeInstanceAttributeRequest()
        describeInstanceAttributeRequest.set_InstanceId(instance_id)
        describeInstanceAttributeRequest.set_accept_format('json')

        resp = json_decode(client.do_action(describeInstanceAttributeRequest))

        result = {}
        # check if exist
        if 'Code' in resp.keys() and resp['Code'] == 'InvalidInstanceId.NotFound':
            result['text'] = 'stop %s %s failed, %s' % (region_id, instance_id, resp['Code'])
        else:
            if resp['Status'] != 'Running':
                result['text'] = 'stop %s %s failed' % (region_id, instance_id)
                result['attachments'] = [{"title": "%s" % resp['InstanceId'], "text": "%s" % resp['Status'], "color": "%s" % self.status_color(resp['Status'])}]
            else:
                stopInstanceRequest = StopInstanceRequest.StopInstanceRequest()
                stopInstanceRequest.set_InstanceId(instance_id)
                stopInstanceRequest.set_accept_format('json')

                client.do_action(stopInstanceRequest)
                result['text'] = 'stopping instance %s %s' % (region_id, instance_id)

        return result
Beispiel #2
0
    def __stopInstance(self, instanceId=None):
        if instanceId is None:
            instance = self.__InstanceId
        else:
            instance = instanceId

        request = StopInstanceRequest.StopInstanceRequest()
        request.set_InstanceId(instance)

        request.set_accept_format(u'json')
        try:
            result = self.__client.do_action(request)
            result_data = json.loads(result)
        except Exception as e:
            print "exception arised "
            print e
            return 1

        if result_data.has_key(u"Code"):
            print 'stop instance failed Code %s with instanceid %s' % (result_data[u'Code'], instance)
            print result_data[u'Message']
            return 1

        else:
            print 'stop instance %s successful  ' % instance
            return 0
Beispiel #3
0
 def stop_instance(self, instance_id, force=False):
     request = StopInstanceRequest.StopInstanceRequest()
     key_list = ["InstanceId", "ForceStop"]
     self.vm_params["InstanceId"] = instance_id
     if force:
         self.vm_params["ForceStop"] = force
     request = self._add_params(request, key_list, self.vm_params)
     return self._send_request(request)
Beispiel #4
0
 def stop_instance(self):
     request = StopInstanceRequest.StopInstanceRequest()
     request.set_accept_format('json')
     request.add_query_param('InstanceId', 'i-bjk23j1rlvfghlq79au')
     request.add_query_param('ForceStop', 'false')
     # 发起请求
     response = self.clentoper.do_action_with_exception(request)
     self.logger.info(response)
     print(response)
Beispiel #5
0
 def stop_instance(client, instance_id):
     mylogger.info("trying to stop instance...", )
     request = StopInstanceRequest.StopInstanceRequest()
     request.set_accept_format("JSON")
     request.set_InstanceId(instance_id)
     content = client.do_action_with_exception(request)
     response = json.loads(content)
     mylogger.info("success")
     return response.get('InstanceId')
Beispiel #6
0
def stopInstance(clt, instanceId):
    print "stopInstance==start:" + instanceId
    request = StopInstanceRequest.StopInstanceRequest()

    request.set_accept_format('json')
    request.set_InstanceId(instanceId)
    request.set_ForceStop('true')
    result = clt.do_action(request)
    print "stopInstance==end:(" + instanceId + ")" + result
    return result
Beispiel #7
0
 def stop_instances(self, instance_id, force_stop=True):
     try:
         request = StopInstanceRequest.StopInstanceRequest()
         request.set_InstanceId(instance_id)
         request.set_ForceStop(force_stop)
         self._send_request(request)
         logging.info("Stop %s command submit successfully.", instance_id)
     except Exception as e:
         logging.error("Failed to stop node instance %s. Encountered following " "exception: %s." % (instance_id, e))
         sys.exit(1)
Beispiel #8
0
def stop_vm(vmid):
    client = create_acs_client()

    request = StopInstanceRequest.StopInstanceRequest()
    request.set_action_name('StopInstance')
    request.set_InstanceId(vmid)
    response = client.do_action_with_exception(request)
    r = json.loads(response.decode())
    log.debug(r)
    return r
Beispiel #9
0
 def stop_server(self,serverid):
     client = AcsClient(access_key_id, access_key_secret,region_id)
     request = StopInstanceRequest.StopInstanceRequest()
     request.set_InstanceId(serverid)
     response = client.do_action_with_exception(request)
     i = 0
     while i < 600:
         serverstatus = self.get_server_status_by_serverid(serverid)
         if serverstatus['status'] == 'Stopped':
             break
         time.sleep(1)
         i = i + 1
     if  i == 600:
         raise Exception('stop timeout')
     return response
Beispiel #10
0
    def stop_instance(self, instance_id):
        """
        关闭实例
        :param instance_id:
        :return: JobId
        """
        request = StopInstanceRequest.StopInstanceRequest()
        request.set_protocol_type("https")
        request.set_accept_format('json')
        request.set_InstanceId(instance_id)

        try:
            response = self.client.do_action_with_exception(request)
            result = str(response, encoding='utf-8')
        except ServerException as e:
            result = e
        except ClientException as e:
            result = e
        return result
Beispiel #11
0
request = StartInstanceRequest.StartInstanceRequest()
request.set_accept_format('json')
request.set_InstanceId('i-62wpk9e7e')

#print clt.do_action(request)

print "##########ModifyInstanceNetworkSpec###########"
request = ModifyInstanceNetworkSpecRequest.ModifyInstanceNetworkSpecRequest()
request.set_accept_format('json')
request.set_InstanceId('i-62wpk9e7e')
request.set_InternetMaxBandwidthOut(1)

#print clt.do_action(request)

print "##########StopInstance###########"
request = StopInstanceRequest.StopInstanceRequest()
request.set_accept_format('json')
request.set_InstanceId('i-62wpk9e7e')
request.set_ForceStop('true')

#print clt.do_action(request)

print "##########DeleteInstance###########"
request = DeleteInstanceRequest.DeleteInstanceRequest()
request.set_accept_format('json')
request.set_InstanceId('i-62wpk9e7e')

#print clt.do_action(request)

print "##########AllocateEipAddress###########"
request = AllocateEipAddressRequest.AllocateEipAddressRequest()
Beispiel #12
0
 def stop_instance(self):
     request = StopInstanceRequest.StopInstanceRequest()
     request.set_InstanceId(self.resource_id)
     self.execute(request, raise_on_falsy=True)
     return True
Beispiel #13
0
 def shutdown_server(self, server_id, *args, **kwargs) -> bool:
     request = StopInstanceRequest.StopInstanceRequest()
     request.set_InstanceId(server_id)
     request.set_ConfirmStop(True)
     response = self.handle_request(request)
     return bool(response)
Beispiel #14
0
def stop_instance(config):
    click.echo(click.style("Stoping instance ...", fg="green"))
    client = config.create_api_client()
    req = StopInstanceRequest.StopInstanceRequest()
    req.set_InstanceId(config.get('InstanceId'))
    result = do_action(client, req)
Beispiel #15
0
 def StopInstance(self):
     request = StopInstanceRequest.StopInstanceRequest()
     request.set_InstanceId(self.instance_id)
     result = self.client.do_action_with_exception(request)
     return result
def stop(instance_id):
    request = StopInstanceRequest.StopInstanceRequest()
    request.set_InstanceId(instance_id)
    response = client.do_action_with_exception(request)
    print("停止实例: {}".format(response))
Beispiel #17
0
def stop():
    request = StopInstanceRequest.StopInstanceRequest()
    request.set_InstanceId('i-uf65cpnw0xewj6niwaju')
    resp = client.do_action_with_exception(request)

    print(resp)