Ejemplo n.º 1
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)
Ejemplo n.º 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)
        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)
Ejemplo n.º 3
0
app_secret = configData['appSecret']
subscription_id = configData['subscriptionId']
#resource_group = configData['resourceGroup']
resource_group = 'guyqlen'

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

# create a storage account 
print('Enter storage account name to create.')
saname = input()
location = 'eastus'
sareturn = azurerm.create_storage_account(access_token, subscription_id, resource_group, saname, location)
print(sareturn)

# list storage accounts per sub
sa_list = azurerm.list_storage_accounts_sub(access_token, subscription_id)
print(sa_list)
#for rg in resource_groups["value"]:
#    print(rg["name"] + ', ' + rg["location"] + ', ' + rg["properties"]["provisioningState"])

print('Press Enter to continue and list accounts in RG.')
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=(',', ': ')))
Ejemplo n.º 4
0
print('Creating NSG: ' + nsg_name)
rmreturn = azurerm.create_nsg(access_token, subscription_id, name, nsg_name, location)
nsg_id = rmreturn.json()['id']
print('nsg_id = ' + nsg_id)

# create NSG rule
nsg_rule = 'ssh'
print('Creating NSG rule: ' + nsg_rule)
rmreturn = azurerm.create_nsg_rule(access_token, subscription_id, name, nsg_name, nsg_rule, description='ssh rule',
                                  destination_range='22')
print(rmreturn)
print(json.dumps(rmreturn.json(), sort_keys=False, indent=2, separators=(',', ': ')))

# create storage account
print('Creating storage account: ' + name)
rmreturn = azurerm.create_storage_account(access_token, subscription_id, name, name, location, storage_type='Premium_LRS')
print(rmreturn)

# create VNET
vnetname = name + 'vnet'
print('Creating VNet: ' + vnetname)
rmreturn = azurerm.create_vnet(access_token, subscription_id, name, vnetname, location, nsg_id=nsg_id)
print(rmreturn)
# print(json.dumps(rmreturn.json(), sort_keys=False, indent=2, separators=(',', ': ')))
subnet_id = rmreturn.json()['properties']['subnets'][0]['id']
print('subnet_id = ' + subnet_id)

# create public IP address
public_ip_name = name + 'ip'
dns_label = name + 'ip'
print('Creating public IP address: ' + public_ip_name)
Ejemplo n.º 5
0
    sys.exit()

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

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

# create a storage account
print('Enter storage account name to create.')
saname = input()
location = 'eastus'
sareturn = azurerm.create_storage_account(access_token, subscription_id,
                                          resource_group, saname, location)
print(sareturn)

# list storage accounts per sub
sa_list = azurerm.list_storage_accounts_sub(access_token, subscription_id)
print(json.dumps(sa_list, sort_keys=False, indent=2, separators=(',', ': ')))
# for rg in resource_groups["value"]:
#    print(rg["name"] + ', ' + rg["location"] + ', ' + rg["properties"]["provisioningState"])

print('Press Enter to continue and list accounts in RG.')
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=(',', ': ')))
Ejemplo n.º 6
0
###
# Create the a resource group for our demo
# We need a resource group and a storage account. A random name is generated, as each storage account name must be globally unique.
###
response = azurerm.create_resource_group(auth_token, subscription_id,
                                         resourcegroup_name, location)
if response.status_code == 200 or response.status_code == 201:
    print(('Resource group: ' + resourcegroup_name + ' created successfully.'))
else:
    print('Error creating resource group')

# Create a storage account for our demo
response = azurerm.create_storage_account(auth_token,
                                          subscription_id,
                                          resourcegroup_name,
                                          storageaccount_name,
                                          location,
                                          storage_type='Standard_LRS')
if response.status_code == 202:
    print(
        ('Storage account: ' + storageaccount_name + ' created successfully.'))
    print('\nWaiting for storage account to be ready before we create a Queue')
    time.sleep(15)
else:
    print('Error creating storage account')

