2
0

network.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/python
  2. # -*- encoding:utf-8 -*-
  3. import json,pprint
  4. from prettyprinter import prettyPrinter
  5. from kscore.session import get_session
  6. if __name__ == "__main__":
  7. s = get_session()
  8. region='cn-beijing-6'
  9. #region='cn-shanghai-2'
  10. #vpcClient = s.create_client("vpc", region, use_ssl=True)
  11. #vpcClient = s.create_client("vpc", region, use_ssl=True)
  12. #vpcClient = s.create_client("vpc", region, use_ssl=True,verify=False)
  13. #eipClient = s.create_client("eip", region, use_ssl=True)
  14. slbClient = s.create_client("slb", region, use_ssl=True)
  15. #kecClient = s.create_client("kec", region, use_ssl=True)
  16. #allVpcs=vpcClient.describe_vpcs()
  17. #allInstances=kecClient.describe_instances()
  18. #allNics=vpcClient.describe_network_interfaces()
  19. #allEips=eipClient.describe_addresses(MaxResults=7,NextToken='OA==')
  20. #allEips=eipClient.describe_addresses(MaxResults=7)
  21. #allEips=eipClient.describe_addresses(**{'Filter.1.Name':'instance-type','Filter.1.Value.1':'Ipfwd'})
  22. #allEips=eipClient.describe_addresses(**{'Filter.1.Name':'instance-type','Filter.1.Value.1':'Slb'})
  23. #allListeners=slbClient.describe_listeners(**{'Filter.1.Name':'load-balancer-id','Filter.1.Value.1':'89befb57-095a-4329-ae2a-fdfe81959f8c'})
  24. #allListeners=slbClient.describe_listeners()
  25. #slbClient.register_instances_with_listener(**{'ListenerId':'9b465945-5214-4038-8436-c1764b8298f5','RealServerIp':'10.0.0.2','RealServerPort':'80','RealServerType':'host'})
  26. #slbClient.register_instances_with_listener(**{'ListenerId':'c1b03c98-9252-44fe-94e8-ece92767f76e','RealServerIp':'120.92.44.206','RealServerPort':'80','RealServerType':'Ipfwd'})
  27. slbClient.register_instances_with_listener(**{'ListenerId':'9156f303-65fb-4f90-86cb-52dc25721031','RealServerIp':'120.92.33.46','RealServerPort':'4431','RealServerType':'Ipfwd','Weight':10})
  28. slbClient.register_instances_with_listener(**{'ListenerId':'9156f303-65fb-4f90-86cb-52dc25721031','RealServerIp':'120.92.42.4','RealServerPort':'4431','RealServerType':'Ipfwd','Weight':10})
  29. slbClient.register_instances_with_listener(**{'ListenerId':'9156f303-65fb-4f90-86cb-52dc25721031','RealServerIp':'120.92.9.75','RealServerPort':'4431','RealServerType':'Ipfwd','Weight':10})
  30. #givenListeners=slbClient.describe_listeners(**{'ListenerId.1':'d94b6af0-61bd-4b15-ab2c-c6758a3367bc'})
  31. #prettyPrinter().pprint(givenListeners)
  32. #slbClient.deregister_instances_from_listener(**{'RegisterId':'cf0245b2-b847-462a-a777-7f680f6e48b8'})
  33. #slbClient.delete_load_balancer(**{'LoadBalancerId':'b5a2fac6-7cd0-40ee-abb5-dbcc59cbb4b7'})
  34. #pprint.pprint(allEips)
  35. #pprint.pprint(allVpcs)
  36. #prettyPrinter().pprint(allVpcs)
  37. #prettyPrinter().pprint(allEips)
  38. #prettyPrinter().pprint(allNics)
  39. #prettyPrinter().pprint(allInstances)
  40. '''
  41. for item in allEips['AddressesSet']:
  42. print item['PublicIp']
  43. print item['AllocationId']
  44. #eipClient.associate_address(**{'AllocationId':'1cd0da05-8a3e-4c8e-8230-e6d39b85331e','InstanceType':'Ipfwd','InstanceId':'bede9a1c-d3a7-4b31-82e6-6699790ad1a3', 'NetworkInterfaceId':'fec81567-a4c7-4460-a998-54f407e77c0a'})
  45. #eipClient.disassociate_address(**{'AllocationId':'1cd0da05-8a3e-4c8e-8230-e6d39b85331e'})
  46. for item in allListeners['ListenerSet']:
  47. print item['ListenerName']
  48. print item['ListenerId']
  49. #availableIps=vpcClient.describe_subnet_available_addresses(**{'Filter.1.Name':'subnet-id','Filter.1.Value.1':'0d238ac1-69b0-4602-893b-8da5862069e0'})
  50. #pprint.pprint(dir(vpcClient))
  51. #eipClient.modify_address(**{'AllocationId':'c054f87a-4508-4db2-bc10-f594b34a2ef3','BandWidth':1})
  52. #eipClient.modify_address(**{'AllocationId':'070a4af5-90ff-4953-a388-01a694ebdae5','BandWidth':1})
  53. '''