最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

华为云的API调用实践(python版本)

IT圈 admin 43浏览 0评论

2024年1月17日发(作者:昔代秋)

7

8 username='xxx' 9 password='xxx' 10 project_name='xxx' 11 project_domain_id='xxx' 12 user_domain_id='xxx' 13 auth_url='/v3' 14 auth = rd(auth_url=auth_url, 15 username=username, 16 password=password, 17 project_name=project_name, 18 project_domain_id=project_domain_id, 19 user_domain_id=user_domain_id) 20 sess = n(auth=auth) 21 neutron = (session=sess) 22

23

24

25 def createvpn(vpcid, local_cidr, peer_ip, peer_cidr): 26 print "######## create vpn ######" 27 print "################### step 1 vpn service ############" 28

29 vpnservice = { 30 "vpnservice": {

31 "router_id": vpcid, 32 "name": "myservice", 33 "admin_state_up": "true" 34 } 35 } 36

37 ret = _vpnservice(vpnservice) 38

39 vpnserviceid = ret['vpnservice']['id'] 40 print "vpnserviceid = "+vpnserviceid 41

42 print "public_ip = "+ret['vpnservice']['external_v4_ip'] 43

44

45

46 print "################### step 2 ike policy ############" 47

48 ikepolicy = { 49 "ikepolicy": { 50 "phase1_negotiation_mode": "main", 51 "auth_algorithm": "sha1", 52 "encryption_algorithm": "aes-128", 53 "pfs": "group5", 54 "lifetime": { 55 "units": "seconds", 56 "value": 86400 57 }, 58 "ike_version": "v1", 59 "name": "ikepolicy1" 60 } 61 } 62

63 ret = _ikepolicy(ikepolicy) 64

65 ikepolicyid = ret['ikepolicy']['id'] 66 print "ikepolicyid = "+ikepolicyid 67

68

69

70 print "################### step 3 ipsec policy ############" 71

72 ipsecpolicy = {

72 ipsecpolicy = { 73 "ipsecpolicy": { 74 "name": "ipsecpolicy1", 75 "transform_protocol": "esp", 76 "auth_algorithm": "sha1", 77 "encapsulation_mode": "tunnel", 78 "encryption_algorithm": "aes-128", 79 "pfs": "group5", 80 "lifetime": { 81 "units": "seconds", 82 "value": 3600 83 } 84 } 85 } 86

87 ret = _ipsecpolicy(ipsecpolicy) 88

89 ipsecpolicyid = ret['ipsecpolicy']['id'] 90 print "ipsecpolicyid = "+ipsecpolicyid 91

92

93 print "################### step 4 local and remote endpoints ############" 94

95 localendpointgroup = { 96 "endpoint_group": { 97 "endpoints": local_cidr, 98 "type": "cidr", 99 "name": "my-localendpoints"100 }101 }102

103 ret = _endpoint_group(localendpointgroup)104

105 localepgroupid = ret['endpoint_group']['id']106 print "localepgroupid = "+localepgroupid107

108 #### remote endpoint group

109 remoteendpointgroup = {110 "endpoint_group": {111 "endpoints": peer_cidr,112 "type": "cidr",113 "name": "remote-localendpoints"114 }115 }116

117 ret = _endpoint_group(remoteendpointgroup)118

119 remoteepgroupid = ret['endpoint_group']['id']120 print "remoteepgroupid = "+remoteepgroupid121

122

123

124 print "################### step 5 ipsec connection ############"125

126 ipsecconnection = {127 "ipsec_site_connection": {128 "psk": "secret",129 "initiator": "bi-directional",130 "ipsecpolicy_id": ipsecpolicyid,131 "admin_state_up": "true",132 "mtu": "1500",133 "peer_ep_group_id": remoteepgroupid,134 "ikepolicy_id": ikepolicyid,135 "vpnservice_id": vpnserviceid,136 "local_ep_group_id": localepgroupid,137 "peer_address": peer_ip,

2024年1月17日发(作者:昔代秋)

7

8 username='xxx' 9 password='xxx' 10 project_name='xxx' 11 project_domain_id='xxx' 12 user_domain_id='xxx' 13 auth_url='/v3' 14 auth = rd(auth_url=auth_url, 15 username=username, 16 password=password, 17 project_name=project_name, 18 project_domain_id=project_domain_id, 19 user_domain_id=user_domain_id) 20 sess = n(auth=auth) 21 neutron = (session=sess) 22

23

24

25 def createvpn(vpcid, local_cidr, peer_ip, peer_cidr): 26 print "######## create vpn ######" 27 print "################### step 1 vpn service ############" 28

29 vpnservice = { 30 "vpnservice": {

31 "router_id": vpcid, 32 "name": "myservice", 33 "admin_state_up": "true" 34 } 35 } 36

37 ret = _vpnservice(vpnservice) 38

39 vpnserviceid = ret['vpnservice']['id'] 40 print "vpnserviceid = "+vpnserviceid 41

42 print "public_ip = "+ret['vpnservice']['external_v4_ip'] 43

44

45

46 print "################### step 2 ike policy ############" 47

48 ikepolicy = { 49 "ikepolicy": { 50 "phase1_negotiation_mode": "main", 51 "auth_algorithm": "sha1", 52 "encryption_algorithm": "aes-128", 53 "pfs": "group5", 54 "lifetime": { 55 "units": "seconds", 56 "value": 86400 57 }, 58 "ike_version": "v1", 59 "name": "ikepolicy1" 60 } 61 } 62

63 ret = _ikepolicy(ikepolicy) 64

65 ikepolicyid = ret['ikepolicy']['id'] 66 print "ikepolicyid = "+ikepolicyid 67

68

69

70 print "################### step 3 ipsec policy ############" 71

72 ipsecpolicy = {

72 ipsecpolicy = { 73 "ipsecpolicy": { 74 "name": "ipsecpolicy1", 75 "transform_protocol": "esp", 76 "auth_algorithm": "sha1", 77 "encapsulation_mode": "tunnel", 78 "encryption_algorithm": "aes-128", 79 "pfs": "group5", 80 "lifetime": { 81 "units": "seconds", 82 "value": 3600 83 } 84 } 85 } 86

87 ret = _ipsecpolicy(ipsecpolicy) 88

89 ipsecpolicyid = ret['ipsecpolicy']['id'] 90 print "ipsecpolicyid = "+ipsecpolicyid 91

92

93 print "################### step 4 local and remote endpoints ############" 94

95 localendpointgroup = { 96 "endpoint_group": { 97 "endpoints": local_cidr, 98 "type": "cidr", 99 "name": "my-localendpoints"100 }101 }102

103 ret = _endpoint_group(localendpointgroup)104

105 localepgroupid = ret['endpoint_group']['id']106 print "localepgroupid = "+localepgroupid107

108 #### remote endpoint group

109 remoteendpointgroup = {110 "endpoint_group": {111 "endpoints": peer_cidr,112 "type": "cidr",113 "name": "remote-localendpoints"114 }115 }116

117 ret = _endpoint_group(remoteendpointgroup)118

119 remoteepgroupid = ret['endpoint_group']['id']120 print "remoteepgroupid = "+remoteepgroupid121

122

123

124 print "################### step 5 ipsec connection ############"125

126 ipsecconnection = {127 "ipsec_site_connection": {128 "psk": "secret",129 "initiator": "bi-directional",130 "ipsecpolicy_id": ipsecpolicyid,131 "admin_state_up": "true",132 "mtu": "1500",133 "peer_ep_group_id": remoteepgroupid,134 "ikepolicy_id": ikepolicyid,135 "vpnservice_id": vpnserviceid,136 "local_ep_group_id": localepgroupid,137 "peer_address": peer_ip,

发布评论

评论列表 (0)

  1. 暂无评论