###
# Use the Azure Storage Storage SDK for Python to create a Queue
###
print('\nLet\'s create an Azure Storage Queue to drop some messages on.')
input('Press Enter to continue...')
Ejemplo n.º 7
0
    def setUp(self):
        # 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']
        self.subscription_id = configData['subscriptionId']
        self.access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)
        self.location = configData['location']
        
        # generate names used in tests
        self.rgname = Haikunator.haikunate()
        self.vnet = Haikunator.haikunate(delimiter='')
        self.saname = Haikunator.haikunate(delimiter='')
        self.vmname = Haikunator.haikunate(delimiter='')
        self.vmssname = Haikunator.haikunate(delimiter='')

        # generate RSA Key for compute resources
        key = rsa.generate_private_key(backend=default_backend(), public_exponent=65537, \
            key_size=2048)
        self.public_key = key.public_key().public_bytes(serialization.Encoding.OpenSSH, \
            serialization.PublicFormat.OpenSSH).decode('utf-8')

        # 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)

        # create vnet
        print('Creating vnet: ' + self.vnet)
        response = azurerm.create_vnet(self.access_token, self.subscription_id, self.rgname, \
            self.vnet, self.location, address_prefix='10.0.0.0/16', nsg_id=None)
        self.assertEqual(response.status_code, 201)
        self.subnet_id = response.json()['properties']['subnets'][0]['id']

        # create public ip address for VM NIC
        self.ipname = self.vnet + 'ip'
        print('Creating VM NIC public ip address: ' + self.ipname)
        dns_label = self.vnet
        response = azurerm.create_public_ip(self.access_token, self.subscription_id, self.rgname, \
            self.ipname, dns_label, self.location)
        self.assertEqual(response.status_code, 201)
        self.ip_id = response.json()['id']

        # create public ip address for VMSS LB
        self.ipname2 = self.vnet + 'ip2'
        print('Creating VMSS LB public ip address: ' + self.ipname2)
        dns_label2 = self.vnet + '2'
        response = azurerm.create_public_ip(self.access_token, self.subscription_id, self.rgname, \
            self.ipname2, dns_label2, self.location)
        self.assertEqual(response.status_code, 201)
        self.ip2_id = response.json()['id']

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

        # create 5 storage accounts for vmssname
        print('Creating storage accounts for scale set')
        self.container_list = []
        for count in range(5):
            sa_name = ''.join(choice(ascii_lowercase) for i in range(10))
            print(sa_name)
            response = azurerm.create_storage_account(self.access_token, self.subscription_id, \
                self.rgname, sa_name, self.location, storage_type='Standard_LRS')
            self.assertEqual(response.status_code, 202)
            container = 'https://' + sa_name + '.blob.core.windows.net/' + self.vmssname + 'vhd'
            self.container_list.append(container)

        # create NSG
        nsg_name = self.vnet + 'nsg'
        print('Creating NSG: ' + nsg_name)
        response = azurerm.create_nsg(self.access_token, self.subscription_id, self.rgname, \
            nsg_name, self.location)
        self.assertEqual(response.status_code, 201)
        # print(json.dumps(response.json()))
        self.nsg_id = response.json()['id']

        # create NSG rule
        nsg_rule = 'ssh'
        print('Creating NSG rule: ' + nsg_rule)
        response = azurerm.create_nsg_rule(self.access_token, self.subscription_id, self.rgname, \
            nsg_name, nsg_rule, description='ssh rule', destination_range='22')
        self.assertEqual(response.status_code, 201)

        # create nic for VM create
        nic_name = self.vnet + 'nic'
        print('Creating nic: ' + nic_name)
        response = azurerm.create_nic(self.access_token, self.subscription_id, self.rgname, \
            nic_name, self.ip_id, self.subnet_id, self.location)
        self.assertEqual(response.status_code, 201)
        self.nic_id = response.json()['id']

        # create load balancer with nat pool for VMSS create
        lb_name = self.vnet + 'lb'
        print('Creating load balancer with nat pool: ' + lb_name)
        response = azurerm.create_lb_with_nat_pool(self.access_token, self.subscription_id, \
            self.rgname, lb_name, self.ip2_id, '50000', '50100', '22', self.location)
        self.be_pool_id = response.json()['properties']['backendAddressPools'][0]['id']
        self.lb_pool_id = response.json()['properties']['inboundNatPools'][0]['id']
Ejemplo n.º 8
0
                                   nsg_name,
                                   nsg_rule,
                                   description='ssh rule',
                                   destination_range='22')
print(rmreturn)
print(
    json.dumps(rmreturn.json(),
               sort_keys=False,
               indent=2,
               separators=(',', ': ')))

# create storage account
print('Creating storage account: ' + name)
rmreturn = azurerm.create_storage_account(access_token,
                                          subscription_id,
                                          name,
                                          name,
                                          location,
                                          storage_type='Premium_LRS')
print(rmreturn)

# create VNET
vnetname = name + 'vnet'
print('Creating VNet: ' + vnetname)
rmreturn = azurerm.create_vnet(access_token,
                               subscription_id,
                               name,
                               vnetname,
                               location,
                               nsg_id=nsg_id)
print(rmreturn)
# print(json.dumps(rmreturn.json(), sort_keys=False, indent=2, separators=(',', ': ')))
Ejemplo n.º 9
0
    sys.exit()

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)

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...')
Ejemplo n.º 10
0
print('nsg_id = ' + nsg_id)

# create NSG rule
nsg_rule = 'ssh'
print('Creating NSG rule: ' + nsg_rule)
rmreturn = azurerm.create_nsg_rule(access_token, subscription_id, name, nsg_name, nsg_rule, \
    description='ssh rule', destination_range='22')
