filtered-gcp-image.res 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. cloudbridge.test.test_image_service.CloudImageServiceTestCase
  2. Test output
  3. ..
  4. ----------------------------------------------------------------------
  5. Ran 2 tests in 696.940s
  6. OK
  7. Wrote profile results to run_single.py.lprof
  8. Timer unit: 1e-06 s
  9. Total time: 170.308 s
  10. Function: get at line 642
  11. Line # Hits Time Per Hit % Time Line Contents
  12. ==============================================================
  13. 642 @dispatch(event="provider.compute.instances.get",
  14. 643 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  15. 644 @profile
  16. 645 def get(self, instance_id):
  17. 646 """
  18. 647 Returns an instance given its name. Returns None
  19. 648 if the object does not exist.
  20. 649
  21. 650 A GCP instance is uniquely identified by its selfLink, which is used
  22. 651 as its id.
  23. 652 """
  24. 653 223 170303125.0 763691.1 100.0 instance = self.provider.get_resource('instances', instance_id)
  25. 654 223 4754.0 21.3 0.0 return GCPInstance(self.provider, instance) if instance else None
  26. Total time: 169.705 s
  27. Function: refresh at line 1237
  28. Line # Hits Time Per Hit % Time Line Contents
  29. ==============================================================
  30. 1237 @profile
  31. 1238 def refresh(self):
  32. 1239 """
  33. 1240 Refreshes the state of this instance by re-querying the cloud provider
  34. 1241 for its latest state.
  35. 1242 """
  36. 1243 221 169702381.0 767884.1 100.0 inst = self._provider.compute.instances.get(self.id)
  37. 1244 221 280.0 1.3 0.0 if inst:
  38. 1245 # pylint:disable=protected-access
  39. 1246 219 1973.0 9.0 0.0 self._gcp_instance = inst._gcp_instance
  40. 1247 else:
  41. 1248 # instance no longer exists
  42. 1249 2 6.0 3.0 0.0 self._gcp_instance['status'] = InstanceState.UNKNOWN
  43. Total time: 101.152 s
  44. Function: create at line 490
  45. Line # Hits Time Per Hit % Time Line Contents
  46. ==============================================================
  47. 490 @dispatch(event="provider.compute.instances.create",
  48. 491 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  49. 492 @profile
  50. 493 def create(self, label, image, vm_type, subnet, zone=None,
  51. 494 key_pair=None, vm_firewalls=None, user_data=None,
  52. 495 launch_config=None, **kwargs):
  53. 496 """
  54. 497 Creates a new virtual machine instance.
  55. 498 """
  56. 499 2 23.0 11.5 0.0 GCPInstance.assert_valid_resource_name(label)
  57. 500 2 9.0 4.5 0.0 zone_name = self.provider.default_zone
  58. 501 2 4.0 2.0 0.0 if zone:
  59. 502 2 6.0 3.0 0.0 if not isinstance(zone, GCPPlacementZone):
  60. 503 2 4.0 2.0 0.0 zone = GCPPlacementZone(
  61. 504 2 5.0 2.5 0.0 self.provider,
  62. 505 2 311408.0 155704.0 0.3 self.provider.get_resource('zones', zone))
  63. 506 2 25.0 12.5 0.0 zone_name = zone.name
  64. 507 2 11.0 5.5 0.0 if not isinstance(vm_type, GCPVMType):
  65. 508 2 321874.0 160937.0 0.3 vm_type = self.provider.compute.vm_types.get(vm_type)
  66. 509
  67. 510 2 6.0 3.0 0.0 network_interface = {'accessConfigs': [{'type': 'ONE_TO_ONE_NAT',
  68. 511 2 8.0 4.0 0.0 'name': 'External NAT'}]}
  69. 512 2 7.0 3.5 0.0 if subnet:
  70. 513 2 11.0 5.5 0.0 network_interface['subnetwork'] = subnet.id
  71. 514 else:
  72. 515 network_interface['network'] = 'global/networks/default'
  73. 516
  74. 517 2 6.0 3.0 0.0 num_roots = 0
  75. 518 2 5.0 2.5 0.0 disks = []
  76. 519 2 6.0 3.0 0.0 boot_disk = None
  77. 520 2 9.0 4.5 0.0 if isinstance(launch_config, GCPLaunchConfig):
  78. 521 for disk in launch_config.block_devices:
  79. 522 if not disk.source:
  80. 523 volume_name = 'disk-{0}'.format(uuid.uuid4())
  81. 524 volume_size = disk.size if disk.size else 1
  82. 525 volume = self.provider.storage.volumes.create(
  83. 526 volume_name, volume_size, zone)
  84. 527 volume.wait_till_ready()
  85. 528 source_field = 'source'
  86. 529 source_value = volume.id
  87. 530 elif isinstance(disk.source, GCPMachineImage):
  88. 531 source_field = 'initializeParams'
  89. 532 # Explicitly set diskName; otherwise, instance label will
  90. 533 # be used by default which may collide with existing disks.
  91. 534 source_value = {
  92. 535 'sourceImage': disk.source.id,
  93. 536 'diskName': 'image-disk-{0}'.format(uuid.uuid4()),
  94. 537 'diskSizeGb': disk.size if disk.size else 20}
  95. 538 elif isinstance(disk.source, GCPVolume):
  96. 539 source_field = 'source'
  97. 540 source_value = disk.source.id
  98. 541 elif isinstance(disk.source, GCPSnapshot):
  99. 542 volume = disk.source.create_volume(zone, size=disk.size)
  100. 543 volume.wait_till_ready()
  101. 544 source_field = 'source'
  102. 545 source_value = volume.id
  103. 546 else:
  104. 547 log.warning('Unknown disk source')
  105. 548 continue
  106. 549 autoDelete = True
  107. 550 if disk.delete_on_terminate is not None:
  108. 551 autoDelete = disk.delete_on_terminate
  109. 552 num_roots += 1 if disk.is_root else 0
  110. 553 if disk.is_root and not boot_disk:
  111. 554 boot_disk = {'boot': True,
  112. 555 'autoDelete': autoDelete,
  113. 556 source_field: source_value}
  114. 557 else:
  115. 558 disks.append({'boot': False,
  116. 559 'autoDelete': autoDelete,
  117. 560 source_field: source_value})
  118. 561
  119. 562 2 7.0 3.5 0.0 if num_roots > 1:
  120. 563 log.warning('The launch config contains %d boot disks. Will '
  121. 564 'use the first one', num_roots)
  122. 565 2 6.0 3.0 0.0 if image:
  123. 566 2 6.0 3.0 0.0 if boot_disk:
  124. 567 log.warning('A boot image is given while the launch config '
  125. 568 'contains a boot disk, too. The launch config '
  126. 569 'will be used.')
  127. 570 else:
  128. 571 2 7.0 3.5 0.0 if not isinstance(image, GCPMachineImage):
  129. 572 1 186959.0 186959.0 0.2 image = self.provider.compute.images.get(image)
  130. 573 # Explicitly set diskName; otherwise, instance name will be
  131. 574 # used by default which may conflict with existing disks.
  132. 575 boot_disk = {
  133. 576 2 6.0 3.0 0.0 'boot': True,
  134. 577 2 6.0 3.0 0.0 'autoDelete': True,
  135. 578 'initializeParams': {
  136. 579 2 13.0 6.5 0.0 'sourceImage': image.id,
  137. 580 2 144.0 72.0 0.0 'diskName': 'image-disk-{0}'.format(uuid.uuid4())}}
  138. 581
  139. 582 2 7.0 3.5 0.0 if not boot_disk:
  140. 583 log.warning('No boot disk is given for instance %s.', label)
  141. 584 return None
  142. 585 # The boot disk must be the first disk attached to the instance.
  143. 586 2 10.0 5.0 0.0 disks.insert(0, boot_disk)
  144. 587
  145. 588 config = {
  146. 589 2 112.0 56.0 0.0 'name': GCPInstance._generate_name_from_label(label, 'cb-inst'),
  147. 590 2 11.0 5.5 0.0 'machineType': vm_type.resource_url,
  148. 591 2 6.0 3.0 0.0 'disks': disks,
  149. 592 2 8.0 4.0 0.0 'networkInterfaces': [network_interface]
  150. 593 }
  151. 594
  152. 595 2 5.0 2.5 0.0 if vm_firewalls and isinstance(vm_firewalls, list):
  153. 596 vm_firewall_names = []
  154. 597 if isinstance(vm_firewalls[0], VMFirewall):
  155. 598 vm_firewall_names = [f.name for f in vm_firewalls]
  156. 599 elif isinstance(vm_firewalls[0], str):
  157. 600 vm_firewall_names = vm_firewalls
  158. 601 if len(vm_firewall_names) > 0:
  159. 602 config['tags'] = {}
  160. 603 config['tags']['items'] = vm_firewall_names
  161. 604
  162. 605 2 5.0 2.5 0.0 if user_data:
  163. 606 entry = {'key': 'user-data', 'value': user_data}
  164. 607 config['metadata'] = {'items': [entry]}
  165. 608
  166. 609 2 6.0 3.0 0.0 if key_pair:
  167. 610 if not isinstance(key_pair, GCPKeyPair):
  168. 611 key_pair = self._provider.security.key_pairs.get(key_pair)
  169. 612 if key_pair:
  170. 613 kp = key_pair._key_pair
  171. 614 kp_entry = {
  172. 615 "key": "ssh-keys",
  173. 616 # Format is not removed from public key portion
  174. 617 "value": "{}:{} {}".format(
  175. 618 self.provider.vm_default_user_name,
  176. 619 kp.public_key,
  177. 620 kp.name)
  178. 621 }
  179. 622 meta = config.get('metadata', {})
  180. 623 if meta:
  181. 624 items = meta.get('items', [])
  182. 625 items.append(kp_entry)
  183. 626 else:
  184. 627 config['metadata'] = {'items': [kp_entry]}
  185. 628
  186. 629 2 7.0 3.5 0.0 config['labels'] = {'cblabel': label}
  187. 630
  188. 631 2 51129.0 25564.5 0.1 operation = (self.provider
  189. 632 .gcp_compute.instances()
  190. 633 2 6.0 3.0 0.0 .insert(project=self.provider.project_name,
  191. 634 2 2.0 1.0 0.0 zone=zone_name,
  192. 635 2 3323984.0 1661992.0 3.3 body=config)
  193. 636 .execute())
  194. 637 2 10.0 5.0 0.0 instance_id = operation.get('targetLink')
  195. 638 2 96292576.0 48146288.0 95.2 self.provider.wait_for_operation(operation, zone=zone_name)
  196. 639 2 663453.0 331726.5 0.7 cb_inst = self.get(instance_id)
  197. 640 2 8.0 4.0 0.0 return cb_inst
  198. Total time: 41.9159 s
  199. Function: list at line 467
  200. Line # Hits Time Per Hit % Time Line Contents
  201. ==============================================================
  202. 467 @profile
  203. 468 def list(self, limit=None, marker=None):
  204. 469 """
  205. 470 List all images.
  206. 471 """
  207. 472 221 1442223.0 6525.9 3.4 self._retrieve_public_images()
  208. 473 221 230.0 1.0 0.0 images = []
  209. 474 221 489.0 2.2 0.0 if (self.provider.project_name not in
  210. 475 221 423.0 1.9 0.0 GCPImageService._PUBLIC_IMAGE_PROJECTS):
  211. 476 221 342.0 1.5 0.0 for image in helpers.iter_all(
  212. 477 221 1629065.0 7371.3 3.9 self.provider.gcp_compute.images(),
  213. 478 441 38641821.0 87623.2 92.2 project=self.provider.project_name):
  214. 479 220 4479.0 20.4 0.0 images.append(GCPMachineImage(self.provider, image))
  215. 480 221 2253.0 10.2 0.0 images.extend(self._public_images)
  216. 481 221 504.0 2.3 0.0 return ClientPagedResultList(self.provider, images,
  217. 482 221 194065.0 878.1 0.5 limit=limit, marker=marker)
  218. Total time: 5.04476 s
  219. Function: list at line 1645
  220. Line # Hits Time Per Hit % Time Line Contents
  221. ==============================================================
  222. 1645 @dispatch(event="provider.networking.floating_ips.list",
  223. 1646 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  224. 1647 @profile
  225. 1648 def list(self, gateway, limit=None, marker=None):
  226. 1649 3 5.0 1.7 0.0 max_result = limit if limit is not None and limit < 500 else 500
  227. 1650 3 13040.0 4346.7 0.3 response = (self.provider
  228. 1651 .gcp_compute
  229. 1652 .addresses()
  230. 1653 3 8.0 2.7 0.0 .list(project=self.provider.project_name,
  231. 1654 3 6.0 2.0 0.0 region=self.provider.region_name,
  232. 1655 3 3.0 1.0 0.0 maxResults=max_result,
  233. 1656 3 1564894.0 521631.3 31.0 pageToken=marker)
  234. 1657 .execute())
  235. 1658 3 12.0 4.0 0.0 ips = [GCPFloatingIP(self.provider, ip)
  236. 1659 3 3466730.0 1155576.7 68.7 for ip in response.get('items', [])]
  237. 1660 3 12.0 4.0 0.0 if len(ips) > max_result:
  238. 1661 log.warning('Expected at most %d results; got %d',
  239. 1662 max_result, len(ips))
  240. 1663 3 6.0 2.0 0.0 return ServerPagedResultList('nextPageToken' in response,
  241. 1664 3 6.0 2.0 0.0 response.get('nextPageToken'),
  242. 1665 3 37.0 12.3 0.0 False, data=ips)
  243. Total time: 4.66685 s
  244. Function: get at line 435
  245. Line # Hits Time Per Hit % Time Line Contents
  246. ==============================================================
  247. 435 @profile
  248. 436 def get(self, image_id):
  249. 437 """
  250. 438 Returns an Image given its id
  251. 439 """
  252. 440 10 4658275.0 465827.5 99.8 image = self.provider.get_resource('images', image_id)
  253. 441 10 24.0 2.4 0.0 if image:
  254. 442 7 140.0 20.0 0.0 return GCPMachineImage(self.provider, image)
  255. 443 3 11.0 3.7 0.0 self._retrieve_public_images()
  256. 444 3237 1745.0 0.5 0.0 for public_image in self._public_images:
  257. 445 3234 6650.0 2.1 0.1 if public_image.id == image_id or public_image.name == image_id:
  258. 446 return public_image
  259. 447 3 1.0 0.3 0.0 return None
  260. Total time: 4.07836 s
  261. Function: refresh at line 761
  262. Line # Hits Time Per Hit % Time Line Contents
  263. ==============================================================
  264. 761 @profile
  265. 762 def refresh(self):
  266. 763 """
  267. 764 Refreshes the state of this instance by re-querying the cloud provider
  268. 765 for its latest state.
  269. 766 """
  270. 767 7 4078322.0 582617.4 100.0 image = self._provider.compute.images.get(self.id)
  271. 768 7 5.0 0.7 0.0 if image:
  272. 769 # pylint:disable=protected-access
  273. 770 5 27.0 5.4 0.0 self._gcp_image = image._gcp_image
  274. 771 else:
  275. 772 # image no longer exists
  276. 773 2 6.0 3.0 0.0 self._gcp_image['status'] = MachineImageState.UNKNOWN
  277. Total time: 3.7366 s
  278. Function: label at line 713
  279. Line # Hits Time Per Hit % Time Line Contents
  280. ==============================================================
  281. 713 @label.setter
  282. 714 # pylint:disable=arguments-differ
  283. 715 @profile
  284. 716 def label(self, value):
  285. 717 11 69594.0 6326.7 1.9 req = (self._provider
  286. 718 .gcp_compute
  287. 719 .images()
  288. 720 11 26.0 2.4 0.0 .setLabels(project=self._provider.project_name,
  289. 721 11 15.0 1.4 0.0 resource=self.name,
  290. 722 11 4744.0 431.3 0.1 body={}))
  291. 723
  292. 724 11 3662222.0 332929.3 98.0 helpers.change_label(self, 'cblabel', value, '_gcp_image', req)
  293. Total time: 3.67662 s
  294. Function: get_or_create_default at line 1098
  295. Line # Hits Time Per Hit % Time Line Contents
  296. ==============================================================
  297. 1098 @profile
  298. 1099 def get_or_create_default(self, zone):
  299. 1100 """
  300. 1101 Return an existing or create a new subnet for the supplied zone.
  301. 1102
  302. 1103 In GCP, subnets are a regional resource so a single subnet can services
  303. 1104 an entire region. The supplied zone parameter is used to derive the
  304. 1105 parent region under which the default subnet then exists.
  305. 1106 """
  306. 1107 # In case the supplied zone param is `None`, resort to the default one
  307. 1108 1 4.0 4.0 0.0 region = self._zone_to_region(zone or self.provider.default_zone,
  308. 1109 1 914587.0 914587.0 24.9 return_name_only=False)
  309. 1110 # Check if a default subnet already exists for the given region/zone
  310. 1111 1 2762018.0 2762018.0 75.1 for sn in self.find(label=GCPSubnet.CB_DEFAULT_SUBNET_LABEL):
  311. 1112 1 7.0 7.0 0.0 if sn.region == region.id:
  312. 1113 1 2.0 2.0 0.0 return sn
  313. 1114 # No default subnet in the supplied zone. Look for a default network,
  314. 1115 # then create a subnet whose address space does not overlap with any
  315. 1116 # other existing subnets. If there are existing subnets, this process
  316. 1117 # largely assumes the subnet address spaces are contiguous when it
  317. 1118 # does the calculations (e.g., 10.0.0.0/24, 10.0.1.0/24).
  318. 1119 cidr_block = GCPSubnet.CB_DEFAULT_SUBNET_IPV4RANGE
  319. 1120 net = self.provider.networking.networks.get_or_create_default()
  320. 1121 if net.subnets:
  321. 1122 max_sn = net.subnets[0]
  322. 1123 # Find the maximum address subnet address space within the network
  323. 1124 for esn in net.subnets:
  324. 1125 if (ipaddress.ip_network(esn.cidr_block) >
  325. 1126 ipaddress.ip_network(max_sn.cidr_block)):
  326. 1127 max_sn = esn
  327. 1128 max_sn_ipa = ipaddress.ip_network(max_sn.cidr_block)
  328. 1129 # Find the next available subnet after the max one, based on the
  329. 1130 # max subnet size
  330. 1131 next_sn_address = (
  331. 1132 next(max_sn_ipa.hosts()) + max_sn_ipa.num_addresses - 1)
  332. 1133 cidr_block = "{}/{}".format(next_sn_address, max_sn_ipa.prefixlen)
  333. 1134 sn = self.provider.networking.subnets.create(
  334. 1135 label=GCPSubnet.CB_DEFAULT_SUBNET_LABEL,
  335. 1136 cidr_block=cidr_block, network=net, zone=zone)
  336. 1137 router = self.provider.networking.routers.get_or_create_default(net)
  337. 1138 router.attach_subnet(sn)
  338. 1139 gateway = net.gateways.get_or_create()
  339. 1140 router.attach_gateway(gateway)
  340. 1141 return sn
  341. Total time: 2.71797 s
  342. Function: find at line 308
  343. Line # Hits Time Per Hit % Time Line Contents
  344. ==============================================================
  345. 308 @dispatch(event="provider.networking.subnets.find",
  346. 309 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  347. 310 @profile
  348. 311 def find(self, network=None, **kwargs):
  349. 312 1 2.0 2.0 0.0 if not network:
  350. 313 1 1.0 1.0 0.0 obj_list = self
  351. 314 else:
  352. 315 obj_list = network.subnets
  353. 316 1 1.0 1.0 0.0 filters = ['label']
  354. 317 1 2717925.0 2717925.0 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  355. 318 1 44.0 44.0 0.0 return ClientPagedResultList(self._provider, list(matches))
  356. Total time: 1.58702 s
  357. Function: delete at line 704
  358. Line # Hits Time Per Hit % Time Line Contents
  359. ==============================================================
  360. 704 @dispatch(event="provider.compute.instances.delete",
  361. 705 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  362. 706 @profile
  363. 707 def delete(self, instance):
  364. 708 2 5.0 2.5 0.0 instance = (instance if isinstance(instance, GCPInstance) else
  365. 709 self.get(instance))
  366. 710 2 2.0 1.0 0.0 if instance:
  367. 711 2 44160.0 22080.0 2.8 (self._provider
  368. 712 .gcp_compute
  369. 713 .instances()
  370. 714 2 5.0 2.5 0.0 .delete(project=self.provider.project_name,
  371. 715 2 789.0 394.5 0.0 zone=instance.zone_name,
  372. 716 2 1542062.0 771031.0 97.2 instance=instance.name)
  373. 717 .execute())
  374. Total time: 0.862251 s
  375. Function: get at line 382
  376. Line # Hits Time Per Hit % Time Line Contents
  377. ==============================================================
  378. 382 @dispatch(event="provider.compute.regions.get",
  379. 383 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  380. 384 @profile
  381. 385 def get(self, region_id):
  382. 386 1 3.0 3.0 0.0 region = self.provider.get_resource('regions', region_id,
  383. 387 1 862218.0 862218.0 100.0 region=region_id)
  384. 388 1 30.0 30.0 0.0 return GCPRegion(self.provider, region) if region else None
  385. Total time: 0.36834 s
  386. Function: find at line 449
  387. Line # Hits Time Per Hit % Time Line Contents
  388. ==============================================================
  389. 449 @profile
  390. 450 def find(self, limit=None, marker=None, **kwargs):
  391. 451 """
  392. 452 Searches for an image by a given list of attributes
  393. 453 """
  394. 454 3 5.0 1.7 0.0 label = kwargs.pop('label', None)
  395. 455
  396. 456 # All kwargs should have been popped at this time.
  397. 457 3 6.0 2.0 0.0 if len(kwargs) > 0:
  398. 458 1 1.0 1.0 0.0 raise InvalidParamException(
  399. 459 1 1.0 1.0 0.0 "Unrecognised parameters for search: %s. Supported "
  400. 460 1 15.0 15.0 0.0 "attributes: %s" % (kwargs, 'label'))
  401. 461
  402. 462 # Retrieve all available images by setting limit to sys.maxsize
  403. 463 2 368244.0 184122.0 100.0 images = [image for image in self if image.label == label]
  404. 464 2 7.0 3.5 0.0 return ClientPagedResultList(self.provider, images,
  405. 465 2 61.0 30.5 0.0 limit=limit, marker=marker)
  406. Total time: 0.30929 s
  407. Function: get at line 341
  408. Line # Hits Time Per Hit % Time Line Contents
  409. ==============================================================
  410. 341 @dispatch(event="provider.compute.vm_types.get",
  411. 342 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  412. 343 @profile
  413. 344 def get(self, vm_type_id):
  414. 345 2 309252.0 154626.0 100.0 vm_type = self.provider.get_resource('machineTypes', vm_type_id)
  415. 346 2 38.0 19.0 0.0 return GCPVMType(self.provider, vm_type) if vm_type else None
  416. Total time: 0.201059 s
  417. Function: get at line 786
  418. Line # Hits Time Per Hit % Time Line Contents
  419. ==============================================================
  420. 786 @dispatch(event="provider.networking.networks.get",
  421. 787 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  422. 788 @profile
  423. 789 def get(self, network_id):
  424. 790 1 201018.0 201018.0 100.0 network = self.provider.get_resource('networks', network_id)
  425. 791 1 41.0 41.0 0.0 return GCPNetwork(self.provider, network) if network else None
  426. Total time: 0.186214 s
  427. Function: list at line 1003
  428. Line # Hits Time Per Hit % Time Line Contents
  429. ==============================================================
  430. 1003 @dispatch(event="provider.networking.subnets.list",
  431. 1004 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  432. 1005 @profile
  433. 1006 def list(self, network=None, zone=None, limit=None, marker=None):
  434. 1007 """
  435. 1008 If the zone is not given, we list all subnets in the default region.
  436. 1009 """
  437. 1010 1 1.0 1.0 0.0 filter = None
  438. 1011 1 1.0 1.0 0.0 if network is not None:
  439. 1012 network = (network if isinstance(network, GCPNetwork)
  440. 1013 else self.provider.networking.networks.get(network))
  441. 1014 filter = 'network eq %s' % network.resource_url
  442. 1015 1 1.0 1.0 0.0 if zone:
  443. 1016 region_name = self._zone_to_region(zone)
  444. 1017 else:
  445. 1018 1 5.0 5.0 0.0 region_name = self.provider.region_name
  446. 1019 1 1.0 1.0 0.0 subnets = []
  447. 1020 1 10331.0 10331.0 5.5 response = (self.provider
  448. 1021 .gcp_compute
  449. 1022 .subnetworks()
  450. 1023 1 3.0 3.0 0.0 .list(project=self.provider.project_name,
  451. 1024 1 1.0 1.0 0.0 region=region_name,
  452. 1025 1 175627.0 175627.0 94.3 filter=filter)
  453. 1026 .execute())
  454. 1027 8 13.0 1.6 0.0 for subnet in response.get('items', []):
  455. 1028 7 89.0 12.7 0.0 subnets.append(GCPSubnet(self.provider, subnet))
  456. 1029 1 4.0 4.0 0.0 return ClientPagedResultList(self.provider, subnets,
  457. 1030 1 137.0 137.0 0.1 limit=limit, marker=marker)
  458. Total time: 2e-06 s
  459. Function: get_or_create at line 1610
  460. Line # Hits Time Per Hit % Time Line Contents
  461. ==============================================================
  462. 1610 @dispatch(event="provider.networking.gateways.get_or_create",
  463. 1611 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  464. 1612 @profile
  465. 1613 def get_or_create(self, network):
  466. 1614 1 2.0 2.0 100.0 return self._default_internet_gateway