@@ -48,15 +48,6 @@ class AzureDeploymentService(Service, metaclass=abc.ABCMeta):
48
48
"?api-version=2022-05-01"
49
49
)
50
50
51
- _URL_ASSIGN_IDENTITY = (
52
- "https://management.azure.com" +
53
- "/subscriptions/{subscription}" +
54
- "/resourceGroups/{resource_group}" +
55
- "/providers/Microsoft.Compute" +
56
- "/virtualMachines/{vm_name}" +
57
- "?api-version=2022-03-01"
58
- )
59
-
60
51
def __init__ (self ,
61
52
config : Optional [Dict [str , Any ]] = None ,
62
53
global_config : Optional [Dict [str , Any ]] = None ,
@@ -82,7 +73,6 @@ def __init__(self,
82
73
check_required_params (self .config , [
83
74
"subscription" ,
84
75
"resourceGroup" ,
85
- "managedIdentityName"
86
76
])
87
77
88
78
# These parameters can come from command line as strings, so conversion is needed.
@@ -402,101 +392,6 @@ def _check_deployment(self, params: dict) -> Tuple[Status, dict]: # pylint: di
402
392
_LOG .error ("Response: %s :: %s" , response , response .text )
403
393
return (Status .FAILED , {})
404
394
405
- def _wait_host_managed_identity_assignment (self , params : dict ) -> Tuple [Status , dict ]:
406
- """
407
- Waits for a pending operation on an Azure resource to resolve to SUCCEEDED or FAILED.
408
- Return TIMED_OUT when timing out.
409
-
410
- Parameters
411
- ----------
412
- params : dict
413
- Flat dictionary of (key, value) pairs of tunable parameters.
414
-
415
- Returns
416
- -------
417
- result : (Status, dict)
418
- A pair of Status and result.
419
- Status is one of {PENDING, SUCCEEDED, FAILED, TIMED_OUT}
420
- Result is info on the operation runtime if SUCCEEDED, otherwise {}.
421
- """
422
- params = self ._set_default_params (params )
423
- _LOG .info ("Wait for %s to %s" , self ._deploy_params ["vmName" ], "be assigned managed identity" )
424
- return self ._wait_while (self ._check_managed_identity_assinment , Status .PENDING , params )
425
-
426
- def _check_managed_identity_assinment (self , params : dict ) -> Tuple [Status , dict ]: # pylint: disable=too-many-return-statements
427
- """
428
- Check if the identity is assigned to the VM.
429
- Return SUCCEEDED if true, PENDING otherwise.
430
-
431
- Parameters
432
- ----------
433
- _params : dict
434
- Flat dictionary of (key, value) pairs of tunable parameters.
435
- This parameter is not used; we need it for compatibility with
436
- other polling functions used in `_wait_while()`.
437
-
438
- Returns
439
- -------
440
- result : (Status, dict={})
441
- A pair of Status and result. The result is always {}.
442
- Status is one of {SUCCEEDED, PENDING, FAILED}
443
- """
444
- params = self ._set_default_params (params )
445
- config = merge_parameters (
446
- dest = self .config .copy (),
447
- source = params ,
448
- required_keys = [
449
- "subscription" ,
450
- "resourceGroup" ,
451
- "managedIdentityName" ,
452
- ]
453
- )
454
-
455
- vmName = self ._deploy_params ["vmName" ]
456
- subscriptionId = config ["subscription" ]
457
- resourceGroup = config ["resourceGroup" ]
458
- managedIdentityName = config ["managedIdentityName" ]
459
-
460
- _LOG .info ("Check identity assignment: %s" , vmName )
461
-
462
- url = self ._URL_ASSIGN_IDENTITY .format (
463
- subscription = subscriptionId ,
464
- resource_group = resourceGroup ,
465
- vm_name = vmName ,
466
- )
467
-
468
- session = self ._get_session (params )
469
- try :
470
- response = session .get (url , timeout = self ._request_timeout )
471
- except requests .exceptions .ReadTimeout :
472
- _LOG .warning ("Request timed out after %.2f s: %s" , self ._request_timeout , url )
473
- return Status .RUNNING , {}
474
- except requests .exceptions .RequestException as ex :
475
- _LOG .exception ("Error in request checking deployment" , exc_info = ex )
476
- return (Status .FAILED , {})
477
-
478
- _LOG .debug ("Response: %s" , response )
479
-
480
- if response .status_code == 200 :
481
- output = response .json ()
482
- state = output .get ("properties" , {}).get ("provisioningState" , "" )
483
- print ("state" , state )
484
-
485
- print (output )
486
- mid = f"/subscriptions/{ subscriptionId } /resourceGroups/{ resourceGroup } /providers/Microsoft.ManagedIdentity/userAssignedIdentities/{ managedIdentityName } "
487
- if state == "Succeeded" and "identity" in output and mid in output ["identity" ]["userAssignedIdentities" ]:
488
- return (Status .SUCCEEDED , {})
489
- elif state in {"Accepted" , "Creating" , "Deleting" , "Running" , "Updating" }:
490
- return (Status .PENDING , {})
491
- else :
492
- _LOG .error ("Response: %s :: %s" , response , json .dumps (output , indent = 2 ))
493
- return (Status .FAILED , {})
494
- elif response .status_code == 404 :
495
- return (Status .PENDING , {})
496
-
497
- _LOG .error ("Response: %s :: %s" , response , response .text )
498
- return (Status .FAILED , {})
499
-
500
395
def _provision_resource (self , params : dict ) -> Tuple [Status , dict ]:
501
396
"""
502
397
Attempts to (re)deploy a resource.
@@ -570,74 +465,3 @@ def _provision_resource(self, params: dict) -> Tuple[Status, dict]:
570
465
_LOG .error ("Response: %s :: %s" , response , response .text )
571
466
# _LOG.error("Bad Request:\n%s", response.request.body)
572
467
return (Status .FAILED , {})
573
-
574
- def _assign_managed_identity (self , params : dict ) -> Tuple [Status , dict ]:
575
- """
576
- Attempts to assign a managed identity to resource.
577
-
578
- Parameters
579
- ----------
580
- params : dict
581
- Flat dictionary of (key, value) pairs of tunable parameters.
582
- Tunables are variable parameters that, together with the
583
- Environment configuration, are sufficient to provision the resource.
584
-
585
- Returns
586
- -------
587
- result : (Status, dict={})
588
- A pair of Status and result. The result is the input `params` plus the
589
- parameters extracted from the response JSON, or {} if the status is FAILED.
590
- Status is one of {PENDING, SUCCEEDED, FAILED}
591
- """
592
- params = self ._set_default_params (params )
593
- config = merge_parameters (dest = self .config .copy (), source = params )
594
-
595
- vmName = self ._deploy_params ["vmName" ]
596
- subscriptionId = config ["subscription" ]
597
- resourceGroup = config ["resourceGroup" ]
598
- managedIdentityName = config ["managedIdentityName" ]
599
-
600
- _LOG .info ("Assign managed identity: %s :: %s" , vmName , params )
601
-
602
- url = self ._URL_ASSIGN_IDENTITY .format (
603
- subscription = subscriptionId ,
604
- resource_group = resourceGroup ,
605
- vm_name = vmName ,
606
- )
607
-
608
- json_req = {
609
- "identity" : {
610
- "type" : "UserAssigned" ,
611
- "userAssignedIdentities" : {
612
- f"/subscriptions/{ subscriptionId } /resourceGroups/{ resourceGroup } /providers/Microsoft.ManagedIdentity/userAssignedIdentities/{ managedIdentityName } " : {}
613
- }
614
- }
615
- }
616
-
617
- if _LOG .isEnabledFor (logging .DEBUG ):
618
- _LOG .debug ("Request: PATCH %s\n %s" , url , json .dumps (json_req , indent = 2 ))
619
-
620
- response = requests .patch (url , json = json_req ,
621
- headers = self ._get_headers (), timeout = self ._request_timeout )
622
-
623
- if _LOG .isEnabledFor (logging .DEBUG ):
624
- _LOG .debug ("Response: %s\n %s" , response ,
625
- json .dumps (response .json (), indent = 2 )
626
- if response .content else "" )
627
- else :
628
- _LOG .info ("Response: %s" , response )
629
-
630
- if response .status_code == 200 :
631
- return (Status .PENDING , config )
632
- elif response .status_code == 201 :
633
- output = self ._extract_arm_parameters (response .json ())
634
- if _LOG .isEnabledFor (logging .DEBUG ):
635
- _LOG .debug ("Extracted parameters:\n %s" , json .dumps (output , indent = 2 ))
636
- params .update (output )
637
- params .setdefault ("asyncResultsUrl" , url )
638
- params .setdefault ("deploymentName" , config ["deploymentName" ])
639
- return (Status .PENDING , params )
640
- else :
641
- _LOG .error ("Response: %s :: %s" , response , response .text )
642
- # _LOG.error("Bad Request:\n%s", response.request.body)
643
- return (Status .FAILED , {})
0 commit comments