コード例 #1
0
ファイル: vpc.py プロジェクト: yangchenglong11/ksc-sdk-python
#!/usr/bin/python

# -*- encoding:utf-8 -*-

import json, pprint
from prettyprinter import prettyPrinter
from kscore.session import get_session

if __name__ == "__main__":
    s = get_session()

    region = 'cn-beijing-6'
    #region='cn-shanghai-2'
    vpcClient = s.create_client("vpc", region, use_ssl=True)

    allVpcs = vpcClient.describe_vpcs()
    #allNics=vpcClient.describe_network_interfaces()

    prettyPrinter().pprint(allVpcs)
コード例 #2
0
ファイル: slb.py プロジェクト: yangchenglong11/ksc-sdk-python
#!/usr/bin/python

# -*- encoding:utf-8 -*-

import json, pprint
from prettyprinter import prettyPrinter
from kscore.session import get_session

if __name__ == "__main__":
    s = get_session()

    region = 'cn-beijing-6'
    #region='cn-shanghai-2'
    slbClient = s.create_client("slb", region, use_ssl=True)
    #kecClient = s.create_client("kec", region, use_ssl=True)

    #allInstances=kecClient.describe_instances()
    #allListeners=slbClient.describe_listeners(**{'Filter.1.Name':'load-balancer-id','Filter.1.Value.1':'89befb57-095a-4329-ae2a-fdfe81959f8c'})
    allListeners = slbClient.describe_listeners()
    #slbClient.register_instances_with_listener(**{'ListenerId':'9b465945-5214-4038-8436-c1764b8298f5','RealServerIp':'10.0.0.2','RealServerPort':'80','RealServerType':'host'})
    #givenListeners=slbClient.describe_listeners(**{'ListenerId.1':'d94b6af0-61bd-4b15-ab2c-c6758a3367bc'})
    prettyPrinter().pprint(allListeners)
    #slbClient.deregister_instances_from_listener(**{'RegisterId':'cf0245b2-b847-462a-a777-7f680f6e48b8'})
    #slbClient.delete_load_balancer(**{'LoadBalancerId':'b5a2fac6-7cd0-40ee-abb5-dbcc59cbb4b7'})

    #prettyPrinter().pprint(allInstances)
    for item in allListeners['ListenerSet']:
        print item['ListenerName']
        print item['ListenerId']
コード例 #3
0
ファイル: sks.py プロジェクト: xiaoxianni/ksc-sdk-python
# -*- encoding:utf-8 -*-

import json, pprint
from prettyprinter import prettyPrinter
from kscore.session import get_session

if __name__ == "__main__":
    s = get_session()

    region = 'cn-beijing-6'
    # region='cn-shanghai-2'
    sksClient = s.create_client("sks", region, use_ssl=True)
    #query
    allKeys = sksClient.describe_keys()
    prettyPrinter().pprint(allKeys)
    #create
    # createKey = sksClient.create_key(**{"KeyName":"j-test-3"})
    # prettyPrinter().pprint(createKey)
    #import
    # importKey = sksClient.import_key(**{"KeyName":"j-test-5","PublicKey":"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCcbmgQsS4zM43iFsCo31GtUfp1/cdTXhFha4MkvWnSQaz4Z7ehDHqx9nT2fadY1f0hBD4aNDO3bf+3zUSejOcJw15xlTtiNQ57ttH4LsG+6CP03h9WYYwcCtsnlaPfVr0LldSpLSiHa2UrhuAVItGe6v54+6e8ncueiA6fUW1jUw== root"})
    # prettyPrinter().pprint(importKey)

    #modify
    # modifyKey = sksClient.modify_key(**{"KeyId":"005d19f6-774d-4631-9eda-3dbbd34100d1","KeyName":"modify-test"})
    # prettyPrinter().pprint(modifyKey)

    #delete
    # deleteKey = sksClient.delete_key(**{"KeyId":"a748558d-8994-4f5e-add1-9c4230115608"})
    # prettyPrinter().pprint(deleteKey)
