Пример #1
0
def main():
    '''Main routine.'''
    # Load Azure app defaults
    try:
        with open('azurermconfig.json') as config_file:
            config_data = json.load(config_file)
    except FileNotFoundError:
        sys.exit("Error: Expecting azurermconfig.json in current folder")

    tenant_id = config_data['tenantId']
    app_id = config_data['appId']
    app_secret = config_data['appSecret']
    subscription_id = config_data['subscriptionId']

    access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)

    # list autoscale settings
    auto_settings = azurerm.list_autoscale_settings(access_token,
                                                    subscription_id)
    print(auto_settings)
    for auto_setting in auto_settings['value']:
        print(auto_setting['name'] + ', ' + auto_setting['location'])
        print(auto_setting['properties']['profiles'])

    # loop through resource groups
    resource_groups = azurerm.list_resource_groups(access_token,
                                                   subscription_id)
    for rgs in resource_groups["value"]:
        rgname = rgs["name"]
        insights_comp = azurerm.list_insights_components(
            access_token, subscription_id, rgname)
        if len(insights_comp) > 0:
            print(insights_comp)
Пример #2
0
    def test_resource_groups(self):
        # create resource group
        print('Creating resource group: ' + self.rgname)
        response = azurerm.create_resource_group(self.access_token, self.subscription_id, \
            self.rgname, self.location)
        self.assertEqual(response.status_code, 201)

        # get resource group
        print('Getting resource group: ' + self.rgname)
        response = azurerm.get_resource_group(self.access_token,
                                              self.subscription_id,
                                              self.rgname)
        self.assertEqual(response['name'], self.rgname)

        # list resource groups
        print('List resource groups: ' + self.rgname)
        response = azurerm.list_resource_groups(self.access_token,
                                                self.subscription_id)
        self.assertTrue('value' in response)

        # delete resource group
        print('Deleting resource group: ' + self.rgname)
        response = azurerm.delete_resource_group(self.access_token,
                                                 self.subscription_id,
                                                 self.rgname)
        self.assertEqual(response.status_code, 202)
Пример #3
0
def main():
    '''Main routine.'''
    # if in Azure cloud shell, authenticate using the MSI endpoint
    if 'ACC_CLOUD' in os.environ and 'MSI_ENDPOINT' in os.environ:
        access_token = azurerm.get_access_token_from_cli()
        subscription_id = azurerm.get_subscription_from_cli()
    else: # load service principal details from a config file        
        try:
            with open('azurermconfig.json') as configfile:
                configdata = json.load(configfile)
        except FileNotFoundError:
            sys.exit('Error: Expecting azurermconfig.json in current folder')

        tenant_id = configdata['tenantId']
        app_id = configdata['appId']
        app_secret = configdata['appSecret']
        subscription_id = configdata['subscriptionId']

        # authenticate
        access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)

    # list resource groups
    resource_groups = azurerm.list_resource_groups(access_token, subscription_id)
    for rgname in resource_groups['value']:
        print(rgname['name'] + ', ' + rgname['location'])
        '''
Пример #4
0
def listrgs():
    try:
        resource_groups = azurerm.list_resource_groups(access_token, subscription_id)
        rglist = []
        for rg in resource_groups["value"]:
            rglist.append(rg["name"])
    except KeyError:
        statusmsg('KeyError: azurerm.list_resource_groups() returned: ' + json.dumps(resource_groups))

    return rglist
Пример #5
0
    def getResourceGroup(self):
        try:
            resource_groups = azurerm.list_resource_groups(
                self.access_token, self.subscription)
            array = []
            for rg in resource_groups['value']:
                #print(rg["name"] + ', ' + rg['location'] + ', ' + rg['properties']['provisioningState'])
                array2 = []
                array2.append(rg["name"])
                array2.append(rg['location'])
                array2.append(rg['properties']['provisioningState'])
                array.append(array2)
            return array

        except ValueError:
            print("Fail to get list of resource groups")
            return False
Пример #6
0
    def test_resource_groups(self):
        # create resource group
        print('Creating resource group: ' + self.rgname)
        response = azurerm.create_resource_group(self.access_token, self.subscription_id, \
            self.rgname, self.location)
        self.assertEqual(response.status_code, 201)

        # get resource group
        print('Getting resource group: ' + self.rgname)
        response = azurerm.get_resource_group(self.access_token, self.subscription_id, self.rgname)
        self.assertEqual(response['name'], self.rgname)

        # list resource groups
        print('List resource groups: ' + self.rgname)
        response = azurerm.list_resource_groups(self.access_token, self.subscription_id)
        self.assertTrue('value' in response)

        # delete resource group
        print('Deleting resource group: ' + self.rgname)
        response = azurerm.delete_resource_group(self.access_token, self.subscription_id, self.rgname)
        self.assertEqual(response.status_code, 202)
Пример #7
0
def main():
    '''Main routine.'''
    # Load Azure app defaults
    try:
        with open('azurermconfig.json') as config_file:
            config_data = json.load(config_file)
    except FileNotFoundError:
        sys.exit("Error: Expecting vmssConfig.json in current folder")

    tenant_id = config_data['tenantId']
    app_id = config_data['appId']
    app_secret = config_data['appSecret']
    sub_id = config_data['subscriptionId']

    access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)

    # list resource groups
    resource_groups = azurerm.list_resource_groups(access_token, sub_id)
    for rgname in resource_groups['value']:
        print(rgname['name'] + ', ' + rgname['location'])
        '''
