How to access and use MS Azure ?
Account creation
- Go to https://azure.microsoft.com/en-us/free/students/
- Login using MSE credentials
- Fill information (email and phone number)
- Accept contract
Create an instance using Azure Web Portal
The following tutorial will guide you through the creation of your first instance.
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/quick-create-portal
Note: This tutorial aims to start a Windows instance. To start a Linux instance (ubuntu, debian,...) choose a linux image in step 5
Setting up a local dev environment
-
Install Required components:
-
Follow the steps to set up your local dev environment described in the following web page:
Note: Although we recommend you to use source control, Source control section is not mandatory
Resources and code examples
CREATION OF AN INSTANCE
# Obtain the management object for virtual machines
compute_client = ComputeManagementClient(credential, subscription_id)
poller = compute_client.virtual_machines.begin_create_or_update(RESOURCE_GROUP_NAME, VM_NAME,
{
"location": LOCATION,
"storage_profile": {
"image_reference": {
"publisher": 'Canonical',
"offer": "UbuntuServer",
"sku": "16.04.0-LTS",
"version": "latest"
}
},
"hardware_profile": {
"vm_size": "Standard_DS1_v2"
},
"os_profile": {
"computer_name": VM_NAME,
"admin_username": USERNAME,
"admin_password": PASSWORD,
"linuxConfiguration": {
"ssh": {
"publicKeys": [
{
"path": "/home/{}/.ssh/authorized_keys".format(USERNAME),
"keyData": "ssh-rsa AAAK7obXXXXXXXXXXX"
}
]
},
"disablePasswordAuthentication": True
}
},
"network_profile": {
"network_interfaces": [{
"id": nic_result.id,
"properties": {
"primary": True
}
}]
}
}
)
vm_result = poller.result()
print(f"Provisioned virtual machine {vm_result.name}")
GET THE STATUS OF AN INSTANCE
# List VMs in subscription print('\nList VMs in subscription') for vm in compute_client.virtual_machines.list_all(): print("\tVM: {}".format(vm.name)) # List VM in resource group print('\nList VMs in resource group') for vm in compute_client.virtual_machines.list(GROUP_NAME): print("\tVM: {}".format(vm.name))
DELETION OF AN INSTANCE
# Delete VM print('\nDelete VM') async_vm_delete = compute_client.virtual_machines.delete( GROUP_NAME, VM_NAME) async_vm_delete.wait()
Storage
upload blobs
# Create a blob client using the local file name as the name for the blob
blob_client = blob_service_client.get_blob_client(container=container_name, blob=local_file_name)
print("\nUploading to Azure Storage as blob:\n\t" + local_file_name)
# Upload the created file
with open(upload_file_path, "rb") as data:
blob_client.upload_blob(data)
More information in this link
Download blobs
# Download the blob to a local file # Add 'DOWNLOAD' before the .txt extension so you can see both files in the data directory download_file_path = os.path.join(local_path, str.replace(local_file_name ,'.txt', 'DOWNLOAD.txt')) blob_client = blob_service_client.get_container_client(container= container_name) print("\nDownloading blob to \n\t" + download_file_path) with open(download_file_path, "wb") as download_file: download_file.write(blob_client.download_blob(blob.name).readall())
More information in this link
MORE INFORMATION
Azure Compute API documentation:
In this documentation you will find useful information about how to customise the instance you deploy using the Azure python SDK.
https://docs.microsoft.com/en-us/rest/api/compute/
Provision instance
The following tutorial explains how to deploy an instance using the Azure python SDK.
https://docs.microsoft.com/en-us/azure/developer/python/azure-sdk-example-virtual-machines?tabs=cmd
If you have any questions, please send an Email to Raoul(dot)Dupuis(at)hesge(dot)ch