def __init__(self, group_name, location): self.location = location self.subscription_id = os.environ.get("SUBSCRIPTION_ID", None) # Use 2019-07-01 api version to test create VM self.compute_client = mgmt_compute.ComputeManagementClient( credential=DefaultAzureCredential(), subscription_id=self.subscription_id, api_version="2019-07-01") self.network_client = mgmt_network.NetworkManagementClient( credential=DefaultAzureCredential(), subscription_id=self.subscription_id) self.resource_client = mgmt_resource.ResourceManagementClient( credential=DefaultAzureCredential(), subscription_id=self.subscription_id) self.group = self.resource_client.resource_groups.create_or_update( group_name, # model style resource_models.ResourceGroup(location=self.location) # json style # {'location': self.location} )
def __init__(self, default_resource_group_name: str, default_region: str = 'eastus', profile_name: Optional[str] = None) -> None: """Initialize the AZAccount class. Args: default_resource_group_name (str): The default resource group in which to create new resources in. If the resource group does not exists, it will be automatically created. default_region (str): Optional. The default region to create new resources in. Default is eastus. profile_name (str): Optional. The name of the profile to use for Azure operations. For more information on profiles, see GetCredentials() in libcloudforensics.providers.azure.internal.common.py. Default does not use profiles and will authenticate to Azure using environment variables. """ self.subscription_id, self.credentials = common.GetCredentials(profile_name) self.default_region = default_region self.compute_client = azure_compute.ComputeManagementClient( self.credentials, self.subscription_id) self.storage_client = storage.StorageManagementClient( self.credentials, self.subscription_id) self.resource_client = resource.ResourceManagementClient( self.credentials, self.subscription_id) self.network_client = network.NetworkManagementClient( self.credentials, self.subscription_id) self.default_resource_group_name = self._GetOrCreateResourceGroup( default_resource_group_name)
def __init__(self, az_account: 'account.AZAccount') -> None: """Initialize the AZCompute class. Args: az_account (AZAccount): An Azure account object. """ self.az_account = az_account self.compute_client = compute_sdk.ComputeManagementClient( self.az_account.credentials, self.az_account.subscription_id ) # type: compute_sdk.ComputeManagementClient
def _execute(self): subscription_id = os.environ['ARM_SUBSCRIPTION_ID'] credentials = ServicePrincipalCredentials( client_id=os.environ['ARM_CLIENT_ID'], secret=os.environ['ARM_CLIENT_SECRET'], tenant=os.environ['ARM_TENANT_ID'], ) selected_region = self.operator_dict['region'] client = compute.ComputeManagementClient(credentials, subscription_id) if 'instance_families' not in self.operator_dict: instances = list( set([ i.name for i in client.resource_skus.list(filter="location eq '" + selected_region + "'") ])) else: selected_family = self.operator_dict['instance_families'] selected_family = ['^' + name for name in selected_family] instances = list( set([ i.name for i in client.resource_skus.list(filter="location eq '" + selected_region + "'") ])) instances_split = [i.split("_", 1) for i in instances] for i, name in enumerate(selected_family): if i == 0: exp = name else: exp += "|" + name exp = re.compile(exp) instance_sizes_set = [ i for i in instances_split if len(i) == 2 if exp.match(i[1]) ] instance_sizes_set.sort(key=lambda x: x[1]) instances = ['-'.join([s[0], s[1]]) for s in instance_sizes_set] return instances