interface.res 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470
  1. cloudbridge.test.test_interface.CloudInterfaceTestCase
  2. Test output
  3. ......
  4. ----------------------------------------------------------------------
  5. Ran 6 tests in 3.860s
  6. OK
  7. Wrote profile results to run_tests.py.lprof
  8. Timer unit: 1e-06 s
  9. Total time: 0.6384 s
  10. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  11. Function: __init__ at line 160
  12. Line # Hits Time Per Hit % Time Line Contents
  13. ==============================================================
  14. 160 @profile
  15. 161 def __init__(self, config):
  16. 162 2 7.0 3.5 0.0 self._config = config
  17. 163 2 5.0 2.5 0.0 self.subscription_id = str(config.get('azure_subscription_id'))
  18. 164 2 1.0 0.5 0.0 self._credentials = ServicePrincipalCredentials(
  19. 165 2 1.0 0.5 0.0 client_id=config.get('azure_client_id'),
  20. 166 2 2.0 1.0 0.0 secret=config.get('azure_secret'),
  21. 167 2 638344.0 319172.0 100.0 tenant=config.get('azure_tenant')
  22. 168 )
  23. 169
  24. 170 2 6.0 3.0 0.0 self._access_token = config.get('azure_access_token')
  25. 171 2 2.0 1.0 0.0 self._resource_client = None
  26. 172 2 2.0 1.0 0.0 self._storage_client = None
  27. 173 2 2.0 1.0 0.0 self._network_management_client = None
  28. 174 2 2.0 1.0 0.0 self._subscription_client = None
  29. 175 2 2.0 1.0 0.0 self._compute_client = None
  30. 176 2 2.0 1.0 0.0 self._access_key_result = None
  31. 177 2 3.0 1.5 0.0 self._block_blob_service = None
  32. 178 2 1.0 0.5 0.0 self._table_service = None
  33. 179 2 1.0 0.5 0.0 self._storage_account = None
  34. 180
  35. 181 2 17.0 8.5 0.0 log.debug("azure subscription : %s", self.subscription_id)
  36. Total time: 0.373592 s
  37. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  38. Function: access_key_result at line 183
  39. Line # Hits Time Per Hit % Time Line Contents
  40. ==============================================================
  41. 183 @property
  42. 184 @tenacity.retry(stop=tenacity.stop_after_attempt(5), reraise=True)
  43. 185 @profile
  44. 186 def access_key_result(self):
  45. 187 1 1.0 1.0 0.0 if not self._access_key_result:
  46. 188 1 3.0 3.0 0.0 storage_account = self.storage_account
  47. 189
  48. 190 1 153188.0 153188.0 41.0 if self.get_storage_account(storage_account).\
  49. 191 1 2.0 2.0 0.0 provisioning_state.value != 'Succeeded':
  50. 192 log.debug(
  51. 193 "Storage account %s is not in Succeeded state yet. ",
  52. 194 storage_account)
  53. 195 raise WaitStateException(
  54. 196 "Waited too long for storage account: {0} to "
  55. 197 "become ready.".format(
  56. 198 storage_account,
  57. 199 self.get_storage_account(storage_account).
  58. 200 provisioning_state))
  59. 201
  60. 202 1 212.0 212.0 0.1 self._access_key_result = self.storage_client.storage_accounts. \
  61. 203 1 220184.0 220184.0 58.9 list_keys(self.resource_group, storage_account)
  62. 204 1 2.0 2.0 0.0 return self._access_key_result
  63. Total time: 4e-06 s
  64. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  65. Function: resource_group at line 206
  66. Line # Hits Time Per Hit % Time Line Contents
  67. ==============================================================
  68. 206 @property
  69. 207 @profile
  70. 208 def resource_group(self):
  71. 209 3 4.0 1.3 100.0 return self._config.get('azure_resource_group')
  72. Total time: 4e-06 s
  73. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  74. Function: storage_account at line 211
  75. Line # Hits Time Per Hit % Time Line Contents
  76. ==============================================================
  77. 211 @property
  78. 212 @profile
  79. 213 def storage_account(self):
  80. 214 3 4.0 1.3 100.0 return self._config.get('azure_storage_account')
  81. Total time: 0 s
  82. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  83. Function: region_name at line 216
  84. Line # Hits Time Per Hit % Time Line Contents
  85. ==============================================================
  86. 216 @property
  87. 217 @profile
  88. 218 def region_name(self):
  89. 219 return self._config.get('azure_region_name')
  90. Total time: 3e-06 s
  91. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  92. Function: public_key_storage_table_name at line 221
  93. Line # Hits Time Per Hit % Time Line Contents
  94. ==============================================================
  95. 221 @property
  96. 222 @profile
  97. 223 def public_key_storage_table_name(self):
  98. 224 2 3.0 1.5 100.0 return self._config.get('azure_public_key_storage_table_name')
  99. Total time: 0.006364 s
  100. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  101. Function: storage_client at line 226
  102. Line # Hits Time Per Hit % Time Line Contents
  103. ==============================================================
  104. 226 @property
  105. 227 @profile
  106. 228 def storage_client(self):
  107. 229 3 5.0 1.7 0.1 if not self._storage_client:
  108. 230 self._storage_client = \
  109. 231 1 1.0 1.0 0.0 StorageManagementClient(self._credentials,
  110. 232 1 6354.0 6354.0 99.8 self.subscription_id)
  111. 233 3 4.0 1.3 0.1 return self._storage_client
  112. Total time: 0 s
  113. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  114. Function: subscription_client at line 235
  115. Line # Hits Time Per Hit % Time Line Contents
  116. ==============================================================
  117. 235 @property
  118. 236 @profile
  119. 237 def subscription_client(self):
  120. 238 if not self._subscription_client:
  121. 239 self._subscription_client = SubscriptionClient(self._credentials)
  122. 240 return self._subscription_client
  123. Total time: 0.025636 s
  124. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  125. Function: resource_client at line 242
  126. Line # Hits Time Per Hit % Time Line Contents
  127. ==============================================================
  128. 242 @property
  129. 243 @profile
  130. 244 def resource_client(self):
  131. 245 3 8.0 2.7 0.0 if not self._resource_client:
  132. 246 self._resource_client = \
  133. 247 2 2.0 1.0 0.0 ResourceManagementClient(self._credentials,
  134. 248 2 25619.0 12809.5 99.9 self.subscription_id)
  135. 249 3 7.0 2.3 0.0 return self._resource_client
  136. Total time: 0 s
  137. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  138. Function: compute_client at line 251
  139. Line # Hits Time Per Hit % Time Line Contents
  140. ==============================================================
  141. 251 @property
  142. 252 @profile
  143. 253 def compute_client(self):
  144. 254 if not self._compute_client:
  145. 255 self._compute_client = \
  146. 256 ComputeManagementClient(self._credentials,
  147. 257 self.subscription_id)
  148. 258 return self._compute_client
  149. Total time: 0 s
  150. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  151. Function: network_management_client at line 260
  152. Line # Hits Time Per Hit % Time Line Contents
  153. ==============================================================
  154. 260 @property
  155. 261 @profile
  156. 262 def network_management_client(self):
  157. 263 if not self._network_management_client:
  158. 264 self._network_management_client = NetworkManagementClient(
  159. 265 self._credentials, self.subscription_id)
  160. 266 return self._network_management_client
  161. Total time: 0 s
  162. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  163. Function: blob_service at line 268
  164. Line # Hits Time Per Hit % Time Line Contents
  165. ==============================================================
  166. 268 @property
  167. 269 @profile
  168. 270 def blob_service(self):
  169. 271 self._get_or_create_storage_account()
  170. 272 if not self._block_blob_service:
  171. 273 if self._access_token:
  172. 274 token_credential = TokenCredential(self._access_token)
  173. 275 self._block_blob_service = BlockBlobService(
  174. 276 account_name=self.storage_account,
  175. 277 token_credential=token_credential)
  176. 278 else:
  177. 279 self._block_blob_service = BlockBlobService(
  178. 280 account_name=self.storage_account,
  179. 281 account_key=self.access_key_result.keys[0].value)
  180. 282 return self._block_blob_service
  181. Total time: 1.07638 s
  182. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  183. Function: table_service at line 284
  184. Line # Hits Time Per Hit % Time Line Contents
  185. ==============================================================
  186. 284 @property
  187. 285 @profile
  188. 286 def table_service(self):
  189. 287 1 538972.0 538972.0 50.1 self._get_or_create_storage_account()
  190. 288 1 1.0 1.0 0.0 if not self._table_service:
  191. 289 1 4.0 4.0 0.0 self._table_service = TableService(
  192. 290 1 7.0 7.0 0.0 self.storage_account,
  193. 291 1 374051.0 374051.0 34.8 self.access_key_result.keys[0].value)
  194. 292 1 1.0 1.0 0.0 if not self._table_service. \
  195. 293 1 163345.0 163345.0 15.2 exists(table_name=self.public_key_storage_table_name):
  196. 294 self._table_service.create_table(
  197. 295 self.public_key_storage_table_name)
  198. 296 1 2.0 2.0 0.0 return self._table_service
  199. Total time: 0.706347 s
  200. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  201. Function: get_resource_group at line 298
  202. Line # Hits Time Per Hit % Time Line Contents
  203. ==============================================================
  204. 298 @profile
  205. 299 def get_resource_group(self, name):
  206. 300 3 706347.0 235449.0 100.0 return self.resource_client.resource_groups.get(name)
  207. Total time: 0 s
  208. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  209. Function: create_resource_group at line 302
  210. Line # Hits Time Per Hit % Time Line Contents
  211. ==============================================================
  212. 302 @profile
  213. 303 def create_resource_group(self, name, parameters):
  214. 304 return self.resource_client.resource_groups. \
  215. 305 create_or_update(name, parameters)
  216. Total time: 0.691958 s
  217. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  218. Function: get_storage_account at line 307
  219. Line # Hits Time Per Hit % Time Line Contents
  220. ==============================================================
  221. 307 @profile
  222. 308 def get_storage_account(self, storage_account):
  223. 309 2 261869.0 130934.5 37.8 return self.storage_client.storage_accounts. \
  224. 310 2 430089.0 215044.5 62.2 get_properties(self.resource_group, storage_account)
  225. Total time: 0 s
  226. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  227. Function: create_storage_account at line 312
  228. Line # Hits Time Per Hit % Time Line Contents
  229. ==============================================================
  230. 312 @profile
  231. 313 def create_storage_account(self, name, params):
  232. 314 return self.storage_client.storage_accounts. \
  233. 315 create(self.resource_group, name.lower(), params).result()
  234. Total time: 0.538814 s
  235. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  236. Function: _get_or_create_storage_account at line 319
  237. Line # Hits Time Per Hit % Time Line Contents
  238. ==============================================================
  239. 319 @tenacity.retry(stop=tenacity.stop_after_attempt(2),
  240. 320 retry=tenacity.retry_if_exception_type(CloudError),
  241. 321 reraise=True)
  242. 322 @profile
  243. 323 def _get_or_create_storage_account(self):
  244. 324 1 1.0 1.0 0.0 if self._storage_account:
  245. 325 return self._storage_account
  246. 326 else:
  247. 327 1 1.0 1.0 0.0 try:
  248. 328 self._storage_account = \
  249. 329 1 538812.0 538812.0 100.0 self.get_storage_account(self.storage_account)
  250. 330 except CloudError as cloud_error:
  251. 331 if cloud_error.error.error == "ResourceNotFound":
  252. 332 storage_account_params = {
  253. 333 'sku': {
  254. 334 'name': 'Standard_LRS'
  255. 335 },
  256. 336 'kind': 'storage',
  257. 337 'location': self.region_name,
  258. 338 }
  259. 339 try:
  260. 340 self._storage_account = \
  261. 341 self.create_storage_account(self.storage_account,
  262. 342 storage_account_params)
  263. 343 except CloudError as cloud_error2: # pragma: no cover
  264. 344 if cloud_error2.error.error == "AuthorizationFailed":
  265. 345 mess = 'The following error was returned by ' \
  266. 346 'Azure:\n%s\n\nThis is likely because the' \
  267. 347 ' Role associated with the provided ' \
  268. 348 'credentials does not allow for Storage ' \
  269. 349 'Account creation.\nA Storage Account is ' \
  270. 350 'necessary in order to perform the ' \
  271. 351 'desired operation. You must either ' \
  272. 352 'provide an existing Storage Account name' \
  273. 353 ' as part of the configuration, or ' \
  274. 354 'elevate the associated Role.\nFor more ' \
  275. 355 'information on roles, see: https://docs.' \
  276. 356 'microsoft.com/en-us/azure/role-based-' \
  277. 357 'access-control/overview\n' % cloud_error2
  278. 358 raise ProviderConnectionException(mess)
  279. 359
  280. 360 elif cloud_error2.error.error == \
  281. 361 "StorageAccountAlreadyTaken":
  282. 362 mess = 'The following error was ' \
  283. 363 'returned by Azure:\n%s\n\n' \
  284. 364 'Note that Storage Account names must be ' \
  285. 365 'unique across Azure (not just in your ' \
  286. 366 'subscription).\nFor more information ' \
  287. 367 'see https://docs.microsoft.com/en-us/' \
  288. 368 'azure/azure-resource-manager/resource-' \
  289. 369 'manager-storage-account-name-errors\n' \
  290. 370 % cloud_error2
  291. 371 raise InvalidLabelException(mess)
  292. 372 else:
  293. 373 raise cloud_error2
  294. 374 else:
  295. 375 raise cloud_error
  296. Total time: 0 s
  297. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  298. Function: list_locations at line 377
  299. Line # Hits Time Per Hit % Time Line Contents
  300. ==============================================================
  301. 377 @profile
  302. 378 def list_locations(self):
  303. 379 return self.subscription_client.subscriptions. \
  304. 380 list_locations(self.subscription_id)
  305. Total time: 0 s
  306. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  307. Function: list_vm_firewall at line 382
  308. Line # Hits Time Per Hit % Time Line Contents
  309. ==============================================================
  310. 382 @profile
  311. 383 def list_vm_firewall(self):
  312. 384 return self.network_management_client.network_security_groups. \
  313. 385 list(self.resource_group)
  314. Total time: 0 s
  315. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  316. Function: create_vm_firewall at line 387
  317. Line # Hits Time Per Hit % Time Line Contents
  318. ==============================================================
  319. 387 @profile
  320. 388 def create_vm_firewall(self, name, parameters):
  321. 389 return self.network_management_client.network_security_groups. \
  322. 390 create_or_update(self.resource_group, name,
  323. 391 parameters).result()
  324. Total time: 0 s
  325. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  326. Function: update_vm_firewall_tags at line 393
  327. Line # Hits Time Per Hit % Time Line Contents
  328. ==============================================================
  329. 393 @profile
  330. 394 def update_vm_firewall_tags(self, fw_id, tags):
  331. 395 url_params = azure_helpers.parse_url(VM_FIREWALL_RESOURCE_ID,
  332. 396 fw_id)
  333. 397 name = url_params.get(VM_FIREWALL_NAME)
  334. 398 return self.network_management_client.network_security_groups. \
  335. 399 create_or_update(self.resource_group, name,
  336. 400 {'tags': tags,
  337. 401 'location': self.region_name}).result()
  338. Total time: 0 s
  339. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  340. Function: get_vm_firewall at line 403
  341. Line # Hits Time Per Hit % Time Line Contents
  342. ==============================================================
  343. 403 @profile
  344. 404 def get_vm_firewall(self, fw_id):
  345. 405 url_params = azure_helpers.parse_url(VM_FIREWALL_RESOURCE_ID,
  346. 406 fw_id)
  347. 407 fw_name = url_params.get(VM_FIREWALL_NAME)
  348. 408 return self.network_management_client.network_security_groups. \
  349. 409 get(self.resource_group, fw_name)
  350. Total time: 0 s
  351. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  352. Function: delete_vm_firewall at line 411
  353. Line # Hits Time Per Hit % Time Line Contents
  354. ==============================================================
  355. 411 @profile
  356. 412 def delete_vm_firewall(self, fw_id):
  357. 413 url_params = azure_helpers.parse_url(VM_FIREWALL_RESOURCE_ID,
  358. 414 fw_id)
  359. 415 name = url_params.get(VM_FIREWALL_NAME)
  360. 416 self.network_management_client \
  361. 417 .network_security_groups.delete(self.resource_group, name).wait()
  362. Total time: 0 s
  363. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  364. Function: create_vm_firewall_rule at line 419
  365. Line # Hits Time Per Hit % Time Line Contents
  366. ==============================================================
  367. 419 @profile
  368. 420 def create_vm_firewall_rule(self, fw_id,
  369. 421 rule_name, parameters):
  370. 422 url_params = azure_helpers.parse_url(VM_FIREWALL_RESOURCE_ID,
  371. 423 fw_id)
  372. 424 vm_firewall_name = url_params.get(VM_FIREWALL_NAME)
  373. 425 return self.network_management_client.security_rules. \
  374. 426 create_or_update(self.resource_group, vm_firewall_name,
  375. 427 rule_name, parameters).result()
  376. Total time: 0 s
  377. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  378. Function: delete_vm_firewall_rule at line 429
  379. Line # Hits Time Per Hit % Time Line Contents
  380. ==============================================================
  381. 429 @profile
  382. 430 def delete_vm_firewall_rule(self, fw_rule_id, vm_firewall):
  383. 431 url_params = azure_helpers.parse_url(VM_FIREWALL_RULE_RESOURCE_ID,
  384. 432 fw_rule_id)
  385. 433 name = url_params.get(VM_FIREWALL_RULE_NAME)
  386. 434 return self.network_management_client.security_rules. \
  387. 435 delete(self.resource_group, vm_firewall, name).result()
  388. Total time: 0 s
  389. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  390. Function: list_containers at line 437
  391. Line # Hits Time Per Hit % Time Line Contents
  392. ==============================================================
  393. 437 @profile
  394. 438 def list_containers(self, prefix=None, limit=None, marker=None):
  395. 439 results = self.blob_service.list_containers(prefix=prefix,
  396. 440 num_results=limit,
  397. 441 marker=marker)
  398. 442 return (results.items, results.next_marker)
  399. Total time: 0 s
  400. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  401. Function: create_container at line 444
  402. Line # Hits Time Per Hit % Time Line Contents
  403. ==============================================================
  404. 444 @profile
  405. 445 def create_container(self, container_name):
  406. 446 try:
  407. 447 self.blob_service.create_container(container_name,
  408. 448 fail_on_exist=True)
  409. 449 except AzureConflictHttpError as cloud_error:
  410. 450 if cloud_error.error_code == "ContainerAlreadyExists":
  411. 451 msg = "The given Bucket name '%s' already exists. Please " \
  412. 452 "use the `get` or `find` method to get a reference to " \
  413. 453 "an existing Bucket, or specify a new Bucket name to " \
  414. 454 "create.\nNote that in Azure, Buckets are contained " \
  415. 455 "in Storage Accounts." % container_name
  416. 456 raise DuplicateResourceException(msg)
  417. 457
  418. 458 return self.blob_service.get_container_properties(container_name)
  419. Total time: 0 s
  420. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  421. Function: get_container at line 460
  422. Line # Hits Time Per Hit % Time Line Contents
  423. ==============================================================
  424. 460 @profile
  425. 461 def get_container(self, container_name):
  426. 462 return self.blob_service.get_container_properties(container_name)
  427. Total time: 0 s
  428. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  429. Function: delete_container at line 464
  430. Line # Hits Time Per Hit % Time Line Contents
  431. ==============================================================
  432. 464 @profile
  433. 465 def delete_container(self, container_name):
  434. 466 self.blob_service.delete_container(container_name)
  435. Total time: 0 s
  436. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  437. Function: list_blobs at line 468
  438. Line # Hits Time Per Hit % Time Line Contents
  439. ==============================================================
  440. 468 @profile
  441. 469 def list_blobs(self, container_name, prefix=None):
  442. 470 return self.blob_service.list_blobs(container_name, prefix=prefix)
  443. Total time: 0 s
  444. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  445. Function: get_blob at line 472
  446. Line # Hits Time Per Hit % Time Line Contents
  447. ==============================================================
  448. 472 @profile
  449. 473 def get_blob(self, container_name, blob_name):
  450. 474 return self.blob_service.get_blob_properties(container_name, blob_name)
  451. Total time: 0 s
  452. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  453. Function: create_blob_from_text at line 476
  454. Line # Hits Time Per Hit % Time Line Contents
  455. ==============================================================
  456. 476 @profile
  457. 477 def create_blob_from_text(self, container_name, blob_name, text):
  458. 478 self.blob_service.create_blob_from_text(container_name,
  459. 479 blob_name, text)
  460. Total time: 0 s
  461. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  462. Function: create_blob_from_file at line 481
  463. Line # Hits Time Per Hit % Time Line Contents
  464. ==============================================================
  465. 481 @profile
  466. 482 def create_blob_from_file(self, container_name, blob_name, file_path):
  467. 483 self.blob_service.create_blob_from_path(container_name,
  468. 484 blob_name, file_path)
  469. Total time: 0 s
  470. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  471. Function: delete_blob at line 486
  472. Line # Hits Time Per Hit % Time Line Contents
  473. ==============================================================
  474. 486 @profile
  475. 487 def delete_blob(self, container_name, blob_name):
  476. 488 self.blob_service.delete_blob(container_name, blob_name)
  477. Total time: 0 s
  478. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  479. Function: get_blob_url at line 490
  480. Line # Hits Time Per Hit % Time Line Contents
  481. ==============================================================
  482. 490 @profile
  483. 491 def get_blob_url(self, container_name, blob_name, expiry_time):
  484. 492 expiry_date = datetime.datetime.utcnow() + datetime.timedelta(
  485. 493 seconds=expiry_time)
  486. 494 sas = self.blob_service.generate_blob_shared_access_signature(
  487. 495 container_name, blob_name, permission=BlobPermissions.READ,
  488. 496 expiry=expiry_date)
  489. 497 return self.blob_service.make_blob_url(container_name, blob_name,
  490. 498 sas_token=sas)
  491. Total time: 0 s
  492. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  493. Function: get_blob_content at line 500
  494. Line # Hits Time Per Hit % Time Line Contents
  495. ==============================================================
  496. 500 @profile
  497. 501 def get_blob_content(self, container_name, blob_name):
  498. 502 out_stream = BytesIO()
  499. 503 self.blob_service.get_blob_to_stream(container_name,
  500. 504 blob_name, out_stream)
  501. 505 return out_stream
  502. Total time: 0 s
  503. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  504. Function: create_empty_disk at line 507
  505. Line # Hits Time Per Hit % Time Line Contents
  506. ==============================================================
  507. 507 @profile
  508. 508 def create_empty_disk(self, disk_name, params):
  509. 509 return self.compute_client.disks.create_or_update(
  510. 510 self.resource_group,
  511. 511 disk_name,
  512. 512 params
  513. 513 ).result()
  514. Total time: 0 s
  515. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  516. Function: create_snapshot_disk at line 515
  517. Line # Hits Time Per Hit % Time Line Contents
  518. ==============================================================
  519. 515 @profile
  520. 516 def create_snapshot_disk(self, disk_name, params):
  521. 517 return self.compute_client.disks.create_or_update(
  522. 518 self.resource_group,
  523. 519 disk_name,
  524. 520 params
  525. 521 ).result()
  526. Total time: 0 s
  527. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  528. Function: get_disk at line 523
  529. Line # Hits Time Per Hit % Time Line Contents
  530. ==============================================================
  531. 523 @profile
  532. 524 def get_disk(self, disk_id):
  533. 525 url_params = azure_helpers.parse_url(VOLUME_RESOURCE_ID,
  534. 526 disk_id)
  535. 527 disk_name = url_params.get(VOLUME_NAME)
  536. 528 return self.compute_client.disks.get(self.resource_group, disk_name)
  537. Total time: 0 s
  538. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  539. Function: list_disks at line 530
  540. Line # Hits Time Per Hit % Time Line Contents
  541. ==============================================================
  542. 530 @profile
  543. 531 def list_disks(self):
  544. 532 return self.compute_client.disks. \
  545. 533 list_by_resource_group(self.resource_group)
  546. Total time: 0 s
  547. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  548. Function: delete_disk at line 535
  549. Line # Hits Time Per Hit % Time Line Contents
  550. ==============================================================
  551. 535 @profile
  552. 536 def delete_disk(self, disk_id):
  553. 537 url_params = azure_helpers.parse_url(VOLUME_RESOURCE_ID,
  554. 538 disk_id)
  555. 539 disk_name = url_params.get(VOLUME_NAME)
  556. 540 self.compute_client.disks.delete(self.resource_group, disk_name).wait()
  557. Total time: 0 s
  558. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  559. Function: update_disk_tags at line 542
  560. Line # Hits Time Per Hit % Time Line Contents
  561. ==============================================================
  562. 542 @profile
  563. 543 def update_disk_tags(self, disk_id, tags):
  564. 544 url_params = azure_helpers.parse_url(VOLUME_RESOURCE_ID,
  565. 545 disk_id)
  566. 546 disk_name = url_params.get(VOLUME_NAME)
  567. 547 return self.compute_client.disks.update(
  568. 548 self.resource_group,
  569. 549 disk_name,
  570. 550 {'tags': tags},
  571. 551 raw=True
  572. 552 )
  573. Total time: 0 s
  574. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  575. Function: list_snapshots at line 554
  576. Line # Hits Time Per Hit % Time Line Contents
  577. ==============================================================
  578. 554 @profile
  579. 555 def list_snapshots(self):
  580. 556 return self.compute_client.snapshots. \
  581. 557 list_by_resource_group(self.resource_group)
  582. Total time: 0 s
  583. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  584. Function: get_snapshot at line 559
  585. Line # Hits Time Per Hit % Time Line Contents
  586. ==============================================================
  587. 559 @profile
  588. 560 def get_snapshot(self, snapshot_id):
  589. 561 url_params = azure_helpers.parse_url(SNAPSHOT_RESOURCE_ID,
  590. 562 snapshot_id)
  591. 563 snapshot_name = url_params.get(SNAPSHOT_NAME)
  592. 564 return self.compute_client.snapshots.get(self.resource_group,
  593. 565 snapshot_name)
  594. Total time: 0 s
  595. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  596. Function: create_snapshot at line 567
  597. Line # Hits Time Per Hit % Time Line Contents
  598. ==============================================================
  599. 567 @profile
  600. 568 def create_snapshot(self, snapshot_name, params):
  601. 569 return self.compute_client.snapshots.create_or_update(
  602. 570 self.resource_group,
  603. 571 snapshot_name,
  604. 572 params
  605. 573 ).result()
  606. Total time: 0 s
  607. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  608. Function: delete_snapshot at line 575
  609. Line # Hits Time Per Hit % Time Line Contents
  610. ==============================================================
  611. 575 @profile
  612. 576 def delete_snapshot(self, snapshot_id):
  613. 577 url_params = azure_helpers.parse_url(SNAPSHOT_RESOURCE_ID,
  614. 578 snapshot_id)
  615. 579 snapshot_name = url_params.get(SNAPSHOT_NAME)
  616. 580 self.compute_client.snapshots.delete(self.resource_group,
  617. 581 snapshot_name).wait()
  618. Total time: 0 s
  619. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  620. Function: update_snapshot_tags at line 583
  621. Line # Hits Time Per Hit % Time Line Contents
  622. ==============================================================
  623. 583 @profile
  624. 584 def update_snapshot_tags(self, snapshot_id, tags):
  625. 585 url_params = azure_helpers.parse_url(SNAPSHOT_RESOURCE_ID,
  626. 586 snapshot_id)
  627. 587 snapshot_name = url_params.get(SNAPSHOT_NAME)
  628. 588 return self.compute_client.snapshots.update(
  629. 589 self.resource_group,
  630. 590 snapshot_name,
  631. 591 {'tags': tags},
  632. 592 raw=True
  633. 593 )
  634. Total time: 0 s
  635. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  636. Function: is_gallery_image at line 595
  637. Line # Hits Time Per Hit % Time Line Contents
  638. ==============================================================
  639. 595 @profile
  640. 596 def is_gallery_image(self, image_id):
  641. 597 url_params = azure_helpers.parse_url(IMAGE_RESOURCE_ID,
  642. 598 image_id)
  643. 599 # If it is a gallery image, it will always have an offer
  644. 600 return 'offer' in url_params
  645. Total time: 0 s
  646. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  647. Function: create_image at line 602
  648. Line # Hits Time Per Hit % Time Line Contents
  649. ==============================================================
  650. 602 @profile
  651. 603 def create_image(self, name, params):
  652. 604 return self.compute_client.images. \
  653. 605 create_or_update(self.resource_group, name,
  654. 606 params).result()
  655. Total time: 0 s
  656. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  657. Function: delete_image at line 608
  658. Line # Hits Time Per Hit % Time Line Contents
  659. ==============================================================
  660. 608 @profile
  661. 609 def delete_image(self, image_id):
  662. 610 url_params = azure_helpers.parse_url(IMAGE_RESOURCE_ID,
  663. 611 image_id)
  664. 612 if not self.is_gallery_image(image_id):
  665. 613 name = url_params.get(IMAGE_NAME)
  666. 614 self.compute_client.images.delete(self.resource_group, name).wait()
  667. Total time: 0 s
  668. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  669. Function: list_images at line 616
  670. Line # Hits Time Per Hit % Time Line Contents
  671. ==============================================================
  672. 616 @profile
  673. 617 def list_images(self):
  674. 618 azure_images = list(self.compute_client.images.
  675. 619 list_by_resource_group(self.resource_group))
  676. 620 return azure_images
  677. Total time: 0 s
  678. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  679. Function: list_gallery_refs at line 622
  680. Line # Hits Time Per Hit % Time Line Contents
  681. ==============================================================
  682. 622 @profile
  683. 623 def list_gallery_refs(self):
  684. 624 return gallery_image_references
  685. Total time: 0 s
  686. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  687. Function: get_image at line 626
  688. Line # Hits Time Per Hit % Time Line Contents
  689. ==============================================================
  690. 626 @profile
  691. 627 def get_image(self, image_id):
  692. 628 url_params = azure_helpers.parse_url(IMAGE_RESOURCE_ID,
  693. 629 image_id)
  694. 630 if self.is_gallery_image(image_id):
  695. 631 return GalleryImageReference(publisher=url_params['publisher'],
  696. 632 offer=url_params['offer'],
  697. 633 sku=url_params['sku'],
  698. 634 version=url_params['version'])
  699. 635 else:
  700. 636 name = url_params.get(IMAGE_NAME)
  701. 637 return self.compute_client.images.get(self.resource_group, name)
  702. Total time: 0 s
  703. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  704. Function: update_image_tags at line 639
  705. Line # Hits Time Per Hit % Time Line Contents
  706. ==============================================================
  707. 639 @profile
  708. 640 def update_image_tags(self, image_id, tags):
  709. 641 url_params = azure_helpers.parse_url(IMAGE_RESOURCE_ID,
  710. 642 image_id)
  711. 643 if self.is_gallery_image(image_id):
  712. 644 return True
  713. 645 else:
  714. 646 name = url_params.get(IMAGE_NAME)
  715. 647 return self.compute_client.images. \
  716. 648 create_or_update(self.resource_group, name,
  717. 649 {
  718. 650 'tags': tags,
  719. 651 'location': self.region_name
  720. 652 }).result()
  721. Total time: 0 s
  722. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  723. Function: list_vm_types at line 654
  724. Line # Hits Time Per Hit % Time Line Contents
  725. ==============================================================
  726. 654 @profile
  727. 655 def list_vm_types(self):
  728. 656 return self.compute_client.virtual_machine_sizes. \
  729. 657 list(self.region_name)
  730. Total time: 0 s
  731. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  732. Function: list_networks at line 659
  733. Line # Hits Time Per Hit % Time Line Contents
  734. ==============================================================
  735. 659 @profile
  736. 660 def list_networks(self):
  737. 661 return self.network_management_client.virtual_networks.list(
  738. 662 self.resource_group)
  739. Total time: 0 s
  740. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  741. Function: get_network at line 664
  742. Line # Hits Time Per Hit % Time Line Contents
  743. ==============================================================
  744. 664 @profile
  745. 665 def get_network(self, network_id):
  746. 666 url_params = azure_helpers.parse_url(NETWORK_RESOURCE_ID,
  747. 667 network_id)
  748. 668 network_name = url_params.get(NETWORK_NAME)
  749. 669 return self.network_management_client.virtual_networks.get(
  750. 670 self.resource_group, network_name)
  751. Total time: 0 s
  752. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  753. Function: create_network at line 672
  754. Line # Hits Time Per Hit % Time Line Contents
  755. ==============================================================
  756. 672 @profile
  757. 673 def create_network(self, name, params):
  758. 674 return self.network_management_client.virtual_networks. \
  759. 675 create_or_update(self.resource_group,
  760. 676 name,
  761. 677 parameters=params).result()
  762. Total time: 0 s
  763. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  764. Function: delete_network at line 679
  765. Line # Hits Time Per Hit % Time Line Contents
  766. ==============================================================
  767. 679 @profile
  768. 680 def delete_network(self, network_id):
  769. 681 url_params = azure_helpers.parse_url(NETWORK_RESOURCE_ID, network_id)
  770. 682 network_name = url_params.get(NETWORK_NAME)
  771. 683 return self.network_management_client.virtual_networks. \
  772. 684 delete(self.resource_group, network_name).wait()
  773. Total time: 0 s
  774. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  775. Function: update_network_tags at line 686
  776. Line # Hits Time Per Hit % Time Line Contents
  777. ==============================================================
  778. 686 @profile
  779. 687 def update_network_tags(self, network_id, tags):
  780. 688 url_params = azure_helpers.parse_url(NETWORK_RESOURCE_ID, network_id)
  781. 689 network_name = url_params.get(NETWORK_NAME)
  782. 690 return self.network_management_client.virtual_networks. \
  783. 691 create_or_update(self.resource_group,
  784. 692 network_name, tags).result()
  785. Total time: 0 s
  786. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  787. Function: get_network_id_for_subnet at line 694
  788. Line # Hits Time Per Hit % Time Line Contents
  789. ==============================================================
  790. 694 @profile
  791. 695 def get_network_id_for_subnet(self, subnet_id):
  792. 696 url_params = azure_helpers.parse_url(SUBNET_RESOURCE_ID, subnet_id)
  793. 697 network_id = NETWORK_RESOURCE_ID[0]
  794. 698 for key, val in url_params.items():
  795. 699 network_id = network_id.replace("{" + key + "}", val)
  796. 700 return network_id
  797. Total time: 0 s
  798. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  799. Function: list_subnets at line 702
  800. Line # Hits Time Per Hit % Time Line Contents
  801. ==============================================================
  802. 702 @profile
  803. 703 def list_subnets(self, network_id):
  804. 704 url_params = azure_helpers.parse_url(NETWORK_RESOURCE_ID, network_id)
  805. 705 network_name = url_params.get(NETWORK_NAME)
  806. 706 return self.network_management_client.subnets. \
  807. 707 list(self.resource_group, network_name)
  808. Total time: 0 s
  809. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  810. Function: get_subnet at line 709
  811. Line # Hits Time Per Hit % Time Line Contents
  812. ==============================================================
  813. 709 @profile
  814. 710 def get_subnet(self, subnet_id):
  815. 711 url_params = azure_helpers.parse_url(SUBNET_RESOURCE_ID,
  816. 712 subnet_id)
  817. 713 network_name = url_params.get(NETWORK_NAME)
  818. 714 subnet_name = url_params.get(SUBNET_NAME)
  819. 715 return self.network_management_client.subnets. \
  820. 716 get(self.resource_group, network_name, subnet_name)
  821. Total time: 0 s
  822. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  823. Function: create_subnet at line 718
  824. Line # Hits Time Per Hit % Time Line Contents
  825. ==============================================================
  826. 718 @profile
  827. 719 def create_subnet(self, network_id, subnet_name, params):
  828. 720 url_params = azure_helpers.parse_url(NETWORK_RESOURCE_ID, network_id)
  829. 721 network_name = url_params.get(NETWORK_NAME)
  830. 722 result_create = self.network_management_client \
  831. 723 .subnets.create_or_update(
  832. 724 self.resource_group,
  833. 725 network_name,
  834. 726 subnet_name,
  835. 727 params
  836. 728 )
  837. 729 subnet_info = result_create.result()
  838. 730
  839. 731 return subnet_info
  840. Total time: 0 s
  841. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  842. Function: __if_subnet_in_use at line 733
  843. Line # Hits Time Per Hit % Time Line Contents
  844. ==============================================================
  845. 733 @profile
  846. 734 def __if_subnet_in_use(e):
  847. 735 # return True if the CloudError exception is due to subnet being in use
  848. 736 if isinstance(e, CloudError):
  849. 737 if e.error.error == "InUseSubnetCannotBeDeleted":
  850. 738 return True
  851. 739 return False
  852. Total time: 0 s
  853. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  854. Function: delete_subnet at line 741
  855. Line # Hits Time Per Hit % Time Line Contents
  856. ==============================================================
  857. 741 @tenacity.retry(stop=tenacity.stop_after_attempt(5),
  858. 742 retry=tenacity.retry_if_exception(__if_subnet_in_use),
  859. 743 wait=tenacity.wait_fixed(5),
  860. 744 reraise=True)
  861. 745 @profile
  862. 746 def delete_subnet(self, subnet_id):
  863. 747 url_params = azure_helpers.parse_url(SUBNET_RESOURCE_ID,
  864. 748 subnet_id)
  865. 749 network_name = url_params.get(NETWORK_NAME)
  866. 750 subnet_name = url_params.get(SUBNET_NAME)
  867. 751
  868. 752 try:
  869. 753 result_delete = self.network_management_client \
  870. 754 .subnets.delete(
  871. 755 self.resource_group,
  872. 756 network_name,
  873. 757 subnet_name
  874. 758 )
  875. 759 result_delete.wait()
  876. 760 except CloudError as cloud_error:
  877. 761 log.exception(cloud_error.message)
  878. 762 raise cloud_error
  879. Total time: 0 s
  880. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  881. Function: create_floating_ip at line 764
  882. Line # Hits Time Per Hit % Time Line Contents
  883. ==============================================================
  884. 764 @profile
  885. 765 def create_floating_ip(self, public_ip_name, public_ip_parameters):
  886. 766 return self.network_management_client.public_ip_addresses. \
  887. 767 create_or_update(self.resource_group,
  888. 768 public_ip_name,
  889. 769 public_ip_parameters).result()
  890. Total time: 0 s
  891. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  892. Function: get_floating_ip at line 771
  893. Line # Hits Time Per Hit % Time Line Contents
  894. ==============================================================
  895. 771 @profile
  896. 772 def get_floating_ip(self, public_ip_id):
  897. 773 url_params = azure_helpers.parse_url(PUBLIC_IP_RESOURCE_ID,
  898. 774 public_ip_id)
  899. 775 public_ip_name = url_params.get(PUBLIC_IP_NAME)
  900. 776 return self.network_management_client. \
  901. 777 public_ip_addresses.get(self.resource_group, public_ip_name)
  902. Total time: 0 s
  903. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  904. Function: delete_floating_ip at line 779
  905. Line # Hits Time Per Hit % Time Line Contents
  906. ==============================================================
  907. 779 @profile
  908. 780 def delete_floating_ip(self, public_ip_id):
  909. 781 url_params = azure_helpers.parse_url(PUBLIC_IP_RESOURCE_ID,
  910. 782 public_ip_id)
  911. 783 public_ip_name = url_params.get(PUBLIC_IP_NAME)
  912. 784 self.network_management_client. \
  913. 785 public_ip_addresses.delete(self.resource_group,
  914. 786 public_ip_name).wait()
  915. Total time: 0 s
  916. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  917. Function: update_fip_tags at line 788
  918. Line # Hits Time Per Hit % Time Line Contents
  919. ==============================================================
  920. 788 @profile
  921. 789 def update_fip_tags(self, fip_id, tags):
  922. 790 url_params = azure_helpers.parse_url(PUBLIC_IP_RESOURCE_ID,
  923. 791 fip_id)
  924. 792 fip_name = url_params.get(PUBLIC_IP_NAME)
  925. 793 self.network_management_client.public_ip_addresses. \
  926. 794 create_or_update(self.resource_group,
  927. 795 fip_name, tags).result()
  928. Total time: 0 s
  929. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  930. Function: list_floating_ips at line 797
  931. Line # Hits Time Per Hit % Time Line Contents
  932. ==============================================================
  933. 797 @profile
  934. 798 def list_floating_ips(self):
  935. 799 return self.network_management_client.public_ip_addresses.list(
  936. 800 self.resource_group)
  937. Total time: 0 s
  938. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  939. Function: list_vm at line 802
  940. Line # Hits Time Per Hit % Time Line Contents
  941. ==============================================================
  942. 802 @profile
  943. 803 def list_vm(self):
  944. 804 return self.compute_client.virtual_machines.list(
  945. 805 self.resource_group
  946. 806 )
  947. Total time: 0 s
  948. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  949. Function: restart_vm at line 808
  950. Line # Hits Time Per Hit % Time Line Contents
  951. ==============================================================
  952. 808 @profile
  953. 809 def restart_vm(self, vm_id):
  954. 810 url_params = azure_helpers.parse_url(VM_RESOURCE_ID,
  955. 811 vm_id)
  956. 812 vm_name = url_params.get(VM_NAME)
  957. 813 return self.compute_client.virtual_machines.restart(
  958. 814 self.resource_group, vm_name).wait()
  959. Total time: 0 s
  960. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  961. Function: delete_vm at line 816
  962. Line # Hits Time Per Hit % Time Line Contents
  963. ==============================================================
  964. 816 @profile
  965. 817 def delete_vm(self, vm_id):
  966. 818 url_params = azure_helpers.parse_url(VM_RESOURCE_ID,
  967. 819 vm_id)
  968. 820 vm_name = url_params.get(VM_NAME)
  969. 821 return self.compute_client.virtual_machines.delete(
  970. 822 self.resource_group, vm_name).wait()
  971. Total time: 0 s
  972. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  973. Function: get_vm at line 824
  974. Line # Hits Time Per Hit % Time Line Contents
  975. ==============================================================
  976. 824 @profile
  977. 825 def get_vm(self, vm_id):
  978. 826 url_params = azure_helpers.parse_url(VM_RESOURCE_ID,
  979. 827 vm_id)
  980. 828 vm_name = url_params.get(VM_NAME)
  981. 829 return self.compute_client.virtual_machines.get(
  982. 830 self.resource_group,
  983. 831 vm_name,
  984. 832 expand='instanceView'
  985. 833 )
  986. Total time: 0 s
  987. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  988. Function: create_vm at line 835
  989. Line # Hits Time Per Hit % Time Line Contents
  990. ==============================================================
  991. 835 @profile
  992. 836 def create_vm(self, vm_name, params):
  993. 837 return self.compute_client.virtual_machines. \
  994. 838 create_or_update(self.resource_group,
  995. 839 vm_name, params).result()
  996. Total time: 0 s
  997. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  998. Function: update_vm at line 841
  999. Line # Hits Time Per Hit % Time Line Contents
  1000. ==============================================================
  1001. 841 @profile
  1002. 842 def update_vm(self, vm_id, params):
  1003. 843 url_params = azure_helpers.parse_url(VM_RESOURCE_ID,
  1004. 844 vm_id)
  1005. 845 vm_name = url_params.get(VM_NAME)
  1006. 846 return self.compute_client.virtual_machines. \
  1007. 847 create_or_update(self.resource_group,
  1008. 848 vm_name, params, raw=True)
  1009. Total time: 0 s
  1010. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1011. Function: deallocate_vm at line 850
  1012. Line # Hits Time Per Hit % Time Line Contents
  1013. ==============================================================
  1014. 850 @profile
  1015. 851 def deallocate_vm(self, vm_id):
  1016. 852 url_params = azure_helpers.parse_url(VM_RESOURCE_ID,
  1017. 853 vm_id)
  1018. 854 vm_name = url_params.get(VM_NAME)
  1019. 855 self.compute_client. \
  1020. 856 virtual_machines.deallocate(self.resource_group,
  1021. 857 vm_name).wait()
  1022. Total time: 0 s
  1023. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1024. Function: generalize_vm at line 859
  1025. Line # Hits Time Per Hit % Time Line Contents
  1026. ==============================================================
  1027. 859 @profile
  1028. 860 def generalize_vm(self, vm_id):
  1029. 861 url_params = azure_helpers.parse_url(VM_RESOURCE_ID,
  1030. 862 vm_id)
  1031. 863 vm_name = url_params.get(VM_NAME)
  1032. 864 self.compute_client.virtual_machines. \
  1033. 865 generalize(self.resource_group, vm_name)
  1034. Total time: 0 s
  1035. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1036. Function: start_vm at line 867
  1037. Line # Hits Time Per Hit % Time Line Contents
  1038. ==============================================================
  1039. 867 @profile
  1040. 868 def start_vm(self, vm_id):
  1041. 869 url_params = azure_helpers.parse_url(VM_RESOURCE_ID,
  1042. 870 vm_id)
  1043. 871 vm_name = url_params.get(VM_NAME)
  1044. 872 self.compute_client.virtual_machines. \
  1045. 873 start(self.resource_group,
  1046. 874 vm_name).wait()
  1047. Total time: 0 s
  1048. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1049. Function: update_vm_tags at line 876
  1050. Line # Hits Time Per Hit % Time Line Contents
  1051. ==============================================================
  1052. 876 @profile
  1053. 877 def update_vm_tags(self, vm_id, tags):
  1054. 878 url_params = azure_helpers.parse_url(VM_RESOURCE_ID,
  1055. 879 vm_id)
  1056. 880 vm_name = url_params.get(VM_NAME)
  1057. 881 self.compute_client.virtual_machines. \
  1058. 882 create_or_update(self.resource_group,
  1059. 883 vm_name, tags).result()
  1060. Total time: 0 s
  1061. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1062. Function: delete_nic at line 885
  1063. Line # Hits Time Per Hit % Time Line Contents
  1064. ==============================================================
  1065. 885 @profile
  1066. 886 def delete_nic(self, nic_id):
  1067. 887 nic_params = azure_helpers.\
  1068. 888 parse_url(NETWORK_INTERFACE_RESOURCE_ID, nic_id)
  1069. 889 nic_name = nic_params.get(NETWORK_INTERFACE_NAME)
  1070. 890 self.network_management_client. \
  1071. 891 network_interfaces.delete(self.resource_group,
  1072. 892 nic_name).wait()
  1073. Total time: 0 s
  1074. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1075. Function: get_nic at line 894
  1076. Line # Hits Time Per Hit % Time Line Contents
  1077. ==============================================================
  1078. 894 @profile
  1079. 895 def get_nic(self, nic_id):
  1080. 896 nic_params = azure_helpers.\
  1081. 897 parse_url(NETWORK_INTERFACE_RESOURCE_ID, nic_id)
  1082. 898 nic_name = nic_params.get(NETWORK_INTERFACE_NAME)
  1083. 899 return self.network_management_client. \
  1084. 900 network_interfaces.get(self.resource_group, nic_name)
  1085. Total time: 0 s
  1086. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1087. Function: update_nic at line 902
  1088. Line # Hits Time Per Hit % Time Line Contents
  1089. ==============================================================
  1090. 902 @profile
  1091. 903 def update_nic(self, nic_id, params):
  1092. 904 nic_params = azure_helpers.\
  1093. 905 parse_url(NETWORK_INTERFACE_RESOURCE_ID, nic_id)
  1094. 906 nic_name = nic_params.get(NETWORK_INTERFACE_NAME)
  1095. 907 async_nic_creation = self.network_management_client. \
  1096. 908 network_interfaces.create_or_update(
  1097. 909 self.resource_group,
  1098. 910 nic_name,
  1099. 911 params
  1100. 912 )
  1101. 913 nic_info = async_nic_creation.result()
  1102. 914 return nic_info
  1103. Total time: 0 s
  1104. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1105. Function: create_nic at line 916
  1106. Line # Hits Time Per Hit % Time Line Contents
  1107. ==============================================================
  1108. 916 @profile
  1109. 917 def create_nic(self, nic_name, params):
  1110. 918 return self.network_management_client. \
  1111. 919 network_interfaces.create_or_update(
  1112. 920 self.resource_group,
  1113. 921 nic_name,
  1114. 922 params
  1115. 923 ).result()
  1116. Total time: 0 s
  1117. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1118. Function: create_public_key at line 925
  1119. Line # Hits Time Per Hit % Time Line Contents
  1120. ==============================================================
  1121. 925 @profile
  1122. 926 def create_public_key(self, entity):
  1123. 927 return self.table_service. \
  1124. 928 insert_or_replace_entity(self.public_key_storage_table_name,
  1125. 929 entity)
  1126. Total time: 0 s
  1127. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1128. Function: get_public_key at line 931
  1129. Line # Hits Time Per Hit % Time Line Contents
  1130. ==============================================================
  1131. 931 @profile
  1132. 932 def get_public_key(self, name):
  1133. 933 entities = self.table_service. \
  1134. 934 query_entities(self.public_key_storage_table_name,
  1135. 935 "Name eq '{0}'".format(name), num_results=1)
  1136. 936
  1137. 937 return entities.items[0] if len(entities.items) > 0 else None
  1138. Total time: 0 s
  1139. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1140. Function: delete_public_key at line 939
  1141. Line # Hits Time Per Hit % Time Line Contents
  1142. ==============================================================
  1143. 939 @profile
  1144. 940 def delete_public_key(self, entity):
  1145. 941 self.table_service.delete_entity(self.public_key_storage_table_name,
  1146. 942 entity.PartitionKey, entity.RowKey)
  1147. Total time: 1.13503 s
  1148. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1149. Function: list_public_keys at line 944
  1150. Line # Hits Time Per Hit % Time Line Contents
  1151. ==============================================================
  1152. 944 @profile
  1153. 945 def list_public_keys(self, partition_key, limit=None, marker=None):
  1154. 946 1 1076407.0 1076407.0 94.8 entities = self.table_service. \
  1155. 947 1 8.0 8.0 0.0 query_entities(self.public_key_storage_table_name,
  1156. 948 1 2.0 2.0 0.0 "PartitionKey eq '{0}'".format(partition_key),
  1157. 949 1 58613.0 58613.0 5.2 marker=marker, num_results=limit)
  1158. 950 1 2.0 2.0 0.0 return (entities.items, entities.next_marker)
  1159. Total time: 0 s
  1160. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1161. Function: delete_route_table at line 952
  1162. Line # Hits Time Per Hit % Time Line Contents
  1163. ==============================================================
  1164. 952 @profile
  1165. 953 def delete_route_table(self, route_table_name):
  1166. 954 self.network_management_client. \
  1167. 955 route_tables.delete(self.resource_group, route_table_name
  1168. 956 ).wait()
  1169. Total time: 0 s
  1170. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1171. Function: attach_subnet_to_route_table at line 958
  1172. Line # Hits Time Per Hit % Time Line Contents
  1173. ==============================================================
  1174. 958 @profile
  1175. 959 def attach_subnet_to_route_table(self, subnet_id, route_table_id):
  1176. 960 url_params = azure_helpers.parse_url(SUBNET_RESOURCE_ID,
  1177. 961 subnet_id)
  1178. 962 network_name = url_params.get(NETWORK_NAME)
  1179. 963 subnet_name = url_params.get(SUBNET_NAME)
  1180. 964
  1181. 965 subnet_info = self.network_management_client.subnets.get(
  1182. 966 self.resource_group,
  1183. 967 network_name,
  1184. 968 subnet_name
  1185. 969 )
  1186. 970 if subnet_info:
  1187. 971 subnet_info.route_table = {
  1188. 972 'id': route_table_id
  1189. 973 }
  1190. 974
  1191. 975 result_create = self.network_management_client. \
  1192. 976 subnets.create_or_update(
  1193. 977 self.resource_group,
  1194. 978 network_name,
  1195. 979 subnet_name,
  1196. 980 subnet_info)
  1197. 981 subnet_info = result_create.result()
  1198. 982
  1199. 983 return subnet_info
  1200. Total time: 0 s
  1201. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1202. Function: detach_subnet_to_route_table at line 985
  1203. Line # Hits Time Per Hit % Time Line Contents
  1204. ==============================================================
  1205. 985 @profile
  1206. 986 def detach_subnet_to_route_table(self, subnet_id, route_table_id):
  1207. 987 url_params = azure_helpers.parse_url(SUBNET_RESOURCE_ID,
  1208. 988 subnet_id)
  1209. 989 network_name = url_params.get(NETWORK_NAME)
  1210. 990 subnet_name = url_params.get(SUBNET_NAME)
  1211. 991
  1212. 992 subnet_info = self.network_management_client.subnets.get(
  1213. 993 self.resource_group,
  1214. 994 network_name,
  1215. 995 subnet_name
  1216. 996 )
  1217. 997
  1218. 998 if subnet_info and subnet_info.route_table.id == route_table_id:
  1219. 999 subnet_info.route_table = None
  1220. 1000
  1221. 1001 result_create = self.network_management_client. \
  1222. 1002 subnets.create_or_update(
  1223. 1003 self.resource_group,
  1224. 1004 network_name,
  1225. 1005 subnet_name,
  1226. 1006 subnet_info)
  1227. 1007 subnet_info = result_create.result()
  1228. 1008
  1229. 1009 return subnet_info
  1230. Total time: 0 s
  1231. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1232. Function: list_route_tables at line 1011
  1233. Line # Hits Time Per Hit % Time Line Contents
  1234. ==============================================================
  1235. 1011 @profile
  1236. 1012 def list_route_tables(self):
  1237. 1013 return self.network_management_client. \
  1238. 1014 route_tables.list(self.resource_group)
  1239. Total time: 0 s
  1240. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1241. Function: get_route_table at line 1016
  1242. Line # Hits Time Per Hit % Time Line Contents
  1243. ==============================================================
  1244. 1016 @profile
  1245. 1017 def get_route_table(self, router_id):
  1246. 1018 url_params = azure_helpers.parse_url(ROUTER_RESOURCE_ID,
  1247. 1019 router_id)
  1248. 1020 router_name = url_params.get(ROUTER_NAME)
  1249. 1021 return self.network_management_client. \
  1250. 1022 route_tables.get(self.resource_group, router_name)
  1251. Total time: 0 s
  1252. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1253. Function: create_route_table at line 1024
  1254. Line # Hits Time Per Hit % Time Line Contents
  1255. ==============================================================
  1256. 1024 @profile
  1257. 1025 def create_route_table(self, route_table_name, params):
  1258. 1026 return self.network_management_client. \
  1259. 1027 route_tables.create_or_update(
  1260. 1028 self.resource_group,
  1261. 1029 route_table_name, params).result()
  1262. Total time: 0 s
  1263. File: /Users/alex/Desktop/work/cb-profiled/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py
  1264. Function: update_route_table_tags at line 1031
  1265. Line # Hits Time Per Hit % Time Line Contents
  1266. ==============================================================
  1267. 1031 @profile
  1268. 1032 def update_route_table_tags(self, route_table_name, tags):
  1269. 1033 self.network_management_client.route_tables. \
  1270. 1034 create_or_update(self.resource_group,
  1271. 1035 route_table_name, tags).result()