filtered-aws-compute.res 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. cloudbridge.test.test_compute_service.CloudComputeServiceTestCase
  2. Error during cleanup: False is not true : Instance.state must be unknown when refreshing after a delete but got deleted
  3. Error during cleanup: An error occurred (InvalidAllocationID.NotFound) when calling the DescribeAddresses operation: The allocation ID 'eipalloc-0ee614962c6e91a84' does not exist
  4. Test output
  5. ......
  6. ----------------------------------------------------------------------
  7. Ran 6 tests in 383.400s
  8. OK
  9. Wrote profile results to run_single.py.lprof
  10. Timer unit: 1e-06 s
  11. Total time: 40.1343 s
  12. Function: refresh at line 376
  13. Line # Hits Time Per Hit % Time Line Contents
  14. ==============================================================
  15. 376 @profile
  16. 377 def refresh(self):
  17. 378 308 1184.0 3.8 0.0 try:
  18. 379 308 40132285.0 130299.6 100.0 self._ec2_instance.reload()
  19. 380 308 854.0 2.8 0.0 self._unknown_state = False
  20. 381 except ClientError:
  21. 382 # The instance no longer exists and cannot be refreshed.
  22. 383 # set the state to unknown
  23. 384 self._unknown_state = True
  24. Total time: 8.67415 s
  25. Function: create at line 769
  26. Line # Hits Time Per Hit % Time Line Contents
  27. ==============================================================
  28. 769 @dispatch(event="provider.compute.instances.create",
  29. 770 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  30. 771 @profile
  31. 772 def create(self, label, image, vm_type, subnet, zone,
  32. 773 key_pair=None, vm_firewalls=None, user_data=None,
  33. 774 launch_config=None, **kwargs):
  34. 775 14 154.0 11.0 0.0 AWSInstance.assert_valid_resource_label(label)
  35. 776 4 9.0 2.2 0.0 image_id = image.id if isinstance(image, MachineImage) else image
  36. 777 vm_size = vm_type.id if \
  37. 778 4 5.0 1.2 0.0 isinstance(vm_type, VMType) else vm_type
  38. 779 subnet = (self.provider.networking.subnets.get(subnet)
  39. 780 4 10.0 2.5 0.0 if isinstance(subnet, str) else subnet)
  40. 781 4 4.0 1.0 0.0 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  41. 782 4 3.0 0.8 0.0 key_pair_name = key_pair.name if isinstance(
  42. 783 4 2.0 0.5 0.0 key_pair,
  43. 784 4 17.0 4.2 0.0 KeyPair) else key_pair
  44. 785 4 4.0 1.0 0.0 if launch_config:
  45. 786 1 52.0 52.0 0.0 bdm = self._process_block_device_mappings(launch_config)
  46. 787 else:
  47. 788 3 3.0 1.0 0.0 bdm = None
  48. 789
  49. 790 subnet_id, zone_id, vm_firewall_ids = \
  50. 791 4 218183.0 54545.8 2.5 self._resolve_launch_options(subnet, zone_id, vm_firewalls)
  51. 792
  52. 793 4 6.0 1.5 0.0 placement = {'AvailabilityZone': zone_id} if zone_id else None
  53. 794 4 14.0 3.5 0.0 inst = self.svc.create('create_instances',
  54. 795 4 4.0 1.0 0.0 ImageId=image_id,
  55. 796 4 4.0 1.0 0.0 MinCount=1,
  56. 797 4 4.0 1.0 0.0 MaxCount=1,
  57. 798 4 4.0 1.0 0.0 KeyName=key_pair_name,
  58. 799 4 3.0 0.8 0.0 SecurityGroupIds=vm_firewall_ids or None,
  59. 800 4 9.0 2.2 0.0 UserData=str(user_data) or None,
  60. 801 4 2.0 0.5 0.0 InstanceType=vm_size,
  61. 802 4 3.0 0.8 0.0 Placement=placement,
  62. 803 4 2.0 0.5 0.0 BlockDeviceMappings=bdm,
  63. 804 4 6868958.0 1717239.5 79.2 SubnetId=subnet_id
  64. 805 )
  65. 806 4 11.0 2.8 0.0 if inst and len(inst) == 1:
  66. 807 # Wait until the resource exists
  67. 808 # pylint:disable=protected-access
  68. 809 4 853666.0 213416.5 9.8 inst[0]._wait_till_exists()
  69. 810 # Tag the instance w/ the name
  70. 811 4 733006.0 183251.5 8.5 inst[0].label = label
  71. 812 4 9.0 2.2 0.0 return inst[0]
  72. 813 raise ValueError(
  73. 814 'Expected a single object response, got a list: %s' % inst)
  74. Total time: 5.88847 s
  75. Function: create at line 369
  76. Line # Hits Time Per Hit % Time Line Contents
  77. ==============================================================
  78. 369 @dispatch(event="provider.storage.volumes.create",
  79. 370 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  80. 371 @profile
  81. 372 def create(self, label, size, zone, snapshot=None, description=None):
  82. 373 1 13.0 13.0 0.0 AWSVolume.assert_valid_resource_label(label)
  83. 374 1 1.0 1.0 0.0 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  84. 375 1 1.0 1.0 0.0 snapshot_id = snapshot.id if isinstance(
  85. 376 1 1.0 1.0 0.0 snapshot, AWSSnapshot) and snapshot else snapshot
  86. 377
  87. 378 1 4.0 4.0 0.0 cb_vol = self.svc.create('create_volume', Size=size,
  88. 379 1 0.0 0.0 0.0 AvailabilityZone=zone_id,
  89. 380 1 284030.0 284030.0 4.8 SnapshotId=snapshot_id)
  90. 381 # Wait until ready to tag instance
  91. 382 1 5496369.0 5496369.0 93.3 cb_vol.wait_till_ready()
  92. 383 1 108043.0 108043.0 1.8 cb_vol.label = label
  93. 384 1 2.0 2.0 0.0 if description:
  94. 385 cb_vol.description = description
  95. 386 1 1.0 1.0 0.0 return cb_vol
  96. Total time: 2.79839 s
  97. Function: list at line 881
  98. Line # Hits Time Per Hit % Time Line Contents
  99. ==============================================================
  100. 881 @dispatch(event="provider.compute.vm_types.list",
  101. 882 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  102. 883 @profile
  103. 884 def list(self, limit=None, marker=None):
  104. 885 6 9.0 1.5 0.0 vm_types = [AWSVMType(self.provider, vm_type)
  105. 886 6 2798173.0 466362.2 100.0 for vm_type in self.instance_data]
  106. 887 6 11.0 1.8 0.0 return ClientPagedResultList(self.provider, vm_types,
  107. 888 6 202.0 33.7 0.0 limit=limit, marker=marker)
  108. Total time: 2.12073 s
  109. Function: find at line 225
  110. Line # Hits Time Per Hit % Time Line Contents
  111. ==============================================================
  112. 225 @dispatch(event="provider.compute.vm_types.find",
  113. 226 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  114. 227 @profile
  115. 228 def find(self, **kwargs):
  116. 229 5 8.0 1.6 0.0 obj_list = self
  117. 230 5 5.0 1.0 0.0 filters = ['name']
  118. 231 5 2120612.0 424122.4 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  119. 232 5 101.0 20.2 0.0 return ClientPagedResultList(self._provider, list(matches))
  120. Total time: 1.404 s
  121. Function: label at line 254
  122. Line # Hits Time Per Hit % Time Line Contents
  123. ==============================================================
  124. 254 @label.setter
  125. 255 # pylint:disable=arguments-differ
  126. 256 @profile
  127. 257 def label(self, value):
  128. 258 15 184.0 12.3 0.0 self.assert_valid_resource_label(value)
  129. 259 7 14.0 2.0 0.0 self._ec2_instance.create_tags(Tags=[{'Key': 'Name',
  130. 260 7 1403800.0 200542.9 100.0 'Value': value or ""}])
  131. Total time: 1.29368 s
  132. Function: list at line 836
  133. Line # Hits Time Per Hit % Time Line Contents
  134. ==============================================================
  135. 836 @dispatch(event="provider.compute.instances.list",
  136. 837 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  137. 838 @profile
  138. 839 def list(self, limit=None, marker=None):
  139. 840 9 1293682.0 143742.4 100.0 return self.svc.list(limit=limit, marker=marker)
  140. Total time: 1.27073 s
  141. Function: get at line 173
  142. Line # Hits Time Per Hit % Time Line Contents
  143. ==============================================================
  144. 173 @dispatch(event="provider.security.vm_firewalls.get",
  145. 174 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  146. 175 @profile
  147. 176 def get(self, vm_firewall_id):
  148. 177 13 99.0 7.6 0.0 log.debug("Getting Firewall Service with the id: %s", vm_firewall_id)
  149. 178 13 1270631.0 97740.8 100.0 return self.svc.get(vm_firewall_id)
  150. Total time: 1.11421 s
  151. Function: get_or_create_default at line 1103
  152. Line # Hits Time Per Hit % Time Line Contents
  153. ==============================================================
  154. 1103 @profile
  155. 1104 def get_or_create_default(self, zone):
  156. 1105 3 8.0 2.7 0.0 zone_name = zone.name if isinstance(zone, AWSPlacementZone) else zone
  157. 1106
  158. 1107 # # Look for provider default subnet in current zone
  159. 1108 # if zone_name:
  160. 1109 # snl = self.svc.find('availabilityZone', zone_name)
  161. 1110 #
  162. 1111 # else:
  163. 1112 # snl = self.svc.list()
  164. 1113 # # Find first available default subnet by sorted order
  165. 1114 # # of availability zone. Prefer zone us-east-1a over 1e,
  166. 1115 # # because newer zones tend to have less compatibility
  167. 1116 # # with different instance types (e.g. c5.large not available
  168. 1117 # # on us-east-1e as of 14 Dec. 2017).
  169. 1118 # # pylint:disable=protected-access
  170. 1119 # snl.sort(key=lambda sn: sn._subnet.availability_zone)
  171. 1120 #
  172. 1121 # for sn in snl:
  173. 1122 # # pylint:disable=protected-access
  174. 1123 # if sn._subnet.default_for_az:
  175. 1124 # return sn
  176. 1125
  177. 1126 # If no provider-default subnet has been found, look for
  178. 1127 # cloudbridge-default by label. We suffix labels by availability zone,
  179. 1128 # thus we add the wildcard for the regular expression to find the
  180. 1129 # subnet
  181. 1130 3 1114076.0 371358.7 100.0 snl = self.find(label=AWSSubnet.CB_DEFAULT_SUBNET_LABEL + "*")
  182. 1131
  183. 1132 3 7.0 2.3 0.0 if snl:
  184. 1133 # pylint:disable=protected-access
  185. 1134 3 45.0 15.0 0.0 snl.sort(key=lambda sn: sn._subnet.availability_zone)
  186. 1135 3 6.0 2.0 0.0 if not zone_name:
  187. 1136 return snl[0]
  188. 1137 3 4.0 1.3 0.0 for subnet in snl:
  189. 1138 3 58.0 19.3 0.0 if subnet.zone.name == zone_name:
  190. 1139 3 4.0 1.3 0.0 return subnet
  191. 1140
  192. 1141 # No default Subnet exists, try to create a CloudBridge-specific
  193. 1142 # subnet. This involves creating the network, subnets, internet
  194. 1143 # gateway, and connecting it all together so that the network has
  195. 1144 # Internet connectivity.
  196. 1145
  197. 1146 # Check if a default net already exists and get it or create on
  198. 1147 default_net = self.provider.networking.networks.get_or_create_default()
  199. 1148
  200. 1149 # Get/create an internet gateway for the default network and a
  201. 1150 # corresponding router if it does not already exist.
  202. 1151 # NOTE: Comment this out because the docs instruct users to setup
  203. 1152 # network connectivity manually. There's a bit of discrepancy here
  204. 1153 # though because the provider-default network will have Internet
  205. 1154 # connectivity (unlike the CloudBridge-default network with this
  206. 1155 # being commented) and is hence left in the codebase.
  207. 1156 # default_gtw = default_net.gateways.get_or_create()
  208. 1157 # router_label = "{0}-router".format(
  209. 1158 # AWSNetwork.CB_DEFAULT_NETWORK_LABEL)
  210. 1159 # default_routers = self.provider.networking.routers.find(
  211. 1160 # label=router_label)
  212. 1161 # if len(default_routers) == 0:
  213. 1162 # default_router = self.provider.networking.routers.create(
  214. 1163 # router_label, default_net)
  215. 1164 # default_router.attach_gateway(default_gtw)
  216. 1165 # else:
  217. 1166 # default_router = default_routers[0]
  218. 1167
  219. 1168 # Create a subnet in each of the region's zones
  220. 1169 region = self.provider.compute.regions.get(self.provider.region_name)
  221. 1170 default_sn = None
  222. 1171
  223. 1172 # Determine how many subnets we'll need for the default network and the
  224. 1173 # number of available zones. We need to derive a non-overlapping
  225. 1174 # network size for each subnet within the parent net so figure those
  226. 1175 # subnets here. `<net>.subnets` method will do this but we need to give
  227. 1176 # it a prefix. Determining that prefix depends on the size of the
  228. 1177 # network and should be incorporate the number of zones. So iterate
  229. 1178 # over potential number of subnets until enough can be created to
  230. 1179 # accommodate the number of available zones. That is where the fixed
  231. 1180 # number comes from in the for loop as that many iterations will yield
  232. 1181 # more potential subnets than any region has zones.
  233. 1182 ip_net = ipaddress.ip_network(AWSNetwork.CB_DEFAULT_IPV4RANGE)
  234. 1183 for x in range(5):
  235. 1184 if len(region.zones) <= len(list(ip_net.subnets(
  236. 1185 prefixlen_diff=x))):
  237. 1186 prefixlen_diff = x
  238. 1187 break
  239. 1188 subnets = list(ip_net.subnets(prefixlen_diff=prefixlen_diff))
  240. 1189
  241. 1190 for i, z in reversed(list(enumerate(region.zones))):
  242. 1191 sn_label = "{0}-{1}".format(AWSSubnet.CB_DEFAULT_SUBNET_LABEL,
  243. 1192 z.id[-1])
  244. 1193 log.info("Creating a default CloudBridge subnet %s: %s" %
  245. 1194 (sn_label, str(subnets[i])))
  246. 1195 sn = self.create(sn_label, default_net, str(subnets[i]), z)
  247. 1196 # Create a route table entry between the SN and the inet gateway
  248. 1197 # See note above about why this is commented
  249. 1198 # default_router.attach_subnet(sn)
  250. 1199 if zone and zone_name == z.name:
  251. 1200 default_sn = sn
  252. 1201 # No specific zone was supplied; return the last created subnet
  253. 1202 # The list was originally reversed to have the last subnet be in zone a
  254. 1203 if not default_sn:
  255. 1204 default_sn = sn
  256. 1205 return default_sn
  257. Total time: 1.08196 s
  258. Function: find at line 1061
  259. Line # Hits Time Per Hit % Time Line Contents
  260. ==============================================================
  261. 1061 @dispatch(event="provider.networking.subnets.find",
  262. 1062 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  263. 1063 @profile
  264. 1064 def find(self, network=None, **kwargs):
  265. 1065 3 6.0 2.0 0.0 label = kwargs.pop('label', None)
  266. 1066
  267. 1067 # All kwargs should have been popped at this time.
  268. 1068 3 4.0 1.3 0.0 if len(kwargs) > 0:
  269. 1069 raise InvalidParamException(
  270. 1070 "Unrecognised parameters for search: %s. Supported "
  271. 1071 "attributes: %s" % (kwargs, 'label'))
  272. 1072
  273. 1073 3 26.0 8.7 0.0 log.debug("Searching for AWS Subnet Service %s", label)
  274. 1074 3 1081928.0 360642.7 100.0 return self.svc.find(filter_name='tag:Name', filter_value=label)
  275. Total time: 0.915045 s
  276. Function: create at line 186
  277. Line # Hits Time Per Hit % Time Line Contents
  278. ==============================================================
  279. 186 @cb_helpers.deprecated_alias(network_id='network')
  280. 187 @dispatch(event="provider.security.vm_firewalls.create",
  281. 188 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  282. 189 @profile
  283. 190 def create(self, label, network, description=None):
  284. 191 2 17.0 8.5 0.0 AWSVMFirewall.assert_valid_resource_label(label)
  285. 192 2 89.0 44.5 0.0 name = AWSVMFirewall._generate_name_from_label(label, 'cb-fw')
  286. 193 2 3.0 1.5 0.0 network_id = network.id if isinstance(network, Network) else network
  287. 194 2 4.0 2.0 0.0 obj = self.svc.create('create_security_group', GroupName=name,
  288. 195 2 1.0 0.5 0.0 Description=name,
  289. 196 2 382090.0 191045.0 41.8 VpcId=network_id)
  290. 197 2 274942.0 137471.0 30.0 obj.label = label
  291. 198 2 257897.0 128948.5 28.2 obj.description = description
  292. 199 2 2.0 1.0 0.0 return obj
  293. Total time: 0.875675 s
  294. Function: delete at line 216
  295. Line # Hits Time Per Hit % Time Line Contents
  296. ==============================================================
  297. 216 @dispatch(event="provider.security.vm_firewalls.delete",
  298. 217 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  299. 218 @profile
  300. 219 def delete(self, vm_firewall):
  301. 220 2 4.0 2.0 0.0 firewall = (vm_firewall if isinstance(vm_firewall, AWSVMFirewall)
  302. 221 else self.get(vm_firewall))
  303. 222 2 1.0 0.5 0.0 if firewall:
  304. 223 # pylint:disable=protected-access
  305. 224 2 875670.0 437835.0 100.0 firewall._vm_firewall.delete()
  306. Total time: 0.874787 s
  307. Function: create at line 990
  308. Line # Hits Time Per Hit % Time Line Contents
  309. ==============================================================
  310. 990 @dispatch(event="provider.networking.networks.create",
  311. 991 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  312. 992 @profile
  313. 993 def create(self, label, cidr_block):
  314. 994 1 13.0 13.0 0.0 AWSNetwork.assert_valid_resource_label(label)
  315. 995
  316. 996 1 261299.0 261299.0 29.9 cb_net = self.svc.create('create_vpc', CidrBlock=cidr_block)
  317. 997 # Wait until ready to tag instance
  318. 998 1 458052.0 458052.0 52.4 cb_net.wait_till_ready()
  319. 999 1 1.0 1.0 0.0 if label:
  320. 1000 1 155421.0 155421.0 17.8 cb_net.label = label
  321. 1001 1 1.0 1.0 0.0 return cb_net
  322. Total time: 0.826672 s
  323. Function: delete at line 842
  324. Line # Hits Time Per Hit % Time Line Contents
  325. ==============================================================
  326. 842 @dispatch(event="provider.compute.instances.delete",
  327. 843 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  328. 844 @profile
  329. 845 def delete(self, instance):
  330. 846 4 8.0 2.0 0.0 aws_inst = (instance if isinstance(instance, AWSInstance) else
  331. 847 self.get(instance))
  332. 848 4 4.0 1.0 0.0 if aws_inst:
  333. 849 # pylint:disable=protected-access
  334. 850 4 826660.0 206665.0 100.0 aws_inst._ec2_instance.terminate()
  335. Total time: 0.725538 s
  336. Function: get at line 218
  337. Line # Hits Time Per Hit % Time Line Contents
  338. ==============================================================
  339. 218 @dispatch(event="provider.compute.vm_types.get",
  340. 219 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  341. 220 @profile
  342. 221 def get(self, vm_type_id):
  343. 222 1 5.0 5.0 0.0 vm_type = (t for t in self if t.id == vm_type_id)
  344. 223 1 725533.0 725533.0 100.0 return next(vm_type, None)
  345. Total time: 0.510209 s
  346. Function: get_or_create at line 1273
  347. Line # Hits Time Per Hit % Time Line Contents
  348. ==============================================================
  349. 1273 @dispatch(event="provider.networking.gateways.get_or_create",
  350. 1274 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  351. 1275 @profile
  352. 1276 def get_or_create(self, network):
  353. 1277 1 2.0 2.0 0.0 network_id = network.id if isinstance(
  354. 1278 1 6.0 6.0 0.0 network, AWSNetwork) else network
  355. 1279 # Don't filter by label because it may conflict with at least the
  356. 1280 # default VPC that most accounts have but that network is typically
  357. 1281 # without a name.
  358. 1282 1 2.0 2.0 0.0 gtw = self.svc.find(filter_name='attachment.vpc-id',
  359. 1283 1 97507.0 97507.0 19.1 filter_value=network_id)
  360. 1284 1 2.0 2.0 0.0 if gtw:
  361. 1285 return gtw[0] # There can be only one gtw attached to a VPC
  362. 1286 # Gateway does not exist so create one and attach to the supplied net
  363. 1287 1 135340.0 135340.0 26.5 cb_gateway = self.svc.create('create_internet_gateway')
  364. 1288 1 2.0 2.0 0.0 cb_gateway._gateway.create_tags(
  365. 1289 1 1.0 1.0 0.0 Tags=[{'Key': 'Name',
  366. 1290 1 154776.0 154776.0 30.3 'Value': AWSInternetGateway.CB_DEFAULT_INET_GATEWAY_NAME
  367. 1291 }])
  368. 1292 1 122570.0 122570.0 24.0 cb_gateway._gateway.attach_to_vpc(VpcId=network_id)
  369. 1293 1 1.0 1.0 0.0 return cb_gateway
  370. Total time: 0.478308 s
  371. Function: refresh at line 509
  372. Line # Hits Time Per Hit % Time Line Contents
  373. ==============================================================
  374. 509 @profile
  375. 510 def refresh(self):
  376. 511 5 19.0 3.8 0.0 try:
  377. 512 5 478276.0 95655.2 100.0 self._volume.reload()
  378. 513 5 13.0 2.6 0.0 self._unknown_state = False
  379. 514 except ClientError:
  380. 515 # The volume no longer exists and cannot be refreshed.
  381. 516 # set the status to unknown
  382. 517 self._unknown_state = True
  383. Total time: 0.454137 s
  384. Function: create at line 1076
  385. Line # Hits Time Per Hit % Time Line Contents
  386. ==============================================================
  387. 1076 @dispatch(event="provider.networking.subnets.create",
  388. 1077 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  389. 1078 @profile
  390. 1079 def create(self, label, network, cidr_block, zone):
  391. 1080 1 9.0 9.0 0.0 AWSSubnet.assert_valid_resource_label(label)
  392. 1081 1 1.0 1.0 0.0 zone_name = zone.name if isinstance(
  393. 1082 1 2.0 2.0 0.0 zone, AWSPlacementZone) else zone
  394. 1083
  395. 1084 1 6.0 6.0 0.0 network_id = network.id if isinstance(network, AWSNetwork) else network
  396. 1085
  397. 1086 1 3.0 3.0 0.0 subnet = self.svc.create('create_subnet',
  398. 1087 1 1.0 1.0 0.0 VpcId=network_id,
  399. 1088 1 0.0 0.0 0.0 CidrBlock=cidr_block,
  400. 1089 1 272957.0 272957.0 60.1 AvailabilityZone=zone_name)
  401. 1090 1 2.0 2.0 0.0 if label:
  402. 1091 1 181155.0 181155.0 39.9 subnet.label = label
  403. 1092 1 1.0 1.0 0.0 return subnet
  404. Total time: 0.407957 s
  405. Function: get at line 816
  406. Line # Hits Time Per Hit % Time Line Contents
  407. ==============================================================
  408. 816 @dispatch(event="provider.compute.instances.get",
  409. 817 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  410. 818 @profile
  411. 819 def get(self, instance_id):
  412. 820 3 407957.0 135985.7 100.0 return self.svc.get(instance_id)
  413. Total time: 0.401777 s
  414. Function: delete at line 1352
  415. Line # Hits Time Per Hit % Time Line Contents
  416. ==============================================================
  417. 1352 @dispatch(event="provider.networking.floating_ips.delete",
  418. 1353 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  419. 1354 @profile
  420. 1355 def delete(self, gateway, fip):
  421. 1356 1 5.0 5.0 0.0 if isinstance(fip, AWSFloatingIP):
  422. 1357 # pylint:disable=protected-access
  423. 1358 aws_fip = fip._ip
  424. 1359 else:
  425. 1360 1 224850.0 224850.0 56.0 aws_fip = self.svc.get_raw(fip)
  426. 1361 1 176922.0 176922.0 44.0 aws_fip.release()
  427. Total time: 0.38744 s
  428. Function: delete at line 1003
  429. Line # Hits Time Per Hit % Time Line Contents
  430. ==============================================================
  431. 1003 @dispatch(event="provider.networking.networks.delete",
  432. 1004 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  433. 1005 @profile
  434. 1006 def delete(self, network):
  435. 1007 1 3.0 3.0 0.0 network = (network if isinstance(network, AWSNetwork)
  436. 1008 else self.get(network))
  437. 1009 1 1.0 1.0 0.0 if network:
  438. 1010 # pylint:disable=protected-access
  439. 1011 1 387436.0 387436.0 100.0 network._vpc.delete()
  440. Total time: 0.35181 s
  441. Function: refresh at line 1038
  442. Line # Hits Time Per Hit % Time Line Contents
  443. ==============================================================
  444. 1038 @profile
  445. 1039 def refresh(self):
  446. 1040 2 351810.0 175905.0 100.0 self._ip.reload()
  447. Total time: 0.340546 s
  448. Function: delete at line 1094
  449. Line # Hits Time Per Hit % Time Line Contents
  450. ==============================================================
  451. 1094 @dispatch(event="provider.networking.subnets.delete",
  452. 1095 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  453. 1096 @profile
  454. 1097 def delete(self, subnet):
  455. 1098 1 2.0 2.0 0.0 sn = subnet if isinstance(subnet, AWSSubnet) else self.get(subnet)
  456. 1099 1 0.0 0.0 0.0 if sn:
  457. 1100 # pylint:disable=protected-access
  458. 1101 1 340544.0 340544.0 100.0 sn._subnet.delete()
  459. Total time: 0.277115 s
  460. Function: create at line 1244
  461. Line # Hits Time Per Hit % Time Line Contents
  462. ==============================================================
  463. 1244 @dispatch(event="provider.networking.routers.create",
  464. 1245 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  465. 1246 @profile
  466. 1247 def create(self, label, network):
  467. 1248 1 12.0 12.0 0.0 network_id = network.id if isinstance(network, AWSNetwork) else network
  468. 1249
  469. 1250 1 134758.0 134758.0 48.6 cb_router = self.svc.create('create_route_table', VpcId=network_id)
  470. 1251 1 1.0 1.0 0.0 if label:
  471. 1252 1 142343.0 142343.0 51.4 cb_router.label = label
  472. 1253 1 1.0 1.0 0.0 return cb_router
  473. Total time: 0.275631 s
  474. Function: create at line 1341
  475. Line # Hits Time Per Hit % Time Line Contents
  476. ==============================================================
  477. 1341 @dispatch(event="provider.networking.floating_ips.create",
  478. 1342 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  479. 1343 @profile
  480. 1344 def create(self, gateway):
  481. 1345 1 12.0 12.0 0.0 log.debug("Creating a floating IP under gateway %s", gateway)
  482. 1346 1 10.0 10.0 0.0 ip = self.provider.ec2_conn.meta.client.allocate_address(
  483. 1347 1 274365.0 274365.0 99.5 Domain='vpc')
  484. 1348 1 3.0 3.0 0.0 return AWSFloatingIP(
  485. 1349 1 3.0 3.0 0.0 self.provider,
  486. 1350 1 1238.0 1238.0 0.4 self.provider.ec2_conn.VpcAddress(ip.get('AllocationId')))
  487. Total time: 0.274904 s
  488. Function: label at line 640
  489. Line # Hits Time Per Hit % Time Line Contents
  490. ==============================================================
  491. 640 @label.setter
  492. 641 # pylint:disable=arguments-differ
  493. 642 @profile
  494. 643 def label(self, value):
  495. 644 2 18.0 9.0 0.0 self.assert_valid_resource_label(value)
  496. 645 2 2.0 1.0 0.0 self._vm_firewall.create_tags(Tags=[{'Key': 'Name',
  497. 646 2 274884.0 137442.0 100.0 'Value': value or ""}])
  498. Total time: 0.26292 s
  499. Function: refresh at line 930
  500. Line # Hits Time Per Hit % Time Line Contents
  501. ==============================================================
  502. 930 @profile
  503. 931 def refresh(self):
  504. 932 1 2.0 2.0 0.0 try:
  505. 933 1 262913.0 262913.0 100.0 self._vpc.reload()
  506. 934 1 5.0 5.0 0.0 self._unknown_state = False
  507. 935 except ClientError:
  508. 936 # The network no longer exists and cannot be refreshed.
  509. 937 # set the status to unknown
  510. 938 self._unknown_state = True
  511. Total time: 0.257867 s
  512. Function: description at line 655
  513. Line # Hits Time Per Hit % Time Line Contents
  514. ==============================================================
  515. 655 @description.setter
  516. 656 # pylint:disable=arguments-differ
  517. 657 @profile
  518. 658 def description(self, value):
  519. 659 2 3.0 1.5 0.0 self._vm_firewall.create_tags(Tags=[{'Key': 'Description',
  520. 660 2 257864.0 128932.0 100.0 'Value': value or ""}])
  521. Total time: 0.257728 s
  522. Function: get at line 633
  523. Line # Hits Time Per Hit % Time Line Contents
  524. ==============================================================
  525. 633 @profile
  526. 634 def get(self, image_id):
  527. 635 2 13.0 6.5 0.0 log.debug("Getting AWS Image Service with the id: %s", image_id)
  528. 636 2 257715.0 128857.5 100.0 return self.svc.get(image_id)
  529. Total time: 0.24604 s
  530. Function: delete at line 388
  531. Line # Hits Time Per Hit % Time Line Contents
  532. ==============================================================
  533. 388 @dispatch(event="provider.storage.volumes.delete",
  534. 389 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  535. 390 @profile
  536. 391 def delete(self, vol):
  537. 392 1 2.0 2.0 0.0 volume = vol if isinstance(vol, AWSVolume) else self.get(vol)
  538. 393 1 1.0 1.0 0.0 if volume:
  539. 394 # pylint:disable=protected-access
  540. 395 1 246037.0 246037.0 100.0 volume._volume.delete()
  541. Total time: 0.24311 s
  542. Function: find at line 822
  543. Line # Hits Time Per Hit % Time Line Contents
  544. ==============================================================
  545. 822 @dispatch(event="provider.compute.instances.find",
  546. 823 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  547. 824 @profile
  548. 825 def find(self, **kwargs):
  549. 826 3 6.0 2.0 0.0 label = kwargs.pop('label', None)
  550. 827
  551. 828 # All kwargs should have been popped at this time.
  552. 829 3 5.0 1.7 0.0 if len(kwargs) > 0:
  553. 830 1 0.0 0.0 0.0 raise InvalidParamException(
  554. 831 1 0.0 0.0 0.0 "Unrecognised parameters for search: %s. Supported "
  555. 832 1 12.0 12.0 0.0 "attributes: %s" % (kwargs, 'label'))
  556. 833
  557. 834 2 243087.0 121543.5 100.0 return self.svc.find(filter_name='tag:Name', filter_value=label)
  558. Total time: 0.217225 s
  559. Function: list at line 1049
  560. Line # Hits Time Per Hit % Time Line Contents
  561. ==============================================================
  562. 1049 @dispatch(event="provider.networking.subnets.list",
  563. 1050 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  564. 1051 @profile
  565. 1052 def list(self, network=None, limit=None, marker=None):
  566. 1053 1 18.0 18.0 0.0 network_id = network.id if isinstance(network, AWSNetwork) else network
  567. 1054 1 2.0 2.0 0.0 if network_id:
  568. 1055 1 7.0 7.0 0.0 return self.svc.find(
  569. 1056 1 1.0 1.0 0.0 filter_name='vpc-id', filter_value=network_id,
  570. 1057 1 217197.0 217197.0 100.0 limit=limit, marker=marker)
  571. 1058 else:
  572. 1059 return self.svc.list(limit=limit, marker=marker)
  573. Total time: 0.212642 s
  574. Function: create at line 134
  575. Line # Hits Time Per Hit % Time Line Contents
  576. ==============================================================
  577. 134 @dispatch(event="provider.security.key_pairs.create",
  578. 135 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  579. 136 @profile
  580. 137 def create(self, name, public_key_material=None):
  581. 138 1 9.0 9.0 0.0 AWSKeyPair.assert_valid_resource_name(name)
  582. 139 1 1.0 1.0 0.0 private_key = None
  583. 140 1 1.0 1.0 0.0 if not public_key_material:
  584. 141 1 76661.0 76661.0 36.1 public_key_material, private_key = cb_helpers.generate_key_pair()
  585. 142 1 2.0 2.0 0.0 try:
  586. 143 1 3.0 3.0 0.0 kp = self.svc.create('import_key_pair', KeyName=name,
  587. 144 1 135961.0 135961.0 63.9 PublicKeyMaterial=public_key_material)
  588. 145 1 4.0 4.0 0.0 kp.material = private_key
  589. 146 1 0.0 0.0 0.0 return kp
  590. 147 except ClientError as e:
  591. 148 if e.response['Error']['Code'] == 'InvalidKeyPair.Duplicate':
  592. 149 raise DuplicateResourceException(
  593. 150 'Keypair already exists with name {0}'.format(name))
  594. 151 else:
  595. 152 raise e
  596. Total time: 0.186605 s
  597. Function: refresh at line 593
  598. Line # Hits Time Per Hit % Time Line Contents
  599. ==============================================================
  600. 593 @profile
  601. 594 def refresh(self):
  602. 595 2 6.0 3.0 0.0 try:
  603. 596 2 186595.0 93297.5 100.0 self._snapshot.reload()
  604. 597 2 4.0 2.0 0.0 self._unknown_state = False
  605. 598 except ClientError:
  606. 599 # The snapshot no longer exists and cannot be refreshed.
  607. 600 # set the status to unknown
  608. 601 self._unknown_state = True
  609. Total time: 0.18114 s
  610. Function: label at line 975
  611. Line # Hits Time Per Hit % Time Line Contents
  612. ==============================================================
  613. 975 @label.setter
  614. 976 # pylint:disable=arguments-differ
  615. 977 @profile
  616. 978 def label(self, value):
  617. 979 1 7.0 7.0 0.0 self.assert_valid_resource_label(value)
  618. 980 1 181133.0 181133.0 100.0 self._subnet.create_tags(Tags=[{'Key': 'Name', 'Value': value or ""}])
  619. Total time: 0.172383 s
  620. Function: delete at line 1255
  621. Line # Hits Time Per Hit % Time Line Contents
  622. ==============================================================
  623. 1255 @dispatch(event="provider.networking.routers.delete",
  624. 1256 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  625. 1257 @profile
  626. 1258 def delete(self, router):
  627. 1259 1 3.0 3.0 0.0 r = router if isinstance(router, AWSRouter) else self.get(router)
  628. 1260 1 1.0 1.0 0.0 if r:
  629. 1261 # pylint:disable=protected-access
  630. 1262 1 172379.0 172379.0 100.0 r._route_table.delete()
  631. Total time: 0.167096 s
  632. Function: refresh at line 1069
  633. Line # Hits Time Per Hit % Time Line Contents
  634. ==============================================================
  635. 1069 @profile
  636. 1070 def refresh(self):
  637. 1071 2 3.0 1.5 0.0 try:
  638. 1072 2 167093.0 83546.5 100.0 self._route_table.reload()
  639. 1073 except ClientError:
  640. 1074 self._route_table.associations = None
  641. Total time: 0.155392 s
  642. Function: label at line 896
  643. Line # Hits Time Per Hit % Time Line Contents
  644. ==============================================================
  645. 896 @label.setter
  646. 897 # pylint:disable=arguments-differ
  647. 898 @profile
  648. 899 def label(self, value):
  649. 900 1 9.0 9.0 0.0 self.assert_valid_resource_label(value)
  650. 901 1 155383.0 155383.0 100.0 self._vpc.create_tags(Tags=[{'Key': 'Name', 'Value': value or ""}])
  651. Total time: 0.142324 s
  652. Function: label at line 1061
  653. Line # Hits Time Per Hit % Time Line Contents
  654. ==============================================================
  655. 1061 @label.setter
  656. 1062 # pylint:disable=arguments-differ
  657. 1063 @profile
  658. 1064 def label(self, value):
  659. 1065 1 11.0 11.0 0.0 self.assert_valid_resource_label(value)
  660. 1066 1 1.0 1.0 0.0 self._route_table.create_tags(Tags=[{'Key': 'Name',
  661. 1067 1 142312.0 142312.0 100.0 'Value': value or ""}])
  662. Total time: 0.137572 s
  663. Function: delete at line 154
  664. Line # Hits Time Per Hit % Time Line Contents
  665. ==============================================================
  666. 154 @dispatch(event="provider.security.key_pairs.delete",
  667. 155 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  668. 156 @profile
  669. 157 def delete(self, key_pair):
  670. 158 1 3.0 3.0 0.0 key_pair = (key_pair if isinstance(key_pair, AWSKeyPair) else
  671. 159 self.get(key_pair))
  672. 160 1 1.0 1.0 0.0 if key_pair:
  673. 161 # pylint:disable=protected-access
  674. 162 1 137568.0 137568.0 100.0 key_pair._key_pair.delete()
  675. Total time: 0.130891 s
  676. Function: list at line 232
  677. Line # Hits Time Per Hit % Time Line Contents
  678. ==============================================================
  679. 232 @dispatch(event="provider.security.vm_firewall_rules.list",
  680. 233 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  681. 234 @profile
  682. 235 def list(self, firewall, limit=None, marker=None):
  683. 236 # pylint:disable=protected-access
  684. 237 12 19.0 1.6 0.0 rules = [AWSVMFirewallRule(firewall,
  685. 238 TrafficDirection.INBOUND, r)
  686. 239 12 129948.0 10829.0 99.3 for r in firewall._vm_firewall.ip_permissions]
  687. 240 # pylint:disable=protected-access
  688. 241 12 14.0 1.2 0.0 rules = rules + [
  689. 242 12 17.0 1.4 0.0 AWSVMFirewallRule(
  690. 243 firewall, TrafficDirection.OUTBOUND, r)
  691. 244 12 527.0 43.9 0.4 for r in firewall._vm_firewall.ip_permissions_egress]
  692. 245 12 34.0 2.8 0.0 return ClientPagedResultList(self.provider, rules,
  693. 246 12 332.0 27.7 0.3 limit=limit, marker=marker)
  694. Total time: 0.12099 s
  695. Function: delete at line 452
  696. Line # Hits Time Per Hit % Time Line Contents
  697. ==============================================================
  698. 452 @dispatch(event="provider.storage.snapshots.delete",
  699. 453 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  700. 454 @profile
  701. 455 def delete(self, snapshot):
  702. 456 1 2.0 2.0 0.0 snapshot = (snapshot if isinstance(snapshot, AWSSnapshot) else
  703. 457 self.get(snapshot))
  704. 458 1 0.0 0.0 0.0 if snapshot:
  705. 459 # pylint:disable=protected-access
  706. 460 1 120988.0 120988.0 100.0 snapshot._snapshot.delete()
  707. Total time: 0.119243 s
  708. Function: delete at line 1295
  709. Line # Hits Time Per Hit % Time Line Contents
  710. ==============================================================
  711. 1295 @dispatch(event="provider.networking.gateways.delete",
  712. 1296 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  713. 1297 @profile
  714. 1298 def delete(self, network, gateway):
  715. 1299 1 2.0 2.0 0.0 gw = (gateway if isinstance(gateway, AWSInternetGateway)
  716. 1300 else self.svc.get(gateway))
  717. 1301 1 1.0 1.0 0.0 try:
  718. 1302 1 8.0 8.0 0.0 if gw.network_id:
  719. 1303 # pylint:disable=protected-access
  720. 1304 gw._gateway.detach_from_vpc(VpcId=gw.network_id)
  721. 1305 except ClientError as e:
  722. 1306 log.warn("Error deleting gateway {0}: {1}".format(self.id, e))
  723. 1307 # pylint:disable=protected-access
  724. 1308 1 119232.0 119232.0 100.0 gw._gateway.delete()
  725. Total time: 0.10803 s
  726. Function: label at line 426
  727. Line # Hits Time Per Hit % Time Line Contents
  728. ==============================================================
  729. 426 @label.setter
  730. 427 # pylint:disable=arguments-differ
  731. 428 @profile
  732. 429 def label(self, value):
  733. 430 1 9.0 9.0 0.0 self.assert_valid_resource_label(value)
  734. 431 1 108021.0 108021.0 100.0 self._volume.create_tags(Tags=[{'Key': 'Name', 'Value': value or ""}])
  735. Total time: 0.084704 s
  736. Function: get at line 963
  737. Line # Hits Time Per Hit % Time Line Contents
  738. ==============================================================
  739. 963 @dispatch(event="provider.networking.networks.get",
  740. 964 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  741. 965 @profile
  742. 966 def get(self, network_id):
  743. 967 1 84704.0 84704.0 100.0 return self.svc.get(network_id)
  744. Total time: 0.084315 s
  745. Function: get at line 896
  746. Line # Hits Time Per Hit % Time Line Contents
  747. ==============================================================
  748. 896 @dispatch(event="provider.compute.regions.get",
  749. 897 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  750. 898 @profile
  751. 899 def get(self, region_id):
  752. 900 1 2.0 2.0 0.0 log.debug("Getting AWS Region Service with the id: %s",
  753. 901 1 6.0 6.0 0.0 region_id)
  754. 902 1 84307.0 84307.0 100.0 region = [r for r in self if r.id == region_id]
  755. 903 1 0.0 0.0 0.0 if region:
  756. 904 1 0.0 0.0 0.0 return region[0]
  757. 905 else:
  758. 906 return None
  759. Total time: 0.073234 s
  760. Function: list at line 908
  761. Line # Hits Time Per Hit % Time Line Contents
  762. ==============================================================
  763. 908 @dispatch(event="provider.compute.regions.list",
  764. 909 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  765. 910 @profile
  766. 911 def list(self, limit=None, marker=None):
  767. 912 regions = [
  768. 913 1 20.0 20.0 0.0 AWSRegion(self.provider, region) for region in
  769. 914 1 73133.0 73133.0 99.9 self.provider.ec2_conn.meta.client.describe_regions()
  770. 915 1 52.0 52.0 0.1 .get('Regions', [])]
  771. 916 1 2.0 2.0 0.0 return ClientPagedResultList(self.provider, regions,
  772. 917 1 27.0 27.0 0.0 limit=limit, marker=marker)
  773. Total time: 2.1e-05 s
  774. Function: create_launch_config at line 765
  775. Line # Hits Time Per Hit % Time Line Contents
  776. ==============================================================
  777. 765 @profile
  778. 766 def create_launch_config(self):
  779. 767 2 21.0 10.5 100.0 return AWSLaunchConfig(self.provider)