Пример #1
0
    def test_compute(self):
        # create availability set
        print('Creating availability set: ' + self.asname +
              ', update domains = 5, fault domains = 3')
        response = azurerm.create_as(self.access_token, self.subscription_id,
                                     self.rgname, self.asname, 5, 3,
                                     self.location)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['name'], self.asname)

        # create VM
        vm_size = 'Standard_B1s'
        publisher = 'Canonical'
        offer = 'UbuntuServer'
        sku = '18.04-LTS'
        version = 'latest'
        username = '******'

        print('Creating VM: ' + self.vmname)
        response = azurerm.create_vm(self.access_token, self.subscription_id, self.rgname, \
            self.vmname, vm_size, publisher, offer, sku, version, \
            self.nic_id, self.location, username=username, public_key=self.public_key)
        # print(json.dumps(response.json()))
        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.json()['name'], self.vmname)

        # create VMSS
        capacity = 3
        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.subnet_id, self.location, self.be_pool_id, self.lb_pool_id, username=username, \
            public_key=self.public_key)
        # print(json.dumps(response.json()))
        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.json()['name'], self.vmssname)

        # get compute usage
        print('Getting compute usage')
        response = azurerm.get_compute_usage(self.access_token,
                                             self.subscription_id,
                                             self.location)
        self.assertTrue(len(response['value']) > 0)

        # get vm instance view
        print('Getting VM instance view')
        response = azurerm.get_vm_instance_view(self.access_token, self.subscription_id, \
            self.rgname, self.vmname)
        # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': ')))
        self.assertEqual(response['statuses'][0]['displayStatus'], 'Creating')

        # get availability set details
        print('Getting availability set details')
        response = azurerm.get_as(self.access_token, self.subscription_id,
                                  self.rgname, self.asname)
        self.assertEqual(response['name'], self.asname)

        # list VMSS skus
        print('Listing VMSS skus')
        response = azurerm.list_vmss_skus(self.access_token, self.subscription_id, \
            self.rgname, self.vmssname)
        # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': ')))
        self.assertTrue(len(response['value']) > 0)

        # list VMSS nics
        print('Getting VMSS NICs')
        response = azurerm.get_vmss_nics(self.access_token, self.subscription_id, \
            self.rgname, self.vmssname)
        # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': ')))
        self.assertTrue(len(response['value']) > 0)

        # delete VM
        print('Deleting VM: ' + self.vmname)
        response = azurerm.delete_vm(self.access_token, self.subscription_id, self.rgname, \
            self.vmname)
        self.assertEqual(response.status_code, 202)

        # delete VMSS
        print('Deleting VMSS: ' + self.vmssname)
        response = azurerm.delete_vmss(self.access_token, self.subscription_id, self.rgname, \
            self.vmssname)
        self.assertEqual(response.status_code, 202)

        # delete Availability Set
        print('Deleting Availability Set: ' + self.asname)
        response = azurerm.delete_as(self.access_token, self.subscription_id, self.rgname, \
            self.asname)
        self.assertEqual(response.status_code, 200)
