Пример #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 storage accounts per sub
    sa_list = azurerm.list_storage_accounts_sub(access_token, subscription_id)
    # print(sa_list)
    for sta in sa_list['value']:
        print(sta['name'] + ', ' + sta['properties']['primaryLocation'] + ', '
              + rgfromid(sta['id']))

    # get storage account quota
    quota_info = azurerm.get_storage_usage(access_token, subscription_id)
    used = quota_info['value'][0]['currentValue']
    limit = quota_info["value"][0]["limit"]
    print('\nUsing ' + str(used) + ' accounts out of ' + str(limit) + '.')
Пример #2
0
    def test_storage_accounts(self):

        # create storage account
        print('Creating storage account: ' + self.storage_account)
        response = azurerm.create_storage_account(self.access_token, self.subscription_id, \
            self.rgname, self.storage_account, self.location)
        # print(response.text)
        self.assertEqual(response.status_code, 202)

        # get storage account
        print('Get storage account: ' + self.storage_account)
        response = azurerm.get_storage_account(self.access_token, self.subscription_id, \
            self.rgname, self.storage_account)
        self.assertEqual(response['name'], self.storage_account)

        # get storage account keys
        print('Get storage account keys')
        time.sleep(20)  # small delay to allow account keys to be created
        response = azurerm.get_storage_account_keys(self.access_token, self.subscription_id, \
            self.rgname, self.storage_account)
        keys = json.loads(response.text)
        # print(response.text)
        self.assertTrue('keys' in keys)

        # get storage usage
        print('Get storage usage')
        response = azurerm.get_storage_usage(self.access_token,
                                             self.subscription_id,
                                             self.location)
        # print(json.dumps(response))
        self.assertTrue('value' in response)

        # list storage accounts
        print('List storage accounts')
        response = azurerm.list_storage_accounts_rg(self.access_token, self.subscription_id, \
            self.rgname)
        self.assertTrue('value' in response)

        # list storage accounts in subscription
        print('List storage accounts in subscription')
        response = azurerm.list_storage_accounts_sub(self.access_token,
                                                     self.subscription_id)
        self.assertTrue('value' in response)

        # delete storage account
        print('Delete storage account: ' + self.storage_account)
        response = azurerm.delete_storage_account(self.access_token, self.subscription_id, \
            self.rgname, self.storage_account)
        self.assertEqual(response.status_code, 200)
Пример #3
0
    def test_storage_accounts(self):

        # create storage account
        print("Creating storage account: " + self.storage_account)
        response = azurerm.create_storage_account(
            self.access_token, self.subscription_id, self.rgname, self.storage_account, self.location
        )
        self.assertEqual(response.status_code, 202)

        # get storage account
        print("Get storage account: " + self.storage_account)
        response = azurerm.get_storage_account(
            self.access_token, self.subscription_id, self.rgname, self.storage_account
        )
        self.assertEqual(response["name"], self.storage_account)

        # get storage account keys
        print("Get storage account keys")
        time.sleep(2)  # small delay to allow account keys to be created
        response = azurerm.get_storage_account_keys(
            self.access_token, self.subscription_id, self.rgname, self.storage_account
        )
        keys = json.loads(response.text)
        self.assertTrue("keys" in keys)

        # get storage usage
        print("Get storage usage")
        response = azurerm.get_storage_usage(self.access_token, self.subscription_id)
        self.assertTrue("value" in response)

        # list storage accounts
        print("List storage accounts")
        response = azurerm.list_storage_accounts_rg(self.access_token, self.subscription_id, self.rgname)
        self.assertTrue("value" in response)

        # list storage accounts in subscription
        print("List storage accounts in subscription")
        response = azurerm.list_storage_accounts_sub(self.access_token, self.subscription_id)
        self.assertTrue("value" in response)

        # delete storage account
        print("Delete storage account: " + self.storage_account)
        response = azurerm.delete_storage_account(
            self.access_token, self.subscription_id, self.rgname, self.storage_account
        )
        self.assertEqual(response.status_code, 200)
Пример #4
0
    def test_storage_accounts(self):

        # create storage account
        print('Creating storage account: ' + self.storage_account)
        response = azurerm.create_storage_account(self.access_token, self.subscription_id, \
            self.rgname, self.storage_account, self.location)
        self.assertEqual(response.status_code, 202)

        # get storage account
        print('Get storage account: ' + self.storage_account)
        response = azurerm.get_storage_account(self.access_token, self.subscription_id, \
            self.rgname, self.storage_account)
        self.assertEqual(response['name'], self.storage_account)

        # get storage account keys
        print('Get storage account keys')
        time.sleep(2) # small delay to allow account keys to be created
        response = azurerm.get_storage_account_keys(self.access_token, self.subscription_id, \
            self.rgname, self.storage_account) 
        keys = json.loads(response.text)
        self.assertTrue('keys' in keys)

        # get storage usage
        print('Get storage usage')
        response = azurerm.get_storage_usage(self.access_token, self.subscription_id)
        self.assertTrue('value' in response)

        # list storage accounts
        print('List storage accounts')
        response = azurerm.list_storage_accounts_rg(self.access_token, self.subscription_id, \
            self.rgname)
        self.assertTrue('value' in response)

        # list storage accounts in subscription
        print('List storage accounts in subscription')
        response = azurerm.list_storage_accounts_sub(self.access_token, self.subscription_id)
        self.assertTrue('value' in response)

        # delete storage account
        print('Delete storage account: ' + self.storage_account)
        response = azurerm.delete_storage_account(self.access_token, self.subscription_id, \
            self.rgname, self.storage_account)
        self.assertEqual(response.status_code, 200)