#print(json.dumps(rmreturn.json(), sort_keys=False, indent=2, separators=(',', ': ')))

# create set of storage accounts, and construct container array
print('Creating storage accounts')
container_list = []
for count in range(5):
    sa_name = ''.join(choice(ascii_lowercase) for i in range(10))
    print(sa_name)
    rmreturn = azurerm.create_storage_account(access_token, subscription_id, name, sa_name, \
        location, storage_type='Standard_LRS')
    if rmreturn.status_code == 202:
        container = 'https://' + sa_name + '.blob.core.windows.net/' + name + 'vhd'
        container_list.append(container)
    else:
        print('Error ' + str(rmreturn.status_code) + ' creating storage account ' + sa_name)
        sys.exit()

# create VNET
vnetname = name + 'vnet'
print('Creating VNet: ' + vnetname)
rmreturn = azurerm.create_vnet(access_token, subscription_id, name, vnetname, location, \
    nsg_id=nsg_id)
print(rmreturn)
# print(json.dumps(rmreturn.json(), sort_keys=False, indent=2, separators=(',', ': ')))
subnet_id = rmreturn.json()['properties']['subnets'][0]['id']
Ejemplo n.º 11
0
    def setUp(self):
        # 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']
        self.subscription_id = configData['subscriptionId']
        self.access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)
        self.location = configData['location']
        
        # generate names for resources
        self.rgname = Haikunator.haikunate()
        self.vnet = Haikunator.haikunate(delimiter='')
        self.vmssname = Haikunator.haikunate(delimiter='')
        self.setting_name = Haikunator.haikunate(delimiter='')

        # 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)

        # create vnet
        print('Creating vnet: ' + self.vnet)
        response = azurerm.create_vnet(self.access_token, self.subscription_id, self.rgname, \
            self.vnet, self.location, address_prefix='10.0.0.0/16', nsg_id=None)
        self.assertEqual(response.status_code, 201)
        self.subnet_id = response.json()['properties']['subnets'][0]['id']

        # create public ip address for VMSS LB
        self.ipname2 = self.vnet + 'ip2'
        print('Creating VMSS LB public ip address: ' + self.ipname2)
        dns_label2 = self.vnet + '2'
        response = azurerm.create_public_ip(self.access_token, self.subscription_id, self.rgname, \
            self.ipname2, dns_label2, self.location)
        self.assertEqual(response.status_code, 201)
        self.ip2_id = response.json()['id']

        # create 5 storage accounts for vmssname
        print('Creating storage accounts for scale set')
        self.container_list = []
        for count in range(5):
            sa_name = ''.join(choice(ascii_lowercase) for i in range(10))
            print(sa_name)
            response = azurerm.create_storage_account(self.access_token, self.subscription_id, \
                self.rgname, sa_name, self.location, storage_type='Standard_LRS')
            self.assertEqual(response.status_code, 202)
            container = 'https://' + sa_name + '.blob.core.windows.net/' + self.vmssname + 'vhd'
            self.container_list.append(container)

        # create load balancer with nat pool for VMSS create
        lb_name = self.vnet + 'lb'
        print('Creating load balancer with nat pool: ' + lb_name)
        response = azurerm.create_lb_with_nat_pool(self.access_token, self.subscription_id, \
            self.rgname, lb_name, self.ip2_id, '50000', '50100', '22', self.location)
        self.be_pool_id = response.json()['properties']['backendAddressPools'][0]['id']
        self.lb_pool_id = response.json()['properties']['inboundNatPools'][0]['id']

        # create VMSS
        capacity = 1
        vm_size = 'Standard_D1'
        publisher = 'Canonical'
        offer = 'UbuntuServer'
        sku = '16.04.0-LTS'
        version = 'latest'
        username = '******'
        password = Haikunator.haikunate(delimiter=',')
        print('Creating VMSS: ' + self.vmssname + ', capacity = ' + str(capacity))
        response = azurerm.create_vmss(self.access_token, self.subscription_id, self.rgname, \
            self.vmssname, vm_size, capacity, publisher, offer, sku, version, self.container_list, \
            self.subnet_id, self.be_pool_id, self.lb_pool_id, self.location, username=username, \
            password=password)
Ejemplo n.º 12
0
print('nsg_id = ' + nsg_id)

# create NSG rule
nsg_rule = 'ssh'
print('Creating NSG rule: ' + nsg_rule)
rmreturn = azurerm.create_nsg_rule(access_token, subscription_id, name, nsg_name, nsg_rule, \
    description='ssh rule', destination_range='22')
#print(json.dumps(rmreturn.json(), sort_keys=False, indent=2, separators=(',', ': ')))