Пример #2
0
    def test_compute(self):
        # create availability set
        print('Creating availability set: ' + self.asname + ', update domains = 5, fault domains = 3')
        response = azurerm.create_as(self.access_token, self.subscription_id, self.rgname,
                                     self.asname, 5, 3, self.location)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['name'], self.asname)

        # create VM
        vm_size = 'Standard_D1'
        publisher = 'Canonical'
        offer = 'UbuntuServer'
        sku = '16.04-LTS'
        version = 'latest'
        username = '******'
        password = self.h.haikunate(',')

        print('Creating VM: ' + self.vmname)
        response = azurerm.create_vm(self.access_token, self.subscription_id, self.rgname, \
            self.vmname, vm_size, publisher, offer, sku, version, \
            self.nic_id, self.location, username=username, public_key=self.public_key)
        # print(json.dumps(response.json()))
        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.json()['name'], self.vmname)

        # create VMSS
        capacity = 3
        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.subnet_id, self.be_pool_id, self.lb_pool_id, self.location, username=username, \
            public_key=self.public_key)
        # print(json.dumps(response.json()))
        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.json()['name'], self.vmssname)

        # get compute usage
        print('Getting compute usage')
        response = azurerm.get_compute_usage(self.access_token, self.subscription_id, self.location)
        self.assertTrue(len(response['value']) > 0)

        # get vm instance view
        print('Getting VM instance view')
        response = azurerm.get_vm_instance_view(self.access_token, self.subscription_id, \
            self.rgname, self.vmname)
        # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': ')))
        self.assertEqual(response['statuses'][0]['displayStatus'], 'Creating')

        # get availability set details
        print('Getting availability set details')
        response = azurerm.get_as(self.access_token, self.subscription_id, self.rgname, self.asname)
        self.assertEqual(response['name'], self.asname)

        # list vm instance views
        print('Listing VM instance views')
        response = azurerm.list_vm_instance_view(self.access_token, self.subscription_id, \
            self.rgname)
        # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': ')))
        self.assertTrue(len(response['value']) > 0)

        # list VMSS skus
        print('Listing VMSS skus')
        response = azurerm.list_vmss_skus(self.access_token, self.subscription_id, \
            self.rgname, self.vmssname)
        # print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': ')))
        self.assertTrue(len(response['value']) > 0)

        # list VMSS nics
        print('Getting VMSS NICs')
        response = azurerm.get_vmss_nics(self.access_token, self.subscription_id, \
            self.rgname, self.vmssname)
        #print(json.dumps(response, sort_keys=False, indent=2, separators=(',', ': ')))
        self.assertTrue(len(response['value']) > 0)

        # delete VM
        print('Deleting VM: ' + self.vmname)
        response = azurerm.delete_vm(self.access_token, self.subscription_id, self.rgname, \
            self.vmname)
        self.assertEqual(response.status_code, 202)

        # delete VMSS
        print('Deleting VMSS: ' + self.vmssname)
        response = azurerm.delete_vmss(self.access_token, self.subscription_id, self.rgname, \
            self.vmssname)
        self.assertEqual(response.status_code, 202)

        # delete Availability Set
        print('Deleting Availability Set: ' + self.asname)
        response = azurerm.delete_as(self.access_token, self.subscription_id, self.rgname, \
            self.asname)
        self.assertEqual(response.status_code, 200)
Пример #3
0
# Load Azure app defaults
try:
    with open('azurermconfig.json') as configFile:
        configData = json.load(configFile)
except FileNotFoundError:
    print("Error: Expecting azurermonfig.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)

# create an availability set
print('Enter availability set name to create.')
asname = input()
location = 'eastus'
update_domains = 5
fault_domains = 3
asreturn = azurerm.create_as(access_token, subscription_id, resource_group,
                             asname, update_domains, fault_domains, location)
print(asreturn)

print('Availability set details...')

# get availability set details
as_info = azurerm.get_as(access_token, subscription_id, resource_group, asname)
print(json.dumps(as_info, sort_keys=False, indent=2, separators=(',', ': ')))
Пример #4
0
        configData = json.load(configFile)
except FileNotFoundError:
    print("Error: Expecting azurermonfig.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
)

# create an availability set
print('Enter availability set name to create.')
asname = input()
location = 'eastus'
update_domains = 5
fault_domains = 3
asreturn = azurerm.create_as(access_token, subscription_id, resource_group, asname,
                             update_domains, fault_domains, location)
print(asreturn)

print('Availability set details...')

# get availability set details
as_info = azurerm.get_as(access_token, subscription_id, resource_group, asname)
print(json.dumps(as_info, sort_keys=False, indent=2, separators=(',', ': ')))
Пример #5
0
try:
    with open('azurermconfig.json') as configFile:
        CONFIG_DATA = json.load(configFile)
except FileNotFoundError:
    print("Error: Expecting azurermonfig.json in current folder")
    sys.exit()

TENANT_ID = CONFIG_DATA['tenantId']
APP_ID = CONFIG_DATA['appId']
APP_SECRET = CONFIG_DATA['appSecret']
SUB_ID = CONFIG_DATA['subscriptionId']
LOCATION = CONFIG_DATA['region']
ACCESS_TOKEN = azurerm.get_access_token(TENANT_ID, APP_ID, APP_SECRET)

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

# create an availability set
print('Enter availability set name to create.')
AS_NAME = input()
UDS = 5
FDS = 3
RET = azurerm.create_as(ACCESS_TOKEN, SUB_ID, RG_NAME, AS_NAME, UDS, FDS,
                        LOCATION)
print(RET)

# get availability set details
print('Availability set details...')
AS_INFO = azurerm.get_as(ACCESS_TOKEN, SUB_ID, RG_NAME, AS_NAME)
print(json.dumps(AS_INFO, sort_keys=False, indent=2, separators=(',', ': ')))