zoukankan      html  css  js  c++  java
  • 金山云启停虚拟机

    # 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)
  • 相关阅读:
    golang变量2
    golang1
    golang api接收get,post请求读取内容方法
    docker2
    docker
    渗透1
    Crawley框架
    spider类
    爬豆瓣阅读遇到的问题
    CrawlSpiders类
  • 原文地址:https://www.cnblogs.com/slqt/p/10423852.html
Copyright © 2011-2022 走看看