# 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)