コード例 #4
0
ファイル: network.py プロジェクト: CurryGaifan/ksc-sdk-python
    #allEips=eipClient.describe_addresses(MaxResults=7)
    #allEips=eipClient.describe_addresses(**{'Filter.1.Name':'instance-type','Filter.1.Value.1':'Ipfwd'})
    allInstances = kecClient.describe_instances()
    allEips = eipClient.describe_addresses(**{
        'Filter.1.Name': 'instance-type',
        'Filter.1.Value.1': 'Slb'
    })
    allListeners = slbClient.describe_listeners(
        **{
            'Filter.1.Name': 'load-balancer-id',
            'Filter.1.Value.1': '5acac037-531c-414e-bb6f-c639c8948a57'
        })
    #slbClient.register_instances_with_listener(**{'ListenerId':'9b465945-5214-4038-8436-c1764b8298f5','RealServerIp':'10.0.0.2','RealServerPort':'80','RealServerType':'host'})
    givenListeners = slbClient.describe_listeners(
        **{'ListenerId.1': '9b465945-5214-4038-8436-c1764b8298f5'})
    prettyPrinter().pprint(givenListeners)
    #slbClient.deregister_instances_from_listener(**{'RegisterId':'cf0245b2-b847-462a-a777-7f680f6e48b8'})

    #pprint.pprint(allEips)

    #prettyPrinter().pprint(allVpcs)
    #prettyPrinter().pprint(allEips)
    #prettyPrinter().pprint(allNics)
    #prettyPrinter().pprint(allInstances)
    for item in allEips['AddressesSet']:
        print item['PublicIp']
        print item['AllocationId']
    #eipClient.associate_address(**{'AllocationId':'1cd0da05-8a3e-4c8e-8230-e6d39b85331e','InstanceType':'Ipfwd','InstanceId':'bede9a1c-d3a7-4b31-82e6-6699790ad1a3', 'NetworkInterfaceId':'fec81567-a4c7-4460-a998-54f407e77c0a'})
    #eipClient.disassociate_address(**{'AllocationId':'1cd0da05-8a3e-4c8e-8230-e6d39b85331e'})
    for item in allListeners['ListenerSet']:
        print item['ListenerName']
コード例 #5
0
ファイル: network.py プロジェクト: smartwang/kscore
    })
    allListeners = slbClient.describe_listeners(
        **{
            'Filter.1.Name': 'load-balancer-id',
            'Filter.1.Value.1': '5acac037-531c-414e-bb6f-c639c8948a57'
        })
    givenListeners = slbClient.describe_listeners(
        **{'ListenerId.1': 'ca2717c8-9bc0-4955-a2f1-2b53b24301b9'})
    #slbClient.deregister_instances_from_listener(**{'RegisterId':'b74b0d7f-79f2-4601-980f-326804f22f42'})

    #pprint.pprint(allEips)

    #prettyPrinter().pprint(allVpcs)
    #prettyPrinter().pprint(allEips)
    #prettyPrinter().pprint(allNics)
    prettyPrinter().pprint(allInstances)
    for item in allEips['AddressesSet']:
        print item['PublicIp']
        print item['AllocationId']
    eipClient.associate_address(
        **{
            'AllocationId': '1cd0da05-8a3e-4c8e-8230-e6d39b85331e',
            'InstanceType': 'Ipfwd',
            'InstanceId': 'bede9a1c-d3a7-4b31-82e6-6699790ad1a3',
            'NetworkInterfaceId': 'fec81567-a4c7-4460-a998-54f407e77c0a'
        })
    eipClient.disassociate_address(
        **{'AllocationId': '1cd0da05-8a3e-4c8e-8230-e6d39b85331e'})
    for item in allListeners['ListenerSet']:
        print item['ListenerName']
        print item['ListenerId']
コード例 #6
0
#!/usr/bin/python

# -*- encoding:utf-8 -*-

import json,pprint
from prettyprinter import prettyPrinter
from kscore.session import get_session

if __name__ == "__main__":
    s = get_session()

    region='cn-beijing-6'
    dnsClient = s.create_client("dns", region, use_ssl=True)

    allZones=dnsClient.describe_hosted_zones(**{'HostedZoneId':'319076f8-15cb-4e2a-b784-9d18fbaf95ca'})
    allRecords = dnsClient.describe_resource_records(**{'HostedZoneId':'319076f8-15cb-4e2a-b784-9d18fbaf95ca'})


    prettyPrinter().pprint(allZones)
    prettyPrinter().pprint(allRecords)
コード例 #7
0
ファイル: kis.py プロジェクト: yangchenglong11/ksc-sdk-python
from prettyprinter import prettyPrinter
from kscore.session import get_session
import json

