filtered-gcp-security.res 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. cloudbridge.test.test_security_service.CloudSecurityServiceTestCase
  2. Test output
  3. ..........
  4. ----------------------------------------------------------------------
  5. Ran 10 tests in 424.495s
  6. OK
  7. Wrote profile results to run_single.py.lprof
  8. Timer unit: 1e-06 s
  9. Total time: 135.951 s
  10. Function: delete at line 222
  11. Line # Hits Time Per Hit % Time Line Contents
  12. ==============================================================
  13. 222 @dispatch(event="provider.security.vm_firewalls.delete",
  14. 223 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  15. 224 @profile
  16. 225 def delete(self, vm_firewall):
  17. 226 6 107.0 17.8 0.0 fw_id = (vm_firewall.id if isinstance(vm_firewall, GCPVMFirewall)
  18. 227 else vm_firewall)
  19. 228 6 135950603.0 22658433.8 100.0 return self._delegate.delete_tag_network_with_id(fw_id)
  20. Total time: 95.6242 s
  21. Function: create_with_priority at line 284
  22. Line # Hits Time Per Hit % Time Line Contents
  23. ==============================================================
  24. 284 @profile
  25. 285 def create_with_priority(self, firewall, direction, protocol, priority,
  26. 286 from_port=None, to_port=None, cidr=None,
  27. 287 src_dest_fw=None):
  28. 288 11 46.0 4.2 0.0 port = GCPVMFirewallRuleService.to_port_range(from_port, to_port)
  29. 289 11 11.0 1.0 0.0 src_dest_tag = None
  30. 290 11 8.0 0.7 0.0 src_dest_fw_id = None
  31. 291 11 8.0 0.7 0.0 if src_dest_fw:
  32. 292 1 2.0 2.0 0.0 src_dest_tag = src_dest_fw.name
  33. 293 1 24.0 24.0 0.0 src_dest_fw_id = src_dest_fw.id
  34. 294 11 34.0 3.1 0.0 if not firewall.delegate.add_firewall(
  35. 295 11 32.0 2.9 0.0 firewall.name, direction, protocol, priority, port, cidr,
  36. 296 11 38.0 3.5 0.0 src_dest_tag, firewall.description,
  37. 297 11 95433532.0 8675775.6 99.8 firewall.network.name):
  38. 298 return None
  39. 299 11 45.0 4.1 0.0 rules = self.find(firewall, direction=direction, protocol=protocol,
  40. 300 11 13.0 1.2 0.0 from_port=from_port, to_port=to_port, cidr=cidr,
  41. 301 11 190339.0 17303.5 0.2 src_dest_fw_id=src_dest_fw_id)
  42. 302 11 12.0 1.1 0.0 if len(rules) < 1:
  43. 303 6 2.0 0.3 0.0 return None
  44. 304 5 9.0 1.8 0.0 return rules[0]
  45. Total time: 92.3823 s
  46. Function: create at line 205
  47. Line # Hits Time Per Hit % Time Line Contents
  48. ==============================================================
  49. 205 @dispatch(event="provider.security.vm_firewalls.create",
  50. 206 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  51. 207 @profile
  52. 208 def create(self, label, network, description=None):
  53. 209 16 222.0 13.9 0.0 GCPVMFirewall.assert_valid_resource_label(label)
  54. 210 6 14.0 2.3 0.0 network = (network if isinstance(network, GCPNetwork)
  55. 211 6 2195956.0 365992.7 2.4 else self.provider.networking.networks.get(network))
  56. 212 6 165.0 27.5 0.0 fw = GCPVMFirewall(self._delegate, label, network, description)
  57. 213 6 43930059.0 7321676.5 47.6 fw.label = label
  58. 214 # This rule exists implicitly. Add it explicitly so that the firewall
  59. 215 # is not empty and the rule is shown by list/get/find methods.
  60. 216 # pylint:disable=protected-access
  61. 217 6 71.0 11.8 0.0 self.provider.security._vm_firewall_rules.create_with_priority(
  62. 218 6 24.0 4.0 0.0 fw, direction=TrafficDirection.OUTBOUND, protocol='tcp',
  63. 219 6 46255807.0 7709301.2 50.1 priority=65534, cidr='0.0.0.0/0')
  64. 220 6 2.0 0.3 0.0 return fw
  65. Total time: 66.1447 s
  66. Function: label at line 482
  67. Line # Hits Time Per Hit % Time Line Contents
  68. ==============================================================
  69. 482 @label.setter
  70. 483 @profile
  71. 484 def label(self, value):
  72. 485 17 256.0 15.1 0.0 self.assert_valid_resource_label(value)
  73. 486 9 47.0 5.2 0.0 tag_name = "_".join(["firewall", self.name, "label"])
  74. 487 9 66144423.0 7349380.3 100.0 helpers.modify_or_add_metadata_item(self._provider, tag_name, value)
  75. Total time: 49.3686 s
  76. Function: create at line 306
  77. Line # Hits Time Per Hit % Time Line Contents
  78. ==============================================================
  79. 306 @dispatch(event="provider.security.vm_firewall_rules.create",
  80. 307 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  81. 308 @profile
  82. 309 def create(self, firewall, direction, protocol, from_port=None,
  83. 310 to_port=None, cidr=None, src_dest_fw=None):
  84. 311 5 6.0 1.2 0.0 return self.create_with_priority(firewall, direction, protocol,
  85. 312 5 4.0 0.8 0.0 1000, from_port, to_port, cidr,
  86. 313 5 49368624.0 9873724.8 100.0 src_dest_fw)
  87. Total time: 28.7511 s
  88. Function: delete at line 315
  89. Line # Hits Time Per Hit % Time Line Contents
  90. ==============================================================
  91. 315 @dispatch(event="provider.security.vm_firewall_rules.delete",
  92. 316 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  93. 317 @profile
  94. 318 def delete(self, firewall, rule):
  95. 319 2 3.0 1.5 0.0 rule = (rule if isinstance(rule, GCPVMFirewallRule)
  96. 320 else self.get(firewall, rule))
  97. 321 2 426.0 213.0 0.0 if rule.is_dummy_rule():
  98. 322 return True
  99. 323 2 28750687.0 14375343.5 100.0 firewall.delegate.delete_firewall_id(rule._rule)
  100. Total time: 26.1585 s
  101. Function: create at line 137
  102. Line # Hits Time Per Hit % Time Line Contents
  103. ==============================================================
  104. 137 @dispatch(event="provider.security.key_pairs.create",
  105. 138 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  106. 139 @profile
  107. 140 def create(self, name, public_key_material=None):
  108. 141 14 143.0 10.2 0.0 GCPKeyPair.assert_valid_resource_name(name)
  109. 142 4 2.0 0.5 0.0 private_key = None
  110. 143 4 4.0 1.0 0.0 if not public_key_material:
  111. 144 3 234767.0 78255.7 0.9 public_key_material, private_key = cb_helpers.generate_key_pair()
  112. 145 # TODO: Add support for other formats not assume ssh-rsa
  113. 146 1 1.0 1.0 0.0 elif "ssh-rsa" not in public_key_material:
  114. 147 public_key_material = "ssh-rsa {}".format(public_key_material)
  115. 148 4 20.0 5.0 0.0 kp_info = GCPKeyPair.GCPKeyInfo(name, public_key_material)
  116. 149 4 182.0 45.5 0.0 metadata_value = json.dumps(kp_info._asdict())
  117. 150 4 3.0 0.8 0.0 try:
  118. 151 4 9.0 2.2 0.0 helpers.add_metadata_item(self.provider,
  119. 152 4 5.0 1.2 0.0 GCPKeyPair.KP_TAG_PREFIX + name,
  120. 153 4 25923184.0 6480796.0 99.1 metadata_value)
  121. 154 3 65.0 21.7 0.0 return GCPKeyPair(self.provider, kp_info, private_key)
  122. 155 1 5.0 5.0 0.0 except googleapiclient.errors.HttpError as err:
  123. 156 1 4.0 4.0 0.0 if err.resp.get('content-type', '').startswith('application/json'):
  124. 157 1 62.0 62.0 0.0 message = (json.loads(err.content).get('error', {})
  125. 158 1 3.0 3.0 0.0 .get('errors', [{}])[0].get('message'))
  126. 159 1 2.0 2.0 0.0 if "duplicate keys" in message:
  127. 160 1 2.0 2.0 0.0 raise DuplicateResourceException(
  128. 161 1 7.0 7.0 0.0 'A KeyPair with name {0} already exists'.format(name))
  129. 162 raise
  130. Total time: 20.4335 s
  131. Function: delete at line 164
  132. Line # Hits Time Per Hit % Time Line Contents
  133. ==============================================================
  134. 164 @dispatch(event="provider.security.key_pairs.delete",
  135. 165 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  136. 166 @profile
  137. 167 def delete(self, key_pair):
  138. 168 3 7.0 2.3 0.0 key_pair = (key_pair if isinstance(key_pair, GCPKeyPair) else
  139. 169 3 520539.0 173513.0 2.5 self.get(key_pair))
  140. 170 3 2.0 0.7 0.0 if key_pair:
  141. 171 3 4.0 1.3 0.0 helpers.remove_metadata_item(
  142. 172 3 19912993.0 6637664.3 97.5 self.provider, GCPKeyPair.KP_TAG_PREFIX + key_pair.name)
  143. Total time: 20.1145 s
  144. Function: get_or_create_default at line 1098
  145. Line # Hits Time Per Hit % Time Line Contents
  146. ==============================================================
  147. 1098 @profile
  148. 1099 def get_or_create_default(self, zone):
  149. 1100 """
  150. 1101 Return an existing or create a new subnet for the supplied zone.
  151. 1102
  152. 1103 In GCP, subnets are a regional resource so a single subnet can services
  153. 1104 an entire region. The supplied zone parameter is used to derive the
  154. 1105 parent region under which the default subnet then exists.
  155. 1106 """
  156. 1107 # In case the supplied zone param is `None`, resort to the default one
  157. 1108 6 13.0 2.2 0.0 region = self._zone_to_region(zone or self.provider.default_zone,
  158. 1109 6 3993255.0 665542.5 19.9 return_name_only=False)
  159. 1110 # Check if a default subnet already exists for the given region/zone
  160. 1111 6 16121125.0 2686854.2 80.1 for sn in self.find(label=GCPSubnet.CB_DEFAULT_SUBNET_LABEL):
  161. 1112 6 46.0 7.7 0.0 if sn.region == region.id:
  162. 1113 6 16.0 2.7 0.0 return sn
  163. 1114 # No default subnet in the supplied zone. Look for a default network,
  164. 1115 # then create a subnet whose address space does not overlap with any
  165. 1116 # other existing subnets. If there are existing subnets, this process
  166. 1117 # largely assumes the subnet address spaces are contiguous when it
  167. 1118 # does the calculations (e.g., 10.0.0.0/24, 10.0.1.0/24).
  168. 1119 cidr_block = GCPSubnet.CB_DEFAULT_SUBNET_IPV4RANGE
  169. 1120 net = self.provider.networking.networks.get_or_create_default()
  170. 1121 if net.subnets:
  171. 1122 max_sn = net.subnets[0]
  172. 1123 # Find the maximum address subnet address space within the network
  173. 1124 for esn in net.subnets:
  174. 1125 if (ipaddress.ip_network(esn.cidr_block) >
  175. 1126 ipaddress.ip_network(max_sn.cidr_block)):
  176. 1127 max_sn = esn
  177. 1128 max_sn_ipa = ipaddress.ip_network(max_sn.cidr_block)
  178. 1129 # Find the next available subnet after the max one, based on the
  179. 1130 # max subnet size
  180. 1131 next_sn_address = (
  181. 1132 next(max_sn_ipa.hosts()) + max_sn_ipa.num_addresses - 1)
  182. 1133 cidr_block = "{}/{}".format(next_sn_address, max_sn_ipa.prefixlen)
  183. 1134 sn = self.provider.networking.subnets.create(
  184. 1135 label=GCPSubnet.CB_DEFAULT_SUBNET_LABEL,
  185. 1136 cidr_block=cidr_block, network=net, zone=zone)
  186. 1137 router = self.provider.networking.routers.get_or_create_default(net)
  187. 1138 router.attach_subnet(sn)
  188. 1139 gateway = net.gateways.get_or_create()
  189. 1140 router.attach_gateway(gateway)
  190. 1141 return sn
  191. Total time: 19.1619 s
  192. Function: get at line 786
  193. Line # Hits Time Per Hit % Time Line Contents
  194. ==============================================================
  195. 786 @dispatch(event="provider.networking.networks.get",
  196. 787 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  197. 788 @profile
  198. 789 def get(self, network_id):
  199. 790 61 19159803.0 314095.1 100.0 network = self.provider.get_resource('networks', network_id)
  200. 791 61 2126.0 34.9 0.0 return GCPNetwork(self.provider, network) if network else None
  201. Total time: 16.0481 s
  202. Function: find at line 308
  203. Line # Hits Time Per Hit % Time Line Contents
  204. ==============================================================
  205. 308 @dispatch(event="provider.networking.subnets.find",
  206. 309 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  207. 310 @profile
  208. 311 def find(self, network=None, **kwargs):
  209. 312 6 6.0 1.0 0.0 if not network:
  210. 313 6 5.0 0.8 0.0 obj_list = self
  211. 314 else:
  212. 315 obj_list = network.subnets
  213. 316 6 5.0 0.8 0.0 filters = ['label']
  214. 317 6 16047845.0 2674640.8 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  215. 318 6 282.0 47.0 0.0 return ClientPagedResultList(self._provider, list(matches))
  216. Total time: 14.4078 s
  217. Function: list at line 192
  218. Line # Hits Time Per Hit % Time Line Contents
  219. ==============================================================
  220. 192 @dispatch(event="provider.security.vm_firewalls.list",
  221. 193 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  222. 194 @profile
  223. 195 def list(self, limit=None, marker=None):
  224. 196 8 16.0 2.0 0.0 vm_firewalls = []
  225. 197 54 16425.0 304.2 0.1 for tag, network_name in self._delegate.tag_networks:
  226. 198 46 347.0 7.5 0.0 network = self.provider.networking.networks.get(
  227. 199 46 14389298.0 312810.8 99.9 network_name)
  228. 200 46 1055.0 22.9 0.0 vm_firewall = GCPVMFirewall(self._delegate, tag, network)
  229. 201 46 73.0 1.6 0.0 vm_firewalls.append(vm_firewall)
  230. 202 8 27.0 3.4 0.0 return ClientPagedResultList(self.provider, vm_firewalls,
  231. 203 8 566.0 70.8 0.0 limit=limit, marker=marker)
  232. Total time: 8.39101 s
  233. Function: find at line 81
  234. Line # Hits Time Per Hit % Time Line Contents
  235. ==============================================================
  236. 81 @dispatch(event="provider.security.vm_firewalls.find",
  237. 82 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  238. 83 @profile
  239. 84 def find(self, **kwargs):
  240. 85 3 6.0 2.0 0.0 obj_list = self
  241. 86 3 4.0 1.3 0.0 filters = ['label']
  242. 87 3 8390891.0 2796963.7 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  243. 88
  244. 89 # All kwargs should have been popped at this time.
  245. 90 2 6.0 3.0 0.0 if len(kwargs) > 0:
  246. 91 raise InvalidParamException(
  247. 92 "Unrecognised parameters for search: %s. Supported "
  248. 93 "attributes: %s" % (kwargs, ", ".join(filters)))
  249. 94
  250. 95 2 10.0 5.0 0.0 return ClientPagedResultList(self.provider,
  251. 96 2 89.0 44.5 0.0 matches if matches else [])
  252. Total time: 3.93347 s
  253. Function: get at line 382
  254. Line # Hits Time Per Hit % Time Line Contents
  255. ==============================================================
  256. 382 @dispatch(event="provider.compute.regions.get",
  257. 383 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  258. 384 @profile
  259. 385 def get(self, region_id):
  260. 386 6 12.0 2.0 0.0 region = self.provider.get_resource('regions', region_id,
  261. 387 6 3933318.0 655553.0 100.0 region=region_id)
  262. 388 6 138.0 23.0 0.0 return GCPRegion(self.provider, region) if region else None
  263. Total time: 2.33161 s
  264. Function: list at line 104
  265. Line # Hits Time Per Hit % Time Line Contents
  266. ==============================================================
  267. 104 @dispatch(event="provider.security.key_pairs.list",
  268. 105 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  269. 106 @profile
  270. 107 def list(self, limit=None, marker=None):
  271. 108 12 12.0 1.0 0.0 key_pairs = []
  272. 109 12 16.0 1.3 0.0 for item in helpers.find_matching_metadata_items(
  273. 110 59 2329791.0 39488.0 99.9 self.provider, GCPKeyPair.KP_TAG_REGEX):
  274. 111 47 690.0 14.7 0.0 metadata_value = json.loads(item['value'])
  275. 112 47 194.0 4.1 0.0 kp_info = GCPKeyPair.GCPKeyInfo(**metadata_value)
  276. 113 47 412.0 8.8 0.0 key_pairs.append(GCPKeyPair(self.provider, kp_info))
  277. 114 12 17.0 1.4 0.0 return ClientPagedResultList(self.provider, key_pairs,
  278. 115 12 475.0 39.6 0.0 limit=limit, marker=marker)
  279. Total time: 1.39911 s
  280. Function: list at line 1003
  281. Line # Hits Time Per Hit % Time Line Contents
  282. ==============================================================
  283. 1003 @dispatch(event="provider.networking.subnets.list",
  284. 1004 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  285. 1005 @profile
  286. 1006 def list(self, network=None, zone=None, limit=None, marker=None):
  287. 1007 """
  288. 1008 If the zone is not given, we list all subnets in the default region.
  289. 1009 """
  290. 1010 6 4.0 0.7 0.0 filter = None
  291. 1011 6 5.0 0.8 0.0 if network is not None:
  292. 1012 network = (network if isinstance(network, GCPNetwork)
  293. 1013 else self.provider.networking.networks.get(network))
  294. 1014 filter = 'network eq %s' % network.resource_url
  295. 1015 6 2.0 0.3 0.0 if zone:
  296. 1016 region_name = self._zone_to_region(zone)
  297. 1017 else:
  298. 1018 6 8.0 1.3 0.0 region_name = self.provider.region_name
  299. 1019 6 3.0 0.5 0.0 subnets = []
  300. 1020 6 59042.0 9840.3 4.2 response = (self.provider
  301. 1021 .gcp_compute
  302. 1022 .subnetworks()
  303. 1023 6 15.0 2.5 0.0 .list(project=self.provider.project_name,
  304. 1024 6 4.0 0.7 0.0 region=region_name,
  305. 1025 6 1339305.0 223217.5 95.7 filter=filter)
  306. 1026 .execute())
  307. 1027 48 70.0 1.5 0.0 for subnet in response.get('items', []):
  308. 1028 42 326.0 7.8 0.0 subnets.append(GCPSubnet(self.provider, subnet))
  309. 1029 6 12.0 2.0 0.0 return ClientPagedResultList(self.provider, subnets,
  310. 1030 6 311.0 51.8 0.0 limit=limit, marker=marker)
  311. Total time: 1.11951 s
  312. Function: get at line 91
  313. Line # Hits Time Per Hit % Time Line Contents
  314. ==============================================================
  315. 91 @dispatch(event="provider.security.key_pairs.get",
  316. 92 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  317. 93 @profile
  318. 94 def get(self, key_pair_id):
  319. 95 """
  320. 96 Returns a KeyPair given its ID.
  321. 97 """
  322. 98 25 1119442.0 44777.7 100.0 for kp in self:
  323. 99 24 40.0 1.7 0.0 if kp.id == key_pair_id:
  324. 100 5 30.0 6.0 0.0 return kp
  325. 101 else:
  326. 102 1 1.0 1.0 0.0 return None
  327. Total time: 0.897284 s
  328. Function: get at line 181
  329. Line # Hits Time Per Hit % Time Line Contents
  330. ==============================================================
  331. 181 @dispatch(event="provider.security.vm_firewalls.get",
  332. 182 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  333. 183 @profile
  334. 184 def get(self, vm_firewall_id):
  335. 185 tag, network_name = \
  336. 186 4 7801.0 1950.2 0.9 self._delegate.get_tag_network_from_id(vm_firewall_id)
  337. 187 4 5.0 1.2 0.0 if tag is None:
  338. 188 1 1.0 1.0 0.0 return None
  339. 189 3 889408.0 296469.3 99.1 network = self.provider.networking.networks.get(network_name)
  340. 190 3 69.0 23.0 0.0 return GCPVMFirewall(self._delegate, tag, network)
  341. Total time: 0.409439 s
  342. Function: find at line 117
  343. Line # Hits Time Per Hit % Time Line Contents
  344. ==============================================================
  345. 117 @dispatch(event="provider.security.key_pairs.find",
  346. 118 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  347. 119 @profile
  348. 120 def find(self, **kwargs):
  349. 121 """
  350. 122 Searches for a key pair by a given list of attributes.
  351. 123 """
  352. 124 3 3.0 1.0 0.0 obj_list = self
  353. 125 3 3.0 1.0 0.0 filters = ['id', 'name']
  354. 126 3 409375.0 136458.3 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  355. 127
  356. 128 # All kwargs should have been popped at this time.
  357. 129 2 2.0 1.0 0.0 if len(kwargs) > 0:
  358. 130 raise InvalidParamException(
  359. 131 "Unrecognised parameters for search: %s. Supported "
  360. 132 "attributes: %s" % (kwargs, ", ".join(filters)))
  361. 133
  362. 134 2 3.0 1.5 0.0 return ClientPagedResultList(self.provider,
  363. 135 2 53.0 26.5 0.0 matches if matches else [])
  364. Total time: 0.243234 s
  365. Function: refresh at line 542
  366. Line # Hits Time Per Hit % Time Line Contents
  367. ==============================================================
  368. 542 @profile
  369. 543 def refresh(self):
  370. 544 1 243228.0 243228.0 100.0 fw = self._provider.security.vm_firewalls.get(self.id)
  371. 545 # restore all internal state
  372. 546 1 1.0 1.0 0.0 if fw:
  373. 547 # pylint:disable=protected-access
  374. 548 1 1.0 1.0 0.0 self._delegate = fw._delegate
  375. 549 # pylint:disable=protected-access
  376. 550 1 1.0 1.0 0.0 self._description = fw._description
  377. 551 # pylint:disable=protected-access
  378. 552 1 1.0 1.0 0.0 self._network = fw._network
  379. 553 # pylint:disable=protected-access
  380. 554 1 2.0 2.0 0.0 self._rule_container = fw._rule_container
  381. Total time: 0.125725 s
  382. Function: find at line 121
  383. Line # Hits Time Per Hit % Time Line Contents
  384. ==============================================================
  385. 121 @dispatch(event="provider.security.vm_firewall_rules.find",
  386. 122 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  387. 123 @profile
  388. 124 def find(self, firewall, **kwargs):
  389. 125 14 49.0 3.5 0.0 obj_list = firewall.rules
  390. 126 14 12.0 0.9 0.0 filters = ['name', 'direction', 'protocol', 'from_port', 'to_port',
  391. 127 14 13.0 0.9 0.0 'cidr', 'src_dest_fw', 'src_dest_fw_id']
  392. 128 14 125412.0 8958.0 99.8 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  393. 129 13 239.0 18.4 0.2 return ClientPagedResultList(self._provider, list(matches))
  394. Total time: 0.093306 s
  395. Function: list at line 254
  396. Line # Hits Time Per Hit % Time Line Contents
  397. ==============================================================
  398. 254 @dispatch(event="provider.security.vm_firewall_rules.list",
  399. 255 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  400. 256 @profile
  401. 257 def list(self, firewall, limit=None, marker=None):
  402. 258 26 32.0 1.2 0.0 rules = []
  403. 259 26 61.0 2.3 0.1 for fw in firewall.delegate.iter_firewalls(
  404. 260 66 10237.0 155.1 11.0 firewall.name, firewall.network.name):
  405. 261 40 56163.0 1404.1 60.2 rule = GCPVMFirewallRule(firewall, fw['id'])
  406. 262 40 25970.0 649.2 27.8 if rule.is_dummy_rule():
  407. 263 26 62.0 2.4 0.1 self._dummy_rule = rule
  408. 264 else:
  409. 265 14 16.0 1.1 0.0 rules.append(rule)
  410. 266 26 45.0 1.7 0.0 return ClientPagedResultList(self.provider, rules,
  411. 267 26 720.0 27.7 0.8 limit=limit, marker=marker)
  412. Total time: 0.007167 s
  413. Function: get at line 111
  414. Line # Hits Time Per Hit % Time Line Contents
  415. ==============================================================
  416. 111 @dispatch(event="provider.security.vm_firewall_rules.get",
  417. 112 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  418. 113 @profile
  419. 114 def get(self, firewall, rule_id):
  420. 115 2 7166.0 3583.0 100.0 matches = [rule for rule in firewall.rules if rule.id == rule_id]
  421. 116 2 0.0 0.0 0.0 if matches:
  422. 117 1 1.0 1.0 0.0 return matches[0]
  423. 118 else:
  424. 119 1 0.0 0.0 0.0 return None