Command Line Cheat Sheet

shoenisch edited this page Jan 6, 2017 · 5 revisions
Clone this wiki locally

This cheat sheet lists common Photon Controller commands. The commands assume that you have installed Photon Controller with authentication turned on.

Viewing help for commands: For information about photon commands, subcommands, and options, see the help for the Photon CLi. Examples:

photon --help
photon resource-ticket create --help
photon cluster create -h

Here's the output of photon -h:

NAME:
   photon - Command line interface for Photon Controller
USAGE:
   photon [global options] command [command options] [arguments...]
VERSION:
   Git commit hash: 63a4889
COMMANDS:
   auth         options for auth
   system       options for system operations
   target       options for target
   tenant       options for tenant
   host         options for host
   deployment       options for deployment
   resource-ticket  options for resource-ticket
   image        options for image
   task         options for task
   flavor       options for flavor
   project      options for project
   disk         options for disk
   vm           options for vm
   network      options for network
   cluster      Options for clusters
   availability-zone    options for availability-zone
   help, h      Shows a list of commands or help for one command
GLOBAL OPTIONS:
   --non-interactive, -n    trigger for non-interactive mode (scripting)
   --log-file, -l       writes logging information into a logfile at the specified path
   --output, -o         Select output format
   --help, -h           show help
   --version, -v        print the version

Non-interactive mode: The -n option suppresses prompting but assumes that the command contains all the information required to execute successfully.

Replacing variables in commands: Many of the commands in this cheat sheet contain <variables> that you must replace. Commands containing variables are often immediately followed by examples with the variables replaced.

Setting Targets and Logging In

Find the load balancer's IP address:

photon deployment show

Connect to the IP address of the load balancer:

photon target set https://<ip_address>:443

Log in:

photon target login --username <username>@<oauth_tenant> --password <password>
photon target login --username pc-admin@esxcloud --password 'Your$ecret1!'

Check the system's status:

photon system status

Images

Upload an image by using the photon image create command:

photon image create <local-path-to-image> -n <name> -i <replicationType> 
photon image create /tmp/ubuntu14-04.ova -n ubuntu1404 -i ON_DEMAND 

Create an image, list all your images, show information about an image, and then delete it:

photon image create <image_filename> -n <image_name> -i <image_type>
photon image create photon-kubernetes-vm-disk1.vmdk -n photon-kubernetes-vm.vmdk -i EAGER
photon image list
photon image show <image-ID>
photon image show 96cd7af4-f1d0-45ea-8ed1-e18bef6c05ca
photon image delete <image-ID>
photon image delete 96cd7af4-f1d0-45ea-8ed1-e18bef6c05ca

Tenants and Projects

Here are some of the commands for managing tenants and resource tickets:

photon tenant create <name_of_tenant>
photon tenant list
photon tenant show <tenant-ID>
photon resource-ticket list
photon resource-ticket show <resource ticket name>
photon resource-ticket create 

Here are some examples:

photon tenant create plato
photon resource-ticket create --tenant "plato" --name "plato-resources" 
--limits "vm.memory 100 GB, vm.cpu 100 COUNT, vm 100 COUNT, 
          persistent-disk 100 COUNT, persistent-disk.capacity 200 GB" 
photon project create --tenant "plato" --name "plato-prjt" --resource-ticket "plato-resources" 
--limits "vm.memory 100 GB, vm.cpu 100 COUNT, vm 100 COUNT, 
          persistent-disk 100 COUNT, persistent-disk.capacity 200 GB" 
photon tenant set "plato"
photon project set "plato-prjt"

Flavors and Disks

Here are examples of how to provision resources for virtual machines or clusters with photon flavor create:

photon -n flavor create --name "vm-basic" --kind "vm" 
                        --cost "vm 1 COUNT, vm.cpu 2 COUNT, vm.memory 2 GB" 
photon -n flavor create --name "disk-eph" --kind "ephemeral-disk" 
                        --cost "ephemeral-disk 1 COUNT"
