金山云启停虚拟机

# coding=utf8
from kscore.session import get_session
import re
import sys


def make_conn(service_name, region):
try:
s = get_session()
url = 'http://kec.{}.api.hopebank.com'.format(region)
if url.startswith('http://'):
is_ssl = False
else:
is_ssl = True
client = s.create_client(service_name, region_name=region, endpoint_url=url,
use_ssl=is_ssl, ks_access_key_id=ACCESS_KEY_ID,
ks_secret_access_key=SECRET_ACCESS_KEY, api_version='2016-03-04',
verify=False)
return client
except Exception as e:
print e


def startKec(client,instanceId):
try:
client.start_instances(**{'InstanceId.1': instanceId})
except ClientError, e:
print str(e)
else:
print 'start success!!!!'

def stopKec(client,instanceId):
try:
client.stop_instances(**{'InstanceId.1': instanceId})
except ClientError, e:
print str(e)
else:
print 'stop success!!!!'

if __name__ == '__main__':
project_id = 0
client = make_conn('kec', region)
if action=='start':
startKec(client,vm_id)
else:
stopKec(client, vm_id)
上一篇:202-STM32+W5500基本控制篇(阿里云物联网平台)-设备使用一型一密动态注册方式连接云平台,并使用物模型Topic上报温湿度数据


下一篇:Pset_ProjectOrderChangeOrder