Пример #8
0
def main():
    '''Main routine.'''
    # Load Azure app defaults
    try:
        with open('azurermconfig.json') as config_file:
            config_data = json.load(config_file)
    except FileNotFoundError:
        sys.exit("Error: Expecting vmssConfig.json in current folder")

    tenant_id = config_data['tenantId']
    app_id = config_data['appId']
    app_secret = config_data['appSecret']
    sub_id = config_data['subscriptionId']

    access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)

    # list resource groups
    resource_groups = azurerm.list_resource_groups(access_token, sub_id)
    for rgname in resource_groups['value']:
        print(rgname['name'] + ', ' + rgname['location'])
        '''
Пример #9
0
    def test_resource_groups(self):
        # create resource group
        print('Creating resource group: ' + self.rgname)
        response = azurerm.create_resource_group(self.access_token,
                                                 self.subscription_id,
                                                 self.rgname, self.location)
        self.assertEqual(response.status_code, 201)

        # get resource group
        print('Getting resource group: ' + self.rgname)
        response = azurerm.get_resource_group(self.access_token,
                                              self.subscription_id,
                                              self.rgname)
        self.assertEqual(response['name'], self.rgname)

        # export resource group
        print('Exporting resource group: ' + self.rgname)
        response = azurerm.export_template(self.access_token,
                                           self.subscription_id, self.rgname)
        self.assertEqual(response.status_code, 200)

        # get resource group resources
        print('Getting resources for resource group: ' + self.rgname)
        response = azurerm.get_resource_group_resources(
            self.access_token, self.subscription_id, self.rgname)
        #print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': ')))
        self.assertTrue('value' in response)

        # list resource groups
        print('List resource groups: ' + self.rgname)
        response = azurerm.list_resource_groups(self.access_token,
                                                self.subscription_id)
        self.assertTrue('value' in response)

        # delete resource group
        print('Deleting resource group: ' + self.rgname)
        response = azurerm.delete_resource_group(self.access_token,
                                                 self.subscription_id,
                                                 self.rgname)
        self.assertEqual(response.status_code, 202)
Пример #10
0
    with open('azurermconfig.json') as configFile:
        configData = json.load(configFile)
except FileNotFoundError:
    print("Error: Expecting vmssConfig.json in current folder")
    sys.exit()

tenant_id = configData['tenantId']
app_id = configData['appId']
app_secret = configData['appSecret']
subscription_id = configData['subscriptionId']
resource_group = configData['resourceGroup']

access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)

# loop through resource groups
resource_groups = azurerm.list_resource_groups(access_token, subscription_id)
for rg in resource_groups["value"]:
    rgname = rg["name"]
    vmlist = azurerm.list_vms(access_token, subscription_id, rgname)
    for vm in vmlist['value']:
        name = vm['name']
        location = vm['location']
        offer = vm['properties']['storageProfile']['imageReference']['offer']
        sku = vm['properties']['storageProfile']['imageReference']['sku']
        print(''.join([
            'Name: ', name, ', RG: ', rgname, ', location: ', location,
            ', OS: ', offer, ' ', sku
        ]))

# get extension details (note the hardcoded values you'll need to change
extn = azurerm.get_vm_extension(access_token, subscription_id, resource_group,
Пример #11
0
import json

import azurerm

# Load Azure app defaults
try:
    with open('azurermconfig.json') as configFile:
        configData = json.load(configFile)
except FileNotFoundError:
    print("Error: Expecting vmssConfig.json in current folder")
    sys.exit()

tenant_id = configData['tenantId']
app_id = configData['appId']
app_secret = configData['appSecret']
subscription_id = configData['subscriptionId']

access_token = azurerm.get_access_token(
    tenant_id,
    app_id,
    app_secret
)

# list resource groups
resource_groups = azurerm.list_resource_groups(access_token, subscription_id)
for rg in resource_groups["value"]:
    print(rg["name"] + ', ' + rg["location"] + ', ' + rg["properties"]["provisioningState"])