if __name__ == "__main__":
	s = get_session()
	ak = "your AK"
	sk = "your SK"
	kis_client = s.create_client("kis", "cn-beijing-6", "2018-09-01", True, None, None, ak, sk)
	# 列出region
	regions = kis_client.list_region()
	# prettyPrinter().pprint(regions)

	# 列出Idc
	idcs = kis_client.list_idc()
	prettyPrinter().pprint(idcs)

	# 查询各机房内机柜
	for idc in idcs["Data"]:
		devices = kis_client.get_cabinet(Idc=idc["Name"], Limit=-1)
		if devices["Total"] > 0:
			prettyPrinter().pprint(devices)

	# 查询带宽
	instances = []
	for idc in idcs["Data"]:
		bds = kis_client.get_bandwidth(Idc=idc["Name"], Limit=-1)
		if bds["Total"] > 0:
			# prettyPrinter().pprint(bds)
			for bd in bds["Data"]:
				instances.append(bd["InstanceId"])
コード例 #8
0
ファイル: epc.py プロジェクト: xiaoxianni/ksc-sdk-python
#!/usr/bin/python

# -*- encoding:utf-8 -*-

import json, pprint
from prettyprinter import prettyPrinter
from kscore.session import get_session

if __name__ == "__main__":
    s = get_session()

    region = 'cn-beijing-6'
    #region='cn-shanghai-2'
    epcClient = s.create_client("epc", region, use_ssl=True)
    #query epc
    resp = epcClient.describe_epcs(MaxResults=7)
    #resp=epcClient.describe_epcs(**{'Filter.1.Name':'host-type','Filter.1.Value.1':'CAL'})
    prettyPrinter().pprint(resp)
コード例 #9
0
ファイル: network.py プロジェクト: liuyichen/kscore
    kecClient = s.create_client("kec", "cn-shanghai-2", use_ssl=False)

    #allVpcs=vpcClient.describe_vpcs()
    #allNics=vpcClient.describe_network_interfaces()
    #allEips=eipClient.describe_addresses(MaxResults=7,NextToken='OA==')
    #allEips=eipClient.describe_addresses(MaxResults=7)
    #allEips=eipClient.describe_addresses(**{'Filter.1.Name':'instance-type','Filter.1.Value.1':'Ipfwd'})
    allInstances=kecClient.describe_instances()
    allEips=eipClient.describe_addresses(**{'Filter.1.Name':'instance-type','Filter.1.Value.1':'Slb'})
    allListeners=slbClient.describe_listeners(**{'Filter.1.Name':'load-balancer-id','Filter.1.Value.1':'5acac037-531c-414e-bb6f-c639c8948a57'}) 
    givenListeners=slbClient.describe_listeners(**{'ListenerId.1':'ca2717c8-9bc0-4955-a2f1-2b53b24301b9'}) 
    #slbClient.deregister_instances_from_listener(**{'RegisterId':'b74b0d7f-79f2-4601-980f-326804f22f42'}) 

    #pprint.pprint(allEips)

    #prettyPrinter().pprint(allVpcs)
    #prettyPrinter().pprint(allEips)
    #prettyPrinter().pprint(allNics)
    prettyPrinter().pprint(allInstances)
    for item in allEips['AddressesSet']:
       print item['PublicIp']
       print item['AllocationId']
    eipClient.associate_address(**{'AllocationId':'1cd0da05-8a3e-4c8e-8230-e6d39b85331e','InstanceType':'Ipfwd','InstanceId':'bede9a1c-d3a7-4b31-82e6-6699790ad1a3', 'NetworkInterfaceId':'fec81567-a4c7-4460-a998-54f407e77c0a'})
    eipClient.disassociate_address(**{'AllocationId':'1cd0da05-8a3e-4c8e-8230-e6d39b85331e'})
    for item in allListeners['ListenerSet']:
       print item['ListenerName']
       print item['ListenerId']
    prettyPrinter().pprint(givenListeners)
    #availableIps=vpcClient.describe_subnet_available_addresses()
    #availableIps=vpcClient.describe_subnet_available_addresses(**{'Filter.1.Name':'subnet-id','Filter.1.Value.1':'0d238ac1-69b0-4602-893b-8da5862069e0'})