How to mount a custom ISO to a Virtual Machine
Step-by-step guide with PyVss
This section assumes, you have already set up both VSS_API_USER and VSS_API_USER_PASS environment variables and installed PyVss.
Create an instance of VssManager, generate token via get_token, and create an instance of the webdavclient using get_vskey_stor method as follows:
from pyvss.manager import VssManager vss = VssManager(None) vss.get_token() # generates token vss.get_vskey_stor() # creates a WebDav Client instance to interact with VSKEY-STOR
Upload the given iso to any given directory or to your home. In this case, we will use the isos folder:
# upload vss.vskey_stor.upload_sync(local_path='~/Downloads/debian-live-8.6.0-amd64-gnome-desktop.iso', remote_path='isos/debian-live-8.6.0-amd64-gnome-desktop.iso') # check if uploaded vss.vskey_stor.info('isos/debian-live-8.6.0-amd64-gnome-desktop.iso') {'created': None, 'name': None, 'modified': 'Tue, 01 Nov 2016 13:49:31 GMT', 'size': '1394147328'}
- Get the path to mount in the Virtual Machine
isos = vss.get_isos(name='debian-live') iso = isos[0].get('path')
Get VM and Mount given ISO:
# get target vm uuid vms = vss.get_vms(name='vm-testing') uuid = vms[0].get('uuid') # submit change request r = vss.update_vm_cd(uuid=uuid, cd=1, iso=iso) # wait for request to be processed completed = vss.wait_for_request(request_url=r.get('_links').get('request'), request_attr='status', required_status='Processed')
Step-by-step guide with API Calls
Upload ISO to VSKEY-STOR
Login to vskey-stor here.
Upload the desired iso file to your account. After uploading you will see the item available in the web interface:
Get ISO path
With your token make a request to the /iso endpoint filtered by name to get the actual ISO path:
Requesthttp GET "https://vss-api.eis.utoronto.ca/v2/iso?name=gnome" "Authorization: Bearer $TK"
Save [vssUser-xfers] jm/debian-live-8.5.0-amd64-gnome-desktop.iso string, since you'll need this eventually
Mount the ISO
Get virtual machine UUID using the search feature in the /vm resource:
Requesthttp GET "https://vss-api.eis.utoronto.ca/v2/vm?name=vm-testing&summary" "Authorization: Bearer $TK"
Now, we need to verify CD 1 settings, specifically the backing attribute in the data object which has to be set to "client" by default:
Requesthttp GET "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/cd/1" "Authorization: Bearer $TK"
To update CD 1 backend according to the docs, it can be done by making a PUT request to the /vm/<vm_uuid>/cd/1 endpoint with the attribute set to iso and value set to the ISO path, in this case [vssUser-xfers] jm/debian-live-8.5.0-amd64-gnome-desktop.iso
http PUT "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/cd/1" attribute='iso' value="[vssUser-xfers] jm/debian-live-8.5.0-amd64-gnome-desktop.iso" "Authorization: Bearer $TK"
After a few seconds, the ISO file will be mounted and the CD1 would show something like:
http GET "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/cd/1" "Authorization: Bearer $TK"
Unmount the ISO
Once the ISO file is no longer required, you can unmount it by making a PUT request to the same endpoint /vm/<vm_uuid>/cd/1 with attribute set to client and value set to empty.
http PUT "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/cd/1" "Authorization: Bearer $TK" attribute='client' value=''
If the request has been successfully processed, the CD 1 endpoint will show show the following response body:
http GET "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/cd/1" "Authorization: Bearer $TK"
Related articles