Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Working with Virtual Machines

shoenisch edited this page Apr 18, 2017 · 8 revisions

Creating a Virtual Machine from an Image

You create a virtual machine by specifying an image, a name, a flavor, and an ephemeral boot disk. Unlike persistent disks, which must be created before they can be attached to a VM, ephemeral disks are created when the VM is created and discarded when the VM is removed.

When you create a VM, you combine an image and a flavor (CPU and memory resource limits) with an ephemeral boot disk. You can attach other disks to the VM during or after creation.

To create a VM in interactive mode, use the photon vm create command with no options. The command prompts you for the VM name, flavor, and source image ID. Example:

photon vm create 
VM name: vm-1 VM 
flavor: core-100 
Image id: 5889ea6b-20ca-4706-99e8-f87096d2c274 
Disk 1 (ENTER to finish): 
Name: disk-1 
Flavor: core-100 
Boot disk? [y/n]: y 

Disk 2 (ENTER to finish): 
Name: 
Creating VM: vm-1 (core-100) 
Source image id: 5889ea6b-20ca-4706-99e8-f87096d2c274 
Disks: 1: disk-1, core-100, boot 
Are you sure? y 
VM 'bac117cb-fc32-46e0-abcd-999199c6b6d5' created 

You can also supply this information when you run the photon vm create command with the non-interactive option, -n. Example:

photon vm create -n vm-1 -f core-100 -d "disk-1 core-100 boot=true" 
-i 5889ea6b-20ca-4706-99e8-87096d2c274
{:name=>"vm-1"} 
Creating VM: vm-1 (core-100) 
Source image id: 5889ea6b-20ca-4706-99e8-f87096d2c274
Disks: 1: disk-1, core-100, boot

Getting Information about VMs

Get a list of all the VMs in your project:

photon vm list

Get information about a VM:

photon vm show <ID>
photon vm show bac117cb-fc32-46e0-abcd-999199c6b6d5

You can use the photon vm networks command to get more information about a VM's network connections:

photon vm networks 3db6bd84-4fe2-413f-b502-f60f75f74f2d

Attaching Persistent Disks to VMs

Persistent disks endow virtual machines with resources for a project. You can attach a persistent disk to a VM, but after you discard the VM, the disk persists. Disks stick with a project, and they cannot be used by other projects.

Photon Controller categorizes persistent disks as a type of flavor, subtracting each persistent disk from the resources allocated to a project.

The following example commands assume you have set the default project.

Here are the commands to create persistent disks. The commands assume you have set the default project.

photon disk create

The command prompts you for the disk name, flavor, and capacity. Example:

DISK name: disk-2
DISK flavor: core-100
DISK capacity in GB: 10

The following command creates the same persistent disk by specifying the disk's properties in the command:

photon disk create -n disk-2 -f core-100 -g 10

Here's how to delete a disk:

photon disk delete <disk-ID>

Example:

photon disk delete dab22828-8cfe-441d-b837-b197adbc651e

A persistent disk can be attached to a powered-off VM:

photon vm stop <VM-ID>
photon vm attach_disk <VM-ID <disk-ID>
photon vm detach_disk <VM-ID <disk-ID>

Examples:

photon vm attach_disk bac117cb-fc32-46e0-abcd-999199c6b6d5 
				-d dab22828-8cfe-441d-b837-b197adbc651e

photon vm detach_disk bac117cb-fc32-46e0-abcd-999199c6b6d5 
				-d dab22828-8cfe-441d-b837-b197adbc651e

Attaching an ISO to a VM

Here's how to upload and attach an ISO to a powered-off VM:

photon vm attach_iso <VM-ID> -p path -n name

Example:

photon vm attach_iso bac117cb-fc32-46e0-abcd-999199c6b6d5 -p /tmp/db.iso -n test-db

Operating a Virtual Machine

You can start, stop, restart, suspend, and resume a virtual machine by citing its ID. Examples:

photon vm start bac117cb-fc32-46e0-abcd-999199c6b6d5
photon vm stop bac117cb-fc32-46e0-abcd-999199c6b6d5
photon vm suspend bac117cb-fc32-46e0-abcd-999199c6b6d5
photon vm resume bac117cb-fc32-46e0-abcd-999199c6b6d5

Other Options for Creating VMs

You can run the photon vm create command with additional options, the following help output for the command shows:

photon vm create --help
NAME:
   photon vm create - Create a new VM

USAGE:
   photon vm create [command options]  

OPTIONS:
   --name value, -n value              VM name
   --flavor value, -f value            VM flavor
   --image value, -i value             Image ID
   --boot-disk-flavor value, -b value  Boot disk flavor
   --disks value, -d value             VM disks
   --environment value, -e value       VM environment({key:value})
   --affinities value, -a value        VM Locality(kind id)
   --networks value, -w value          VM Networks(id1, id2)
   --tenant value, -t value            Tenant name
   --project value, -p value           Project name

For example, adding the --boot-disk-flavor option to the photon vm create command inserts the boot disk as the first disk implicitly. In interactive mode, the Photon CLI may prompt you for additional data disks, which can no longer be a boot disk. When --boot-disk-flavor does not appear in the command in interactive mode, you may be prompted to supply it but command prompt accepts an empty value. If it's empty, you are prompted to supply disk and at least one boot disk is required.

Clone this wiki locally