# create set of storage accounts, and construct container array
print('Creating storage accounts')
container_list = []
for count in range(5):
    sa_name = ''.join(choice(ascii_lowercase) for i in range(10))
    print(sa_name)
    rmreturn = azurerm.create_storage_account(access_token, subscription_id, name, sa_name, \
        location, storage_type='Standard_LRS')
    if rmreturn.status_code == 202:
        container = 'https://' + sa_name + '.blob.core.windows.net/' + name + 'vhd'
        container_list.append(container)
    else:
        print('Error ' + str(rmreturn.status_code) +
              ' creating storage account ' + sa_name)
        sys.exit()

# create VNET
vnetname = name + 'vnet'
print('Creating VNet: ' + vnetname)
rmreturn = azurerm.create_vnet(access_token, subscription_id, name, vnetname, location, \
    nsg_id=nsg_id)
print(rmreturn)
# print(json.dumps(rmreturn.json(), sort_keys=False, indent=2, separators=(',', ': ')))
Ejemplo n.º 13
0
    def setUp(self):
        # 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']
        self.subscription_id = configData['subscriptionId']
        self.access_token = azurerm.get_access_token(tenant_id, app_id, app_secret)
        self.location = configData['location']
        
        # generate names used in tests
        self.rgname = Haikunator.haikunate()
        self.vnet = Haikunator.haikunate(delimiter='')
        self.saname = Haikunator.haikunate(delimiter='')
        self.vmname = Haikunator.haikunate(delimiter='')
        self.vmssname = Haikunator.haikunate(delimiter='')

        # 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)

        # create vnet
        print('Creating vnet: ' + self.vnet)
        response = azurerm.create_vnet(self.access_token, self.subscription_id, self.rgname, \
            self.vnet, self.location, address_prefix='10.0.0.0/16', nsg_id=None)
        self.assertEqual(response.status_code, 201)
        self.subnet_id = response.json()['properties']['subnets'][0]['id']

        # create public ip address for VM NIC
        self.ipname = self.vnet + 'ip'
        print('Creating VM NIC public ip address: ' + self.ipname)
        dns_label = self.vnet
        response = azurerm.create_public_ip(self.access_token, self.subscription_id, self.rgname, \
            self.ipname, dns_label, self.location)
        self.assertEqual(response.status_code, 201)
        self.ip_id = response.json()['id']

        # create public ip address for VMSS LB
        self.ipname2 = self.vnet + 'ip2'
        print('Creating VMSS LB public ip address: ' + self.ipname2)
        dns_label2 = self.vnet + '2'
        response = azurerm.create_public_ip(self.access_token, self.subscription_id, self.rgname, \
            self.ipname2, dns_label2, self.location)
        self.assertEqual(response.status_code, 201)
        self.ip2_id = response.json()['id']

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

        # create 5 storage accounts for vmssname
        print('Creating storage accounts for scale set')
        self.container_list = []
        for count in range(5):
            sa_name = ''.join(choice(ascii_lowercase) for i in range(10))
            print(sa_name)
            response = azurerm.create_storage_account(self.access_token, self.subscription_id, \
                self.rgname, sa_name, self.location, storage_type='Standard_LRS')
            self.assertEqual(response.status_code, 202)
            container = 'https://' + sa_name + '.blob.core.windows.net/' + self.vmssname + 'vhd'
            self.container_list.append(container)

        # create NSG
        nsg_name = self.vnet + 'nsg'
        print('Creating NSG: ' + nsg_name)
        response = azurerm.create_nsg(self.access_token, self.subscription_id, self.rgname, \
            nsg_name, self.location)
        self.assertEqual(response.status_code, 201)
        # print(json.dumps(response.json()))
        self.nsg_id = response.json()['id']

        # create NSG rule
        nsg_rule = 'ssh'
        print('Creating NSG rule: ' + nsg_rule)
        response = azurerm.create_nsg_rule(self.access_token, self.subscription_id, self.rgname, \
            nsg_name, nsg_rule, description='ssh rule', destination_range='22')
        self.assertEqual(response.status_code, 201)

        # create nic for VM create
        nic_name = self.vnet + 'nic'
        print('Creating nic: ' + nic_name)
        response = azurerm.create_nic(self.access_token, self.subscription_id, self.rgname, \
            nic_name, self.ip_id, self.subnet_id, self.location)
        self.assertEqual(response.status_code, 201)
        self.nic_id = response.json()['id']

        # create load balancer with nat pool for VMSS create
        lb_name = self.vnet + 'lb'
        print('Creating load balancer with nat pool: ' + lb_name)
        response = azurerm.create_lb_with_nat_pool(self.access_token, self.subscription_id, \
            self.rgname, lb_name, self.ip2_id, '50000', '50100', '22', self.location)
        self.be_pool_id = response.json()['properties']['backendAddressPools'][0]['id']
        self.lb_pool_id = response.json()['properties']['inboundNatPools'][0]['id']