Пример #5
0
input()

# list storage accounts in rg
sa_list = azurerm.list_storage_accounts_rg(access_token, subscription_id, resource_group)
print(json.dumps(sa_list, sort_keys=False, indent=2, separators=(',', ': ')))

print('Storage account details...')

# get storage account details
sa_info = azurerm.get_storage_account(access_token, subscription_id, resource_group, saname)
print(json.dumps(sa_info, sort_keys=False, indent=2, separators=(',', ': ')))

print('Storage account quota...')

# get storage account quota
quota_info = azurerm.get_storage_usage(access_token, subscription_id)
print(json.dumps(quota_info, sort_keys=False, indent=2, separators=(',', ': ')))

print('Storage account keys...')

# get storage account keys
keys = azurerm.get_storage_account_keys(access_token, subscription_id, resource_group, saname)
print(keys.text)

# Get just the primary access key. For the secondary access key, use [1] instead of [0]
primarykey = json.loads(keys.text)
print(primarykey['keys'][0]['value'])

# delete storage_account
#print('Press Enter to delete account.')
#input()
Пример #6
0
      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']

# pull the resource group name from the id string
def rgfromid(idstr):
    rgidx = idstr.find('resourceGroups/')
    providx = idstr.find('/providers/')
    return idstr[rgidx + 15:providx]

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

# list storage accounts per sub
sa_list = azurerm.list_storage_accounts_sub(access_token, subscription_id)
# print(sa_list)
for sa in sa_list['value']:
    print(sa['name'] + ', ' + sa['properties']['primaryLocation'] + ', ' + rgfromid(sa['id']))

# get storage account quota
quota_info = azurerm.get_storage_usage(access_token, subscription_id)
used = quota_info['value'][0]['currentValue']
limit = quota_info["value"][0]["limit"]
print('\nUsing ' + str(used) + ' accounts out of ' + str(limit) + '.')

Пример #7
0
SUB_ID = CONFIG_DATA['subscriptionId']
ACCESS_TOKEN = azurerm.get_access_token(TENANT_ID, APP_ID, APP_SECRET)

print('Enter an existing Azure Resource Group name.')
RG_NAME = input()

# create a storage account
print('Enter storage account name to create.')
SA_NAME = input()
LOCATION = 'southeastasia'
RET = azurerm.create_storage_account(ACCESS_TOKEN, SUB_ID, RG_NAME, SA_NAME, LOCATION)
print(RET)

print('Storage account details...')

# get storage account details
SA_INFO = azurerm.get_storage_account(ACCESS_TOKEN, SUB_ID, RG_NAME, SA_NAME)
print(json.dumps(SA_INFO, sort_keys=False, indent=2, separators=(',', ': ')))

print('Storage account quota...')

# get storage account quota
QUOTA_INFO = azurerm.get_storage_usage(ACCESS_TOKEN, SUB_ID)
print(json.dumps(QUOTA_INFO, sort_keys=False, indent=2, separators=(',', ': ')))

print('Storage account keys...')

# get storage account keys
KEYS = azurerm.get_storage_account_keys(ACCESS_TOKEN, SUB_ID, RG_NAME, SA_NAME)
print(json.dumps(KEYS.text, sort_keys=False, indent=2, separators=(',', ': ')))
                        dc(secret_data['osServicePrincipal.json']))
                    access_token = azurerm.get_access_token(
                        azOSP['tenantId'], azOSP['clientId'],
                        azOSP['clientSecret'])
                    for region in [
                            'centralus', 'eastus', 'eastus2', 'westus',
                            'westus2', 'southcentralus'
                    ]:
                        compute_usage = azurerm.get_compute_usage(
                            access_token, azOSP['subscriptionId'],
                            region)['value']
                        compute_usage = compute_usage + azurerm.get_network_usage(
                            access_token, azOSP['subscriptionId'],
                            region)['value']
                        compute_usage = compute_usage + azurerm.get_storage_usage(
                            access_token, azOSP['subscriptionId'],
                            region)['value']
                        print("Azure: Processing Cloud Provider: " +
                              provider_name + " in region: " + region)

                        for quota in compute_usage:
                            if quota['limit'] != 0 and quota[
                                    'currentValue'] / quota[
                                        'limit'] > CM_THRESHOLD and quota[
                                            'name'][
                                                'value'] != 'NetworkWatchers':
                                msg = quota['name'][
                                    'localizedValue'] + " " + str(
                                        quota['currentValue']) + "/" + str(
                                            quota['limit'])
                                print(" \\ -> " + msg)