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)
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)
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)
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() #rgreturn = azurerm.delete_storage_account(access_token, subscription_id, resource_group, saname) #print(rgreturn)
time.sleep(2) else: print('Error creating storage account') ### # Use the Azure Storage Storage SDK for Python to create a Table ### print('\nLet\'s create an Azure Storage Table to store some data.') raw_input('Press Enter to continue...') # Each storage account has a primary and secondary access key. # These keys are used by aplications to access data in your storage account, such as Tables. # Obtain the primary storage access key for use with the rest of the demo response = azurerm.get_storage_account_keys(auth_token, subscription_id, resourcegroup_name, storageaccount_name) storageaccount_keys = json.loads(response.text) storageaccount_primarykey = storageaccount_keys['keys'][0]['value'] # Create the Table with the Azure Storage SDK and the access key obtained in the previous step table_service = TableService(account_name=storageaccount_name, account_key=storageaccount_primarykey) response = table_service.create_table('itemstable') if response == True: print('Storage Table: itemstable created successfully.\n') else: print('Error creating Storage Table.\n') time.sleep(1) ###
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) # delete storage_account # print('Press Enter to delete account.') # input() # rgreturn = azurerm.delete_storage_account(access_token, subscription_id, resource_group, saname) # print(rgreturn)
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=(',', ': ')))