photon -n flavor create --name "disk-persist" --kind "persistent-disk" 
                        --cost "persistent-disk 1 COUNT"
photon -n flavor create --name "my-vm" --kind "vm" 
                        --cost "vm 1 COUNT, vm.cpu 1 COUNT, vm.memory 2 GB"

Virtual Machines and Disks

Stop a VM by its ID and create a new image from it:

photon vm stop bac117cb-fc32-46e0-abcd-999199c6b6d5
photon vm create-image bac117cb-fc32-46e0-abcd-999199c6b6d5 -n image-1 -r ON_DEMAND

More examples of creating a VM:

photon vm create -n vm-1 -f core-100 -d "disk-1 core-100 boot=true" 
-i 5889ea6b-20ca-4706-99e8-87096d2c274
photon -n vm create --name vm-1 --flavor tiny --disks "disk-1 core-100 boot=true" 
-w “ID of Network”  -i “ID of Image”  --affinities disk:"ID of Persistent disk”

Get a list of all the VMs in your project and show the information about one of them:

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

Here are examples of how to create a peristent disk:

photon disk create -n disk-2 -f core-100 -g 10
photon  disk create --name persistent-disk-1 --flavor core-100 
--capacityGB 10 --affinities vm:”ID of VM”

Attach or detach a persistent disk to or from a powered-off VM:

photon vm stop <VM-ID>
photon vm attach_disk <VM-ID <disk-ID>
photon vm attach_disk bac117cb-fc32-46e0-abcd-999199c6b6d5 
  -d dab22828-8cfe-441d-b837-b197adbc651e
photon vm detach_disk <VM-ID <disk-ID>
photon vm detach_disk bac117cb-fc32-46e0-abcd-999199c6b6d5 
  -d dab22828-8cfe-441d-b837-b197adbc651e

Delete a disk:

photon disk delete <disk-ID>
photon disk delete dab22828-8cfe-441d-b837-b197adbc651e

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

photon vm attach_iso <VM-ID> -p path -n name
photon vm attach_iso bac117cb-fc32-46e0-abcd-999199c6b6d5 -p /tmp/db.iso -n test-db

Operate a VM by citing its ID:

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

Clusters

Here are examples of how to establish resources for a Kubernetes cluster:

photon image create photon-kubernetes-vm-disk1.vmdk -n photon-kubernetes-vm.vmdk -i EAGER
photon image list
photon deployment list
photon deployment enable-cluster-type <deployment_ID> -k KUBERNETES -i <Kubernetes_image_ID>

Here's how to create a Kubernetes cluster. Replace the example IP addresses with those from your Photon Controller environment. The IP address for the master-ip option should contain the static IP address that you want to assign to the Kubernetes cluster. The etcd option should also contain a static IP address.

photon cluster create -n kube-socrates -k KUBERNETES --master-ip 198.51.100.85 
--etcd1 198.51.100.86 --container-network 192.0.2.0/16 --dns 198.51.100.1 
--gateway 198.51.100.253 --netmask 255.255.0.0

More photon cluster commands:

photon cluster list

To get the Kubernetes master node IP address, use show:

photon cluster show <cluster-id>

See all the VMs in a cluster:

photon cluster list_vms <cluster-ID>

Delete it:

photon cluster delete <cluster-ID>

Availability Zones

Create an availability zone, set it as the default, and create a VM in it:

Photon availability_zone create --name “zone-name”
photon host set_availability_zone <hostID> <availabilityZoneID>
photon -n vm create --name vm-2 --flavor core-200 --disks "new-disk core-200 boot=true" 
--affinities "availabilityZone:UUIDofAZ"

Authentication

View your token:

photon auth show-login-token

Example output:

    Login Access Token:
    Subject: faulkner@esxcloud
    Groups: esxcloud\group11, esxcloud\Everyone
    Issued: 2016-11-30 04:02:15.00
    Expires: 2016-11-30 04:07:15.00
    Token: ...