in src/hpcadvisor/batch_handler.py [0:0]
def create_testvm(subscription_id, resource_group, vmname, sku):
cloudinitfile = "cloud-init.txt"
cloudinitcontent = f"""#cloud-config
runcmd:
- echo "mounting shared storage on vm"
- mkdir /nfs
- mount {env["STORAGEACCOUNT"]}.file.core.windows.net:/{env["STORAGEACCOUNT"]}/data /nfs"""
with open(cloudinitfile, "w") as w:
w.write(cloudinitcontent)
adminuser = "azureuser"
ssh_key = open(os.path.expanduser("~/.ssh/id_rsa.pub")).read()
credentials = _get_credentials()
compute_client = ComputeManagementClient(credentials, subscription_id)
network_client = NetworkManagementClient(credentials, subscription_id)
nicname = f"{resource_group}{vmname}nic"
nic_poller = network_client.network_interfaces.begin_create_or_update(
resource_group,
nicname,
{
"location": env["REGION"],
"ip_configurations": [
{
"name": "myipconfig",
"subnet": {
"id": "/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Network/virtualNetworks/{}/subnets/{}".format(
subscription_id,
resource_group,
env["VNETNAME"],
env["VSUBNETNAME"],
)
},
"public_ip_address": None,
}
],
},
)
nic_result = nic_poller.result()
os_profile = OSProfile(computer_name=vmname, admin_username=adminuser)
os_profile.linux_configuration = LinuxConfiguration(
ssh=SshConfiguration(
public_keys=[
SshPublicKey(
path=f"/home/{adminuser}/.ssh/authorized_keys", key_data=ssh_key
),
],
)
)
custom_data = get_file_content(cloudinitfile)
os_profile.custom_data = b64encode(custom_data)
publisher, offer, image_sku, version = _get_image_info(VMIMAGE)
vm_poller = compute_client.virtual_machines.begin_create_or_update(
resource_group,
vmname,
{
"location": env["REGION"],
"storage_profile": {
"image_reference": {
"publisher": publisher,
"offer": offer,
"sku": image_sku,
"version": version,
}
},
"hardware_profile": {"vm_size": sku},
"os_profile": os_profile,
"network_profile": {"network_interfaces": [{"id": nic_result.id}]},
# "identity": {
# "type": "UserAssigned",
# "user_assigned_identities": None, # VirtualMachineIdentityUserAssignedIdentitiesValue
# },
},
)
vm_result = vm_poller.result()
log.info(f"Provisioned virtual machine {vm_result.name}")