filtered-azure-compute.res 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. cloudbridge.test.test_compute_service.CloudComputeServiceTestCase
  2. Error during cleanup: 'NoneType' object has no attribute '_ip'
  3. Test output
  4. E.....
  5. ======================================================================
  6. ERROR: test_block_device_mapping_attachments (cloudbridge.test.test_compute_service.CloudComputeServiceTestCase)
  7. ----------------------------------------------------------------------
  8. Traceback (most recent call last):
  9. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 45, in wrap_exception
  10. return next_handler.invoke(event_args, *args, **kwargs)
  11. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 110, in invoke
  12. result = self.callback(*args, **kwargs)
  13. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/line_profiler.py", line 115, in wrapper
  14. result = func(*args, **kwds)
  15. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py", line 537, in create
  16. params)
  17. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py", line 527, in create_snapshot
  18. params
  19. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/azure/mgmt/compute/v2018_04_01/operations/snapshots_operations.py", line 127, in create_or_update
  20. **operation_config
  21. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/azure/mgmt/compute/v2018_04_01/operations/snapshots_operations.py", line 79, in _create_or_update_initial
  22. raise exp
  23. msrestazure.azure_exceptions.CloudError: Azure Error: NotFound
  24. Message: Resource cb-blkattch-6797b5-607ed5 is not found.
  25. The above exception was the direct cause of the following exception:
  26. Traceback (most recent call last):
  27. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 41, in wrapper
  28. func(self, *args, **kwargs)
  29. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/test_compute_service.py", line 250, in test_block_device_mapping_attachments
  30. description=label)
  31. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py", line 445, in create_snapshot
  32. description)
  33. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/middleware.py", line 74, in wrapper
  34. return dispatcher.dispatch(self, event, *args, **kwargs)
  35. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 218, in dispatch
  36. return handlers[0].invoke(event_args, *args, **kwargs)
  37. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 78, in invoke
  38. result = self.callback(event_args, *args, **kwargs)
  39. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 55, in wrap_exception
  40. six.raise_from(cb_ex, e)
  41. File "<string>", line 3, in raise_from
  42. cloudbridge.cloud.interfaces.exceptions.CloudBridgeBaseException: CloudBridgeBaseException: Azure Error: NotFound
  43. Message: Resource cb-blkattch-6797b5-607ed5 is not found. from exception type: <class 'msrestazure.azure_exceptions.CloudError'>
  44. ----------------------------------------------------------------------
  45. Ran 6 tests in 1695.659s
  46. FAILED (errors=1)
  47. Wrote profile results to run_single.py.lprof
  48. Timer unit: 1e-06 s
  49. Total time: 506.829 s
  50. Function: create at line 863
  51. Line # Hits Time Per Hit % Time Line Contents
  52. ==============================================================
  53. 863 @dispatch(event="provider.compute.instances.create",
  54. 864 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  55. 865 @profile
  56. 866 def create(self, label, image, vm_type, subnet, zone,
  57. 867 key_pair=None, vm_firewalls=None, user_data=None,
  58. 868 launch_config=None, **kwargs):
  59. 869 13 299.0 23.0 0.0 AzureInstance.assert_valid_resource_label(label)
  60. 870 3 10.0 3.3 0.0 instance_name = AzureInstance._generate_name_from_label(label,
  61. 871 3 150.0 50.0 0.0 "cb-ins")
  62. 872
  63. 873 3 8.0 2.7 0.0 image = (image if isinstance(image, AzureMachineImage) else
  64. 874 3 317.0 105.7 0.0 self.provider.compute.images.get(image))
  65. 875 3 7.0 2.3 0.0 if not isinstance(image, AzureMachineImage):
  66. 876 raise Exception("Provided image %s is not a valid azure image"
  67. 877 % image)
  68. 878
  69. 879 instance_size = vm_type.id if \
  70. 880 3 13.0 4.3 0.0 isinstance(vm_type, VMType) else vm_type
  71. 881
  72. 882 3 6.0 2.0 0.0 if not subnet:
  73. 883 # Azure has only a single zone per region; use the current one
  74. 884 zone = self.provider.compute.regions.get(
  75. 885 self.provider.region_name).zones[0]
  76. 886 subnet = self.provider.networking.subnets.get_or_create_default(
  77. 887 zone)
  78. 888 else:
  79. 889 subnet = (self.provider.networking.subnets.get(subnet)
  80. 890 3 39.0 13.0 0.0 if isinstance(subnet, str) else subnet)
  81. 891
  82. 892 3 7.0 2.3 0.0 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  83. 893
  84. 894 subnet_id, zone_id, vm_firewall_id = \
  85. 895 3 7.0 2.3 0.0 self._resolve_launch_options(instance_name,
  86. 896 3 1338948.0 446316.0 0.3 subnet, zone_id, vm_firewalls)
  87. 897
  88. 898 3 8.0 2.7 0.0 storage_profile = self._create_storage_profile(image, launch_config,
  89. 899 3 1155.0 385.0 0.0 instance_name, zone_id)
  90. 900
  91. 901 nic_params = {
  92. 902 3 17.0 5.7 0.0 'location': self.provider.region_name,
  93. 903 'ip_configurations': [{
  94. 904 3 4.0 1.3 0.0 'name': instance_name + '_ip_config',
  95. 905 3 4.0 1.3 0.0 'private_ip_allocation_method': 'Dynamic',
  96. 906 'subnet': {
  97. 907 3 6.0 2.0 0.0 'id': subnet_id
  98. 908 }
  99. 909 }]
  100. 910 }
  101. 911
  102. 912 3 5.0 1.7 0.0 if vm_firewall_id:
  103. 913 nic_params['network_security_group'] = {
  104. 914 1 1.0 1.0 0.0 'id': vm_firewall_id
  105. 915 }
  106. 916 3 20.0 6.7 0.0 nic_info = self.provider.azure_client.create_nic(
  107. 917 3 4.0 1.3 0.0 instance_name + '_nic',
  108. 918 3 97431330.0 32477110.0 19.2 nic_params
  109. 919 )
  110. 920 # #! indicates shell script
  111. 921 ud = '#cloud-config\n' + user_data \
  112. 922 3 10.0 3.3 0.0 if user_data and not user_data.startswith('#!')\
  113. 923 and not user_data.startswith('#cloud-config') else user_data
  114. 924
  115. 925 # Key_pair is mandatory in azure and it should not be None.
  116. 926 3 5.0 1.7 0.0 temp_key_pair = None
  117. 927 3 6.0 2.0 0.0 if key_pair:
  118. 928 1 3.0 3.0 0.0 key_pair = (key_pair if isinstance(key_pair, AzureKeyPair)
  119. 929 else self.provider.security.key_pairs.get(key_pair))
  120. 930 else:
  121. 931 # Create a temporary keypair if none is provided to keep Azure
  122. 932 # happy, but the private key will be discarded, so it'll be all
  123. 933 # but useless. However, this will allow an instance to be launched
  124. 934 # without specifying a keypair, so users may still be able to login
  125. 935 # if they have a preinstalled keypair/password baked into the image
  126. 936 2 8.0 4.0 0.0 temp_kp_name = "".join(["cb-default-kp-",
  127. 937 2 9.0 4.5 0.0 str(uuid.uuid5(uuid.NAMESPACE_OID,
  128. 938 2 164.0 82.0 0.0 instance_name))[-6:]])
  129. 939 2 37.0 18.5 0.0 key_pair = self.provider.security.key_pairs.create(
  130. 940 2 6471263.0 3235631.5 1.3 name=temp_kp_name)
  131. 941 2 3.0 1.5 0.0 temp_key_pair = key_pair
  132. 942
  133. 943 params = {
  134. 944 3 6.0 2.0 0.0 'location': zone_id or self.provider.region_name,
  135. 945 'os_profile': {
  136. 946 3 19.0 6.3 0.0 'admin_username': self.provider.vm_default_user_name,
  137. 947 3 5.0 1.7 0.0 'computer_name': instance_name,
  138. 948 'linux_configuration': {
  139. 949 3 4.0 1.3 0.0 "disable_password_authentication": True,
  140. 950 "ssh": {
  141. 951 3 5.0 1.7 0.0 "public_keys": [{
  142. 952 "path":
  143. 953 3 6.0 2.0 0.0 "/home/{}/.ssh/authorized_keys".format(
  144. 954 3 13.0 4.3 0.0 self.provider.vm_default_user_name),
  145. 955 3 25.0 8.3 0.0 "key_data": key_pair._key_pair.Key
  146. 956 }]
  147. 957 }
  148. 958 }
  149. 959 },
  150. 960 'hardware_profile': {
  151. 961 3 6.0 2.0 0.0 'vm_size': instance_size
  152. 962 },
  153. 963 'network_profile': {
  154. 964 3 5.0 1.7 0.0 'network_interfaces': [{
  155. 965 3 10.0 3.3 0.0 'id': nic_info.id
  156. 966 }]
  157. 967 },
  158. 968 3 4.0 1.3 0.0 'storage_profile': storage_profile,
  159. 969 3 7.0 2.3 0.0 'tags': {'Label': label}
  160. 970 }
  161. 971
  162. 972 3 13.0 4.3 0.0 for disk_def in storage_profile.get('data_disks', []):
  163. 973 params['tags'] = dict(disk_def.get('tags', {}), **params['tags'])
  164. 974
  165. 975 3 5.0 1.7 0.0 if user_data:
  166. 976 custom_data = base64.b64encode(bytes(ud, 'utf-8'))
  167. 977 params['os_profile']['custom_data'] = str(custom_data, 'utf-8')
  168. 978
  169. 979 3 5.0 1.7 0.0 if not temp_key_pair:
  170. 980 1 8.0 8.0 0.0 params['tags'].update(Key_Pair=key_pair.id)
  171. 981
  172. 982 3 5.0 1.7 0.0 try:
  173. 983 3 400185160.0 133395053.3 79.0 vm = self.provider.azure_client.create_vm(instance_name, params)
  174. 984 except Exception as e:
  175. 985 # If VM creation fails, attempt to clean up intermediary resources
  176. 986 self.provider.azure_client.delete_nic(nic_info.id)
  177. 987 for disk_def in storage_profile.get('data_disks', []):
  178. 988 if disk_def.get('tags', {}).get('delete_on_terminate'):
  179. 989 disk_id = disk_def.get('managed_disk', {}).get('id')
  180. 990 if disk_id:
  181. 991 vol = self.provider.storage.volumes.get(disk_id)
  182. 992 vol.delete()
  183. 993 raise e
  184. 994 finally:
  185. 995 3 11.0 3.7 0.0 if temp_key_pair:
  186. 996 2 376098.0 188049.0 0.1 temp_key_pair.delete()
  187. 997 3 1023402.0 341134.0 0.2 return AzureInstance(self.provider, vm)
  188. Total time: 490.461 s
  189. Function: delete at line 1044
  190. Line # Hits Time Per Hit % Time Line Contents
  191. ==============================================================
  192. 1044 @dispatch(event="provider.compute.instances.delete",
  193. 1045 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  194. 1046 @profile
  195. 1047 def delete(self, instance):
  196. 1048 """
  197. 1049 Permanently terminate this instance.
  198. 1050 After deleting the VM. we are deleting the network interface
  199. 1051 associated to the instance, and also removing OS disk and data disks
  200. 1052 where tag with name 'delete_on_terminate' has value True.
  201. 1053 """
  202. 1054 3 6.0 2.0 0.0 ins = (instance if isinstance(instance, AzureInstance) else
  203. 1055 self.get(instance))
  204. 1056 3 3.0 1.0 0.0 if not instance:
  205. 1057 return
  206. 1058
  207. 1059 # Remove IPs first to avoid a network interface conflict
  208. 1060 # pylint:disable=protected-access
  209. 1061 3 658259.0 219419.7 0.1 for public_ip_id in ins._public_ip_ids:
  210. 1062 ins.remove_floating_ip(public_ip_id)
  211. 1063 3 232371164.0 77457054.7 47.4 self.provider.azure_client.deallocate_vm(ins.id)
  212. 1064 3 124970163.0 41656721.0 25.5 self.provider.azure_client.delete_vm(ins.id)
  213. 1065 # pylint:disable=protected-access
  214. 1066 6 54.0 9.0 0.0 for nic_id in ins._nic_ids:
  215. 1067 3 36080517.0 12026839.0 7.4 self.provider.azure_client.delete_nic(nic_id)
  216. 1068 # pylint:disable=protected-access
  217. 1069 3 21.0 7.0 0.0 for data_disk in ins._vm.storage_profile.data_disks:
  218. 1070 if data_disk.managed_disk:
  219. 1071 # pylint:disable=protected-access
  220. 1072 if ins._vm.tags.get('delete_on_terminate',
  221. 1073 'False') == 'True':
  222. 1074 self.provider.azure_client. \
  223. 1075 delete_disk(data_disk.managed_disk.id)
  224. 1076 # pylint:disable=protected-access
  225. 1077 3 6.0 2.0 0.0 if ins._vm.storage_profile.os_disk.managed_disk:
  226. 1078 3 28.0 9.3 0.0 self.provider.azure_client. \
  227. 1079 3 96380595.0 32126865.0 19.7 delete_disk(ins._vm.storage_profile.os_disk.managed_disk.id)
  228. Total time: 165.88 s
  229. Function: create at line 113
  230. Line # Hits Time Per Hit % Time Line Contents
  231. ==============================================================
  232. 113 @cb_helpers.deprecated_alias(network_id='network')
  233. 114 @dispatch(event="provider.security.vm_firewalls.create",
  234. 115 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  235. 116 @profile
  236. 117 def create(self, label, network, description=None):
  237. 118 2 31.0 15.5 0.0 AzureVMFirewall.assert_valid_resource_label(label)
  238. 119 2 102.0 51.0 0.0 name = AzureVMFirewall._generate_name_from_label(label, "cb-fw")
  239. 120 2 5.0 2.5 0.0 net = network.id if isinstance(network, Network) else network
  240. 121 2 10.0 5.0 0.0 parameters = {"location": self.provider.region_name,
  241. 122 2 2.0 1.0 0.0 "tags": {'Label': label,
  242. 123 2 2.0 1.0 0.0 'network_id': net}}
  243. 124
  244. 125 2 1.0 0.5 0.0 if description:
  245. 126 2 5.0 2.5 0.0 parameters['tags'].update(Description=description)
  246. 127
  247. 128 2 10.0 5.0 0.0 fw = self.provider.azure_client.create_vm_firewall(name,
  248. 129 2 10108748.0 5054374.0 6.1 parameters)
  249. 130
  250. 131 # Add default rules to negate azure default rules.
  251. 132 # See: https://github.com/CloudVE/cloudbridge/issues/106
  252. 133 # pylint:disable=protected-access
  253. 134 14 40.0 2.9 0.0 for rule in fw.default_security_rules:
  254. 135 12 17.0 1.4 0.0 rule_name = "cb-override-" + rule.name
  255. 136 # Transpose rules to priority 4001 onwards, because
  256. 137 # only 0-4096 are allowed for custom rules
  257. 138 12 19.0 1.6 0.0 rule.priority = rule.priority - 61440
  258. 139 12 11.0 0.9 0.0 rule.access = "Deny"
  259. 140 12 108.0 9.0 0.0 self.provider.azure_client.create_vm_firewall_rule(
  260. 141 12 132700240.0 11058353.3 80.0 fw.id, rule_name, rule)
  261. 142
  262. 143 # Add a new custom rule allowing all outbound traffic to the internet
  263. 144 2 3.0 1.5 0.0 parameters = {"priority": 3000,
  264. 145 2 2.0 1.0 0.0 "protocol": "*",
  265. 146 2 1.0 0.5 0.0 "source_port_range": "*",
  266. 147 2 2.0 1.0 0.0 "source_address_prefix": "*",
  267. 148 2 2.0 1.0 0.0 "destination_port_range": "*",
  268. 149 2 3.0 1.5 0.0 "destination_address_prefix": "Internet",
  269. 150 2 2.0 1.0 0.0 "access": "Allow",
  270. 151 2 10.0 5.0 0.0 "direction": "Outbound"}
  271. 152 2 20.0 10.0 0.0 result = self.provider.azure_client.create_vm_firewall_rule(
  272. 153 2 23070528.0 11535264.0 13.9 fw.id, "cb-default-internet-outbound", parameters)
  273. 154 2 9.0 4.5 0.0 fw.security_rules.append(result)
  274. 155
  275. 156 2 53.0 26.5 0.0 cb_fw = AzureVMFirewall(self.provider, fw)
  276. 157 2 2.0 1.0 0.0 return cb_fw
  277. Total time: 96.5834 s
  278. Function: label at line 1086
  279. Line # Hits Time Per Hit % Time Line Contents
  280. ==============================================================
  281. 1086 @label.setter
  282. 1087 # pylint:disable=arguments-differ
  283. 1088 @profile
  284. 1089 def label(self, value):
  285. 1090 """
  286. 1091 Set the instance label.
  287. 1092 """
  288. 1093 11 153.0 13.9 0.0 self.assert_valid_resource_label(value)
  289. 1094 3 9.0 3.0 0.0 self._vm.tags.update(Label=value or "")
  290. 1095 3 22.0 7.3 0.0 self._provider.azure_client. \
  291. 1096 3 96583183.0 32194394.3 100.0 update_vm_tags(self.id, self._vm)
  292. Total time: 42.3776 s
  293. Function: delete at line 1308
  294. Line # Hits Time Per Hit % Time Line Contents
  295. ==============================================================
  296. 1308 @dispatch(event="provider.networking.subnets.delete",
  297. 1309 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  298. 1310 @profile
  299. 1311 def delete(self, subnet):
  300. 1312 1 2.0 2.0 0.0 sn = subnet if isinstance(subnet, AzureSubnet) else self.get(subnet)
  301. 1313 1 1.0 1.0 0.0 if sn:
  302. 1314 1 10703257.0 10703257.0 25.3 self.provider.azure_client.delete_subnet(sn.id)
  303. 1315 # Although Subnet doesn't support labels, we use the parent
  304. 1316 # Network's tags to track the subnet's labels, thus that
  305. 1317 # network-level tag must be deleted with the subnet
  306. 1318 1 51.0 51.0 0.0 net_id = sn.network_id
  307. 1319 1 331141.0 331141.0 0.8 az_network = self.provider.azure_client.get_network(net_id)
  308. 1320 1 10.0 10.0 0.0 az_network.tags.pop(sn.tag_name)
  309. 1321 1 6.0 6.0 0.0 self.provider.azure_client.update_network_tags(
  310. 1322 1 31343171.0 31343171.0 74.0 az_network.id, az_network)
  311. Total time: 35.753 s
  312. Function: create at line 1283
  313. Line # Hits Time Per Hit % Time Line Contents
  314. ==============================================================
  315. 1283 @dispatch(event="provider.networking.subnets.create",
  316. 1284 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  317. 1285 @profile
  318. 1286 def create(self, label, network, cidr_block, zone):
  319. 1287 1 9.0 9.0 0.0 AzureSubnet.assert_valid_resource_label(label)
  320. 1288 # Although Subnet doesn't support tags in Azure, we use the parent
  321. 1289 # Network's tags to track its subnets' labels
  322. 1290 1 49.0 49.0 0.0 subnet_name = AzureSubnet._generate_name_from_label(label, "cb-sn")
  323. 1291
  324. 1292 network_id = network.id \
  325. 1293 1 3.0 3.0 0.0 if isinstance(network, Network) else network
  326. 1294
  327. 1295 1 6.0 6.0 0.0 subnet_info = self.provider.azure_client\
  328. 1296 .create_subnet(
  329. 1297 1 1.0 1.0 0.0 network_id,
  330. 1298 1 1.0 1.0 0.0 subnet_name,
  331. 1299 {
  332. 1300 1 3961283.0 3961283.0 11.1 'address_prefix': cidr_block
  333. 1301 }
  334. 1302 )
  335. 1303
  336. 1304 1 19.0 19.0 0.0 subnet = AzureSubnet(self.provider, subnet_info)
  337. 1305 1 31791675.0 31791675.0 88.9 subnet.label = label
  338. 1306 1 1.0 1.0 0.0 return subnet
  339. Total time: 34.0238 s
  340. Function: delete at line 461
  341. Line # Hits Time Per Hit % Time Line Contents
  342. ==============================================================
  343. 461 @dispatch(event="provider.storage.volumes.delete",
  344. 462 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  345. 463 @profile
  346. 464 def delete(self, volume_id):
  347. 465 1 5.0 5.0 0.0 vol_id = (volume_id.id if isinstance(volume_id, AzureVolume)
  348. 466 else volume_id)
  349. 467 1 34023747.0 34023747.0 100.0 self.provider.azure_client.delete_disk(vol_id)
  350. Total time: 32.9634 s
  351. Function: create at line 413
  352. Line # Hits Time Per Hit % Time Line Contents
  353. ==============================================================
  354. 413 @dispatch(event="provider.storage.volumes.create",
  355. 414 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  356. 415 @profile
  357. 416 def create(self, label, size, zone, snapshot=None, description=None):
  358. 417 1 11.0 11.0 0.0 AzureVolume.assert_valid_resource_label(label)
  359. 418 1 37.0 37.0 0.0 disk_name = AzureVolume._generate_name_from_label(label, "cb-vol")
  360. 419 1 2.0 2.0 0.0 tags = {'Label': label}
  361. 420
  362. 421 1 2.0 2.0 0.0 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  363. 422 snapshot = (self.provider.storage.snapshots.get(snapshot)
  364. 423 1 0.0 0.0 0.0 if snapshot and isinstance(snapshot, str) else snapshot)
  365. 424
  366. 425 1 1.0 1.0 0.0 if description:
  367. 426 tags.update(Description=description)
  368. 427
  369. 428 1 1.0 1.0 0.0 if snapshot:
  370. 429 params = {
  371. 430 'location':
  372. 431 zone_id or self.provider.azure_client.region_name,
  373. 432 'creation_data': {
  374. 433 'create_option': DiskCreateOption.copy,
  375. 434 'source_uri': snapshot.resource_id
  376. 435 },
  377. 436 'tags': tags
  378. 437 }
  379. 438
  380. 439 disk = self.provider.azure_client.create_snapshot_disk(disk_name,
  381. 440 params)
  382. 441
  383. 442 else:
  384. 443 params = {
  385. 444 'location':
  386. 445 1 1.0 1.0 0.0 zone_id or self.provider.region_name,
  387. 446 1 1.0 1.0 0.0 'disk_size_gb': size,
  388. 447 'creation_data': {
  389. 448 1 2.0 2.0 0.0 'create_option': DiskCreateOption.empty
  390. 449 },
  391. 450 1 1.0 1.0 0.0 'tags': tags
  392. 451 }
  393. 452
  394. 453 1 524645.0 524645.0 1.6 disk = self.provider.azure_client.create_empty_disk(disk_name,
  395. 454 1 32240191.0 32240191.0 97.8 params)
  396. 455
  397. 456 1 198406.0 198406.0 0.6 azure_vol = self.provider.azure_client.get_disk(disk.id)
  398. 457 1 61.0 61.0 0.0 cb_vol = AzureVolume(self.provider, azure_vol)
  399. 458
  400. 459 1 1.0 1.0 0.0 return cb_vol
  401. Total time: 31.7917 s
  402. Function: label at line 957
  403. Line # Hits Time Per Hit % Time Line Contents
  404. ==============================================================
  405. 957 @label.setter
  406. 958 # pylint:disable=arguments-differ
  407. 959 @profile
  408. 960 def label(self, value):
  409. 961 1 9.0 9.0 0.0 self.assert_valid_resource_label(value)
  410. 962 1 279318.0 279318.0 0.9 network = self.network
  411. 963 # pylint:disable=protected-access
  412. 964 1 0.0 0.0 0.0 az_network = network._network
  413. 965 1 7.0 7.0 0.0 kwargs = {self.tag_name: value or ""}
  414. 966 1 2.0 2.0 0.0 az_network.tags.update(**kwargs)
  415. 967 1 6.0 6.0 0.0 self._provider.azure_client.update_network_tags(
  416. 968 1 31512310.0 31512310.0 99.1 az_network.id, az_network)
  417. Total time: 25.2464 s
  418. Function: delete at line 159
  419. Line # Hits Time Per Hit % Time Line Contents
  420. ==============================================================
  421. 159 @dispatch(event="provider.security.vm_firewalls.delete",
  422. 160 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  423. 161 @profile
  424. 162 def delete(self, vm_firewall):
  425. 163 2 12.0 6.0 0.0 fw_id = (vm_firewall.id if isinstance(vm_firewall, AzureVMFirewall)
  426. 164 else vm_firewall)
  427. 165 2 25246418.0 12623209.0 100.0 self.provider.azure_client.delete_vm_firewall(fw_id)
  428. Total time: 11.6034 s
  429. Function: create at line 1369
  430. Line # Hits Time Per Hit % Time Line Contents
  431. ==============================================================
  432. 1369 @dispatch(event="provider.networking.routers.create",
  433. 1370 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  434. 1371 @profile
  435. 1372 def create(self, label, network):
  436. 1373 1 60.0 60.0 0.0 router_name = AzureRouter._generate_name_from_label(label, "cb-router")
  437. 1374
  438. 1375 1 6.0 6.0 0.0 parameters = {"location": self.provider.region_name,
  439. 1376 1 2.0 2.0 0.0 "tags": {'Label': label}}
  440. 1377
  441. 1378 1 14.0 14.0 0.0 route = self.provider.azure_client. \
  442. 1379 1 11603289.0 11603289.0 100.0 create_route_table(router_name, parameters)
  443. 1380 1 19.0 19.0 0.0 return AzureRouter(self.provider, route)
  444. Total time: 10.7982 s
  445. Function: delete at line 1382
  446. Line # Hits Time Per Hit % Time Line Contents
  447. ==============================================================
  448. 1382 @dispatch(event="provider.networking.routers.delete",
  449. 1383 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  450. 1384 @profile
  451. 1385 def delete(self, router):
  452. 1386 1 3.0 3.0 0.0 r = router if isinstance(router, AzureRouter) else self.get(router)
  453. 1387 1 1.0 1.0 0.0 if r:
  454. 1388 1 10798151.0 10798151.0 100.0 self.provider.azure_client.delete_route_table(r.name)
  455. Total time: 10.7652 s
  456. Function: delete at line 1468
  457. Line # Hits Time Per Hit % Time Line Contents
  458. ==============================================================
  459. 1468 @dispatch(event="provider.networking.floating_ips.delete",
  460. 1469 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  461. 1470 @profile
  462. 1471 def delete(self, gateway, fip):
  463. 1472 1 3.0 3.0 0.0 fip_id = fip.id if isinstance(fip, AzureFloatingIP) else fip
  464. 1473 1 10765237.0 10765237.0 100.0 self.provider.azure_client.delete_floating_ip(fip_id)
  465. Total time: 7.94915 s
  466. Function: create at line 306
  467. Line # Hits Time Per Hit % Time Line Contents
  468. ==============================================================
  469. 306 @dispatch(event="provider.security.key_pairs.create",
  470. 307 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  471. 308 @profile
  472. 309 def create(self, name, public_key_material=None):
  473. 310 3 28.0 9.3 0.0 AzureKeyPair.assert_valid_resource_name(name)
  474. 311 3 6710353.0 2236784.3 84.4 key_pair = self.get(name)
  475. 312
  476. 313 3 3.0 1.0 0.0 if key_pair:
  477. 314 raise DuplicateResourceException(
  478. 315 'Keypair already exists with name {0}'.format(name))
  479. 316
  480. 317 3 2.0 0.7 0.0 private_key = None
  481. 318 3 3.0 1.0 0.0 if not public_key_material:
  482. 319 3 183927.0 61309.0 2.3 public_key_material, private_key = cb_helpers.generate_key_pair()
  483. 320
  484. 321 entity = {
  485. 322 3 8.0 2.7 0.0 'PartitionKey': AzureKeyPairService.PARTITION_KEY,
  486. 323 3 103.0 34.3 0.0 'RowKey': str(uuid.uuid4()),
  487. 324 3 3.0 1.0 0.0 'Name': name,
  488. 325 3 2.0 0.7 0.0 'Key': public_key_material
  489. 326 }
  490. 327
  491. 328 3 387851.0 129283.7 4.9 self.provider.azure_client.create_public_key(entity)
  492. 329 3 666858.0 222286.0 8.4 key_pair = self.get(name)
  493. 330 3 7.0 2.3 0.0 key_pair.material = private_key
  494. 331 3 2.0 0.7 0.0 return key_pair
  495. Total time: 7.34557 s
  496. Function: get at line 259
  497. Line # Hits Time Per Hit % Time Line Contents
  498. ==============================================================
  499. 259 @dispatch(event="provider.security.key_pairs.get",
  500. 260 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  501. 261 @profile
  502. 262 def get(self, key_pair_id):
  503. 263 6 6.0 1.0 0.0 try:
  504. 264 6 47.0 7.8 0.0 key_pair = self.provider.azure_client.\
  505. 265 6 7345454.0 1224242.3 100.0 get_public_key(key_pair_id)
  506. 266
  507. 267 6 11.0 1.8 0.0 if key_pair:
  508. 268 3 50.0 16.7 0.0 return AzureKeyPair(self.provider, key_pair)
  509. 269 3 2.0 0.7 0.0 return None
  510. 270 except AzureException as error:
  511. 271 log.debug("KeyPair %s was not found.", key_pair_id)
  512. 272 log.debug(error)
  513. 273 return None
  514. Total time: 6.71618 s
  515. Function: refresh at line 1340
  516. Line # Hits Time Per Hit % Time Line Contents
  517. ==============================================================
  518. 1340 @profile
  519. 1341 def refresh(self):
  520. 1342 """
  521. 1343 Refreshes the state of this instance by re-querying the cloud provider
  522. 1344 for its latest state.
  523. 1345 """
  524. 1346 17 35.0 2.1 0.0 try:
  525. 1347 17 6715501.0 395029.5 100.0 self._vm = self._provider.azure_client.get_vm(self.id)
  526. 1348 13 28.0 2.2 0.0 if not self._vm.tags:
  527. 1349 self._vm.tags = {}
  528. 1350 13 75.0 5.8 0.0 self._update_state()
  529. 1351 4 12.0 3.0 0.0 except (CloudError, ValueError) as cloud_error:
  530. 1352 4 517.0 129.2 0.0 log.exception(cloud_error.message)
  531. 1353 # The volume no longer exists and cannot be refreshed.
  532. 1354 # set the state to unknown
  533. 1355 4 8.0 2.0 0.0 self._state = 'unknown'
  534. Total time: 5.08459 s
  535. Function: create at line 1452
  536. Line # Hits Time Per Hit % Time Line Contents
  537. ==============================================================
  538. 1452 @dispatch(event="provider.networking.floating_ips.create",
  539. 1453 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  540. 1454 @profile
  541. 1455 def create(self, gateway):
  542. 1456 public_ip_parameters = {
  543. 1457 1 9.0 9.0 0.0 'location': self.provider.azure_client.region_name,
  544. 1458 1 1.0 1.0 0.0 'public_ip_allocation_method': 'Static'
  545. 1459 }
  546. 1460
  547. 1461 1 2.0 2.0 0.0 public_ip_name = AzureFloatingIP._generate_name_from_label(
  548. 1462 1 47.0 47.0 0.0 None, 'cb-fip-')
  549. 1463
  550. 1464 1 4.0 4.0 0.0 floating_ip = self.provider.azure_client.\
  551. 1465 1 5084513.0 5084513.0 100.0 create_floating_ip(public_ip_name, public_ip_parameters)
  552. 1466 1 18.0 18.0 0.0 return AzureFloatingIP(self.provider, floating_ip)
  553. Total time: 4.99243 s
  554. Function: create at line 1189
  555. Line # Hits Time Per Hit % Time Line Contents
  556. ==============================================================
  557. 1189 @dispatch(event="provider.networking.networks.create",
  558. 1190 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  559. 1191 @profile
  560. 1192 def create(self, label, cidr_block):
  561. 1193 1 10.0 10.0 0.0 AzureNetwork.assert_valid_resource_label(label)
  562. 1194 params = {
  563. 1195 1 339834.0 339834.0 6.8 'location': self.provider.azure_client.region_name,
  564. 1196 'address_space': {
  565. 1197 1 2.0 2.0 0.0 'address_prefixes': [cidr_block]
  566. 1198 },
  567. 1199 1 1.0 1.0 0.0 'tags': {'Label': label}
  568. 1200 }
  569. 1201
  570. 1202 1 61.0 61.0 0.0 network_name = AzureNetwork._generate_name_from_label(label, 'cb-net')
  571. 1203
  572. 1204 1 10.0 10.0 0.0 az_network = self.provider.azure_client.create_network(network_name,
  573. 1205 1 4652478.0 4652478.0 93.2 params)
  574. 1206 1 37.0 37.0 0.0 cb_network = AzureNetwork(self.provider, az_network)
  575. 1207 1 1.0 1.0 0.0 return cb_network
  576. Total time: 4.71943 s
  577. Function: list at line 1095
  578. Line # Hits Time Per Hit % Time Line Contents
  579. ==============================================================
  580. 1095 @dispatch(event="provider.compute.vm_types.list",
  581. 1096 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  582. 1097 @profile
  583. 1098 def list(self, limit=None, marker=None):
  584. 1099 5 9.0 1.8 0.0 vm_types = [AzureVMType(self.provider, vm_type)
  585. 1100 5 4719066.0 943813.2 100.0 for vm_type in self.instance_data]
  586. 1101 5 44.0 8.8 0.0 return ClientPagedResultList(self.provider, vm_types,
  587. 1102 5 314.0 62.8 0.0 limit=limit, marker=marker)
  588. Total time: 4.52462 s
  589. Function: find at line 225
  590. Line # Hits Time Per Hit % Time Line Contents
  591. ==============================================================
  592. 225 @dispatch(event="provider.compute.vm_types.find",
  593. 226 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  594. 227 @profile
  595. 228 def find(self, **kwargs):
  596. 229 4 4.0 1.0 0.0 obj_list = self
  597. 230 4 3.0 0.8 0.0 filters = ['name']
  598. 231 4 4524522.0 1131130.5 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  599. 232 4 90.0 22.5 0.0 return ClientPagedResultList(self._provider, list(matches))
  600. Total time: 3.44313 s
  601. Function: get_or_create_default at line 320
  602. Line # Hits Time Per Hit % Time Line Contents
  603. ==============================================================
  604. 320 @profile
  605. 321 def get_or_create_default(self, zone):
  606. 322 # Look for a CB-default subnet
  607. 323 2 3443125.0 1721562.5 100.0 matches = self.find(label=BaseSubnet.CB_DEFAULT_SUBNET_LABEL)
  608. 324 2 2.0 1.0 0.0 if matches:
  609. 325 2 3.0 1.5 0.0 return matches[0]
  610. 326
  611. 327 # No provider-default Subnet exists, try to create it (net + subnets)
  612. 328 network = self.provider.networking.networks.get_or_create_default()
  613. 329 subnet = self.create(BaseSubnet.CB_DEFAULT_SUBNET_LABEL, network,
  614. 330 BaseSubnet.CB_DEFAULT_SUBNET_IPV4RANGE, zone)
  615. 331 return subnet
  616. Total time: 3.42406 s
  617. Function: find at line 1272
  618. Line # Hits Time Per Hit % Time Line Contents
  619. ==============================================================
  620. 1272 @dispatch(event="provider.networking.subnets.find",
  621. 1273 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  622. 1274 @profile
  623. 1275 def find(self, network=None, **kwargs):
  624. 1276 2 2109626.0 1054813.0 61.6 obj_list = self._list_subnets(network)
  625. 1277 2 4.0 2.0 0.0 filters = ['label']
  626. 1278 2 1314359.0 657179.5 38.4 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  627. 1279
  628. 1280 2 6.0 3.0 0.0 return ClientPagedResultList(self.provider,
  629. 1281 2 64.0 32.0 0.0 matches if matches else [])
  630. Total time: 2.6431 s
  631. Function: get at line 1168
  632. Line # Hits Time Per Hit % Time Line Contents
  633. ==============================================================
  634. 1168 @dispatch(event="provider.networking.networks.get",
  635. 1169 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  636. 1170 @profile
  637. 1171 def get(self, network_id):
  638. 1172 9 11.0 1.2 0.0 try:
  639. 1173 9 2642843.0 293649.2 100.0 network = self.provider.azure_client.get_network(network_id)
  640. 1174 9 251.0 27.9 0.0 return AzureNetwork(self.provider, network)
  641. 1175 except (CloudError, InvalidValueException) as cloud_error:
  642. 1176 # Azure raises the cloud error if the resource not available
  643. 1177 log.exception(cloud_error)
  644. 1178 return None
  645. Total time: 2.64084 s
  646. Function: list at line 999
  647. Line # Hits Time Per Hit % Time Line Contents
  648. ==============================================================
  649. 999 @dispatch(event="provider.compute.instances.list",
  650. 1000 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  651. 1001 @profile
  652. 1002 def list(self, limit=None, marker=None):
  653. 1003 """
  654. 1004 List all instances.
  655. 1005 """
  656. 1006 5 7.0 1.4 0.0 instances = [AzureInstance(self.provider, inst)
  657. 1007 5 2640620.0 528124.0 100.0 for inst in self.provider.azure_client.list_vm()]
  658. 1008 5 26.0 5.2 0.0 return ClientPagedResultList(self.provider, instances,
  659. 1009 5 182.0 36.4 0.0 limit=limit, marker=marker)
  660. Total time: 1.56939 s
  661. Function: list at line 1180
  662. Line # Hits Time Per Hit % Time Line Contents
  663. ==============================================================
  664. 1180 @dispatch(event="provider.networking.networks.list",
  665. 1181 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  666. 1182 @profile
  667. 1183 def list(self, limit=None, marker=None):
  668. 1184 2 31.0 15.5 0.0 networks = [AzureNetwork(self.provider, network)
  669. 1185 2 1569280.0 784640.0 100.0 for network in self.provider.azure_client.list_networks()]
  670. 1186 2 6.0 3.0 0.0 return ClientPagedResultList(self.provider, networks,
  671. 1187 2 70.0 35.0 0.0 limit=limit, marker=marker)
  672. Total time: 1.03678 s
  673. Function: find at line 1027
  674. Line # Hits Time Per Hit % Time Line Contents
  675. ==============================================================
  676. 1027 @dispatch(event="provider.compute.instances.find",
  677. 1028 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  678. 1029 @profile
  679. 1030 def find(self, **kwargs):
  680. 1031 3 3.0 1.0 0.0 obj_list = self
  681. 1032 3 3.0 1.0 0.0 filters = ['label']
  682. 1033 3 1036722.0 345574.0 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  683. 1034
  684. 1035 # All kwargs should have been popped at this time.
  685. 1036 2 3.0 1.5 0.0 if len(kwargs) > 0:
  686. 1037 raise InvalidParamException(
  687. 1038 "Unrecognised parameters for search: %s. Supported "
  688. 1039 "attributes: %s" % (kwargs, ", ".join(filters)))
  689. 1040
  690. 1041 2 4.0 2.0 0.0 return ClientPagedResultList(self.provider,
  691. 1042 2 46.0 23.0 0.0 matches if matches else [])
  692. Total time: 0.961534 s
  693. Function: get at line 93
  694. Line # Hits Time Per Hit % Time Line Contents
  695. ==============================================================
  696. 93 @dispatch(event="provider.security.vm_firewalls.get",
  697. 94 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  698. 95 @profile
  699. 96 def get(self, vm_firewall_id):
  700. 97 4 7.0 1.8 0.0 try:
  701. 98 4 961436.0 240359.0 100.0 fws = self.provider.azure_client.get_vm_firewall(vm_firewall_id)
  702. 99 4 91.0 22.8 0.0 return AzureVMFirewall(self.provider, fws)
  703. 100 except (CloudError, InvalidValueException) as cloud_error:
  704. 101 # Azure raises the cloud error if the resource not available
  705. 102 log.exception(cloud_error)
  706. 103 return None
  707. Total time: 0.768687 s
  708. Function: get at line 1011
  709. Line # Hits Time Per Hit % Time Line Contents
  710. ==============================================================
  711. 1011 @dispatch(event="provider.compute.instances.get",
  712. 1012 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  713. 1013 @profile
  714. 1014 def get(self, instance_id):
  715. 1015 """
  716. 1016 Returns an instance given its id. Returns None
  717. 1017 if the object does not exist.
  718. 1018 """
  719. 1019 3 2.0 0.7 0.0 try:
  720. 1020 3 768308.0 256102.7 100.0 vm = self.provider.azure_client.get_vm(instance_id)
  721. 1021 1 18.0 18.0 0.0 return AzureInstance(self.provider, vm)
  722. 1022 2 7.0 3.5 0.0 except (CloudError, InvalidValueException) as cloud_error:
  723. 1023 # Azure raises the cloud error if the resource not available
  724. 1024 2 349.0 174.5 0.0 log.exception(cloud_error)
  725. 1025 2 3.0 1.5 0.0 return None
  726. Total time: 0.703833 s
  727. Function: delete at line 333
  728. Line # Hits Time Per Hit % Time Line Contents
  729. ==============================================================
  730. 333 @dispatch(event="provider.security.key_pairs.delete",
  731. 334 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  732. 335 @profile
  733. 336 def delete(self, key_pair):
  734. 337 3 9.0 3.0 0.0 key_pair = (key_pair if isinstance(key_pair, AzureKeyPair) else
  735. 338 self.get(key_pair))
  736. 339 3 4.0 1.3 0.0 if key_pair:
  737. 340 # pylint:disable=protected-access
  738. 341 3 703820.0 234606.7 100.0 self.provider.azure_client.delete_public_key(key_pair._key_pair)
  739. Total time: 0.618865 s
  740. Function: get at line 1109
  741. Line # Hits Time Per Hit % Time Line Contents
  742. ==============================================================
  743. 1109 @dispatch(event="provider.compute.regions.get",
  744. 1110 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  745. 1111 @profile
  746. 1112 def get(self, region_id):
  747. 1113 4 4.0 1.0 0.0 region = None
  748. 1114 12 618660.0 51555.0 100.0 for azureRegion in self.provider.azure_client.list_locations():
  749. 1115 12 14.0 1.2 0.0 if azureRegion.name == region_id:
  750. 1116 4 63.0 15.8 0.0 region = AzureRegion(self.provider, azureRegion)
  751. 1117 4 122.0 30.5 0.0 break
  752. 1118 4 2.0 0.5 0.0 return region
  753. Total time: 0.594712 s
  754. Function: create at line 512
  755. Line # Hits Time Per Hit % Time Line Contents
  756. ==============================================================
  757. 512 @dispatch(event="provider.storage.snapshots.create",
  758. 513 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  759. 514 @profile
  760. 515 def create(self, label, volume, description=None):
  761. 516 1 20.0 20.0 0.0 AzureSnapshot.assert_valid_resource_label(label)
  762. 517 1 2.0 2.0 0.0 snapshot_name = AzureSnapshot._generate_name_from_label(label,
  763. 518 1 51.0 51.0 0.0 "cb-snap")
  764. 519 1 1.0 1.0 0.0 tags = {'Label': label}
  765. 520 1 1.0 1.0 0.0 if description:
  766. 521 1 4.0 4.0 0.0 tags.update(Description=description)
  767. 522
  768. 523 volume = (self.provider.storage.volumes.get(volume)
  769. 524 1 3.0 3.0 0.0 if isinstance(volume, str) else volume)
  770. 525
  771. 526 params = {
  772. 527 1 11.0 11.0 0.0 'location': self.provider.azure_client.region_name,
  773. 528 'creation_data': {
  774. 529 1 3.0 3.0 0.0 'create_option': DiskCreateOption.copy,
  775. 530 1 8.0 8.0 0.0 'source_uri': volume.resource_id
  776. 531 },
  777. 532 1 1.0 1.0 0.0 'disk_size_gb': volume.size,
  778. 533 1 1.0 1.0 0.0 'tags': tags
  779. 534 }
  780. 535
  781. 536 1 3.0 3.0 0.0 azure_snap = self.provider.azure_client.create_snapshot(snapshot_name,
  782. 537 1 594603.0 594603.0 100.0 params)
  783. 538 return AzureSnapshot(self.provider, azure_snap)
  784. Total time: 0.57252 s
  785. Function: refresh at line 1474
  786. Line # Hits Time Per Hit % Time Line Contents
  787. ==============================================================
  788. 1474 @profile
  789. 1475 def refresh(self):
  790. 1476 2 21.0 10.5 0.0 self._route_table = self._provider.azure_client. \
  791. 1477 2 572499.0 286249.5 100.0 get_route_table(self._route_table.name)
  792. Total time: 0.53395 s
  793. Function: refresh at line 852
  794. Line # Hits Time Per Hit % Time Line Contents
  795. ==============================================================
  796. 852 @profile
  797. 853 def refresh(self):
  798. 854 # Gateway is not needed as it doesn't exist in Azure, so just
  799. 855 # getting the Floating IP again from the client
  800. 856 # pylint:disable=protected-access
  801. 857 2 533944.0 266972.0 100.0 fip = self._provider.networking._floating_ips.get(None, self.id)
  802. 858 # pylint:disable=protected-access
  803. 859 2 6.0 3.0 0.0 self._ip = fip._ip
  804. Total time: 0.522689 s
  805. Function: get at line 1430
  806. Line # Hits Time Per Hit % Time Line Contents
  807. ==============================================================
  808. 1430 @dispatch(event="provider.networking.floating_ips.get",
  809. 1431 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  810. 1432 @profile
  811. 1433 def get(self, gateway, fip_id):
  812. 1434 2 2.0 1.0 0.0 try:
  813. 1435 2 522540.0 261270.0 100.0 az_ip = self.provider.azure_client.get_floating_ip(fip_id)
  814. 1436 1 3.0 3.0 0.0 except (CloudError, InvalidValueException) as cloud_error:
  815. 1437 # Azure raises the cloud error if the resource not available
  816. 1438 1 130.0 130.0 0.0 log.exception(cloud_error)
  817. 1439 1 1.0 1.0 0.0 return None
  818. 1440 1 13.0 13.0 0.0 return AzureFloatingIP(self.provider, az_ip)
  819. Total time: 0.378508 s
  820. Function: get at line 677
  821. Line # Hits Time Per Hit % Time Line Contents
  822. ==============================================================
  823. 677 @profile
  824. 678 def get(self, image_id):
  825. 679 """
  826. 680 Returns an Image given its id
  827. 681 """
  828. 682 4 2.0 0.5 0.0 try:
  829. 683 4 378438.0 94609.5 100.0 image = self.provider.azure_client.get_image(image_id)
  830. 684 4 68.0 17.0 0.0 return AzureMachineImage(self.provider, image)
  831. 685 except (CloudError, InvalidValueException) as cloud_error:
  832. 686 # Azure raises the cloud error if the resource not available
  833. 687 log.exception(cloud_error)
  834. 688 return None
  835. Total time: 0.325217 s
  836. Function: refresh at line 782
  837. Line # Hits Time Per Hit % Time Line Contents
  838. ==============================================================
  839. 782 @profile
  840. 783 def refresh(self):
  841. 784 """
  842. 785 Refreshes the state of this network by re-querying the cloud provider
  843. 786 for its latest state.
  844. 787 """
  845. 788 1 3.0 3.0 0.0 try:
  846. 789 1 10.0 10.0 0.0 self._network = self._provider.azure_client.\
  847. 790 1 325080.0 325080.0 100.0 get_network(self.id)
  848. 791 self._state = self._network.provisioning_state
  849. 792 1 2.0 2.0 0.0 except (CloudError, ValueError) as cloud_error:
  850. 793 1 118.0 118.0 0.0 log.exception(cloud_error.message)
  851. 794 # The network no longer exists and cannot be refreshed.
  852. 795 # set the state to unknown
  853. 796 1 4.0 4.0 0.0 self._state = 'unknown'
  854. Total time: 0.251713 s
  855. Function: refresh at line 999
  856. Line # Hits Time Per Hit % Time Line Contents
  857. ==============================================================
  858. 999 @profile
  859. 1000 def refresh(self):
  860. 1001 """
  861. 1002 Refreshes the state of this network by re-querying the cloud provider
  862. 1003 for its latest state.
  863. 1004 """
  864. 1005 1 5.0 5.0 0.0 try:
  865. 1006 1 14.0 14.0 0.0 self._subnet = self._provider.azure_client. \
  866. 1007 1 251559.0 251559.0 99.9 get_subnet(self.id)
  867. 1008 self._state = self._subnet.provisioning_state
  868. 1009 1 3.0 3.0 0.0 except (CloudError, ValueError) as cloud_error:
  869. 1010 1 130.0 130.0 0.1 log.exception(cloud_error.message)
  870. 1011 # The subnet no longer exists and cannot be refreshed.
  871. 1012 # set the state to unknown
  872. 1013 1 2.0 2.0 0.0 self._state = 'unknown'
  873. Total time: 0.231875 s
  874. Function: get at line 218
  875. Line # Hits Time Per Hit % Time Line Contents
  876. ==============================================================
  877. 218 @dispatch(event="provider.compute.vm_types.get",
  878. 219 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  879. 220 @profile
  880. 221 def get(self, vm_type_id):
  881. 222 1 5.0 5.0 0.0 vm_type = (t for t in self if t.id == vm_type_id)
  882. 223 1 231870.0 231870.0 100.0 return next(vm_type, None)
  883. Total time: 0.199181 s
  884. Function: list at line 1264
  885. Line # Hits Time Per Hit % Time Line Contents
  886. ==============================================================
  887. 1264 @dispatch(event="provider.networking.subnets.list",
  888. 1265 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  889. 1266 @profile
  890. 1267 def list(self, network=None, limit=None, marker=None):
  891. 1268 1 7.0 7.0 0.0 return ClientPagedResultList(self.provider,
  892. 1269 1 199134.0 199134.0 100.0 self._list_subnets(network),
  893. 1270 1 40.0 40.0 0.0 limit=limit, marker=marker)
  894. Total time: 0.000324 s
  895. Function: list at line 173
  896. Line # Hits Time Per Hit % Time Line Contents
  897. ==============================================================
  898. 173 @dispatch(event="provider.security.vm_firewall_rules.list",
  899. 174 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  900. 175 @profile
  901. 176 def list(self, firewall, limit=None, marker=None):
  902. 177 # Filter out firewall rules with priority < 3500 because values
  903. 178 # between 3500 and 4096 are assumed to be owned by cloudbridge
  904. 179 # default rules.
  905. 180 # pylint:disable=protected-access
  906. 181 4 5.0 1.2 1.5 rules = [AzureVMFirewallRule(firewall, rule) for rule
  907. 182 4 196.0 49.0 60.5 in firewall._vm_firewall.security_rules
  908. 183 if rule.priority < 3500]
  909. 184 4 11.0 2.8 3.4 return ClientPagedResultList(self.provider, rules,
  910. 185 4 112.0 28.0 34.6 limit=limit, marker=marker)
  911. Total time: 3.6e-05 s
  912. Function: get_or_create at line 1403
  913. Line # Hits Time Per Hit % Time Line Contents
  914. ==============================================================
  915. 1403 @dispatch(event="provider.networking.gateways.get_or_create",
  916. 1404 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  917. 1405 @profile
  918. 1406 def get_or_create(self, network):
  919. 1407 1 36.0 36.0 100.0 return self._gateway_singleton(network)
  920. Total time: 1.7e-05 s
  921. Function: create_launch_config at line 859
  922. Line # Hits Time Per Hit % Time Line Contents
  923. ==============================================================
  924. 859 @profile
  925. 860 def create_launch_config(self):
  926. 861 1 17.0 17.0 100.0 return AzureLaunchConfig(self.provider)