Manage Virtual Machine from CLI

It is the main service that you must have in your Account to use all the other following services. From CLI is possible to manage the Virtual Machines (VM). Generally the life cycle of the VM includes the following steps.

The steps creation and capability assign are mandatory for service use.

Life Cycle of Virtual Machine

../../_images/ComputeLifeCycle.png

How to Create Virtual Machine

Add:

Using add command you are going to create a virtual machine and all it needs for applications that you will runs above. It is necessary to have an Account and the role with privileges who permit to use add command. The way to use the command add is the following:

$ beehive3 bu cpaas vms add -name NAME -account ACCOUNT -type TYPE -subnet SUBNET -image IMAGE -sg SG [-sshkey SSHKEY] [-pwd PWD] [-main-disk MAIN_DISK] [-other-disk OTHER_DISK][-hypervisor HYPERVISOR][-host-group HOST_GROUP][-multi-avz MULTI_AVZ] [-meta META]

  Create a Virtual Machine.

  Fields:
    name                  virtual machine name
    account               parent account id
    type                  virtual machine type
    subnet                virtual machine subnet id
    image                 virtual machine image id
    sg                    virtual machine security group id

    sshkey                ssh key name [optional]
    pwd                   root password [optional]
    main-disk             optional main disk size configuration. Use <size>:<tag> to set custom disk size and storage tag.
                          Ex. 5:oracle [optional]
    other-disk            list of additional disk sizes comma separated. Use :<tag> to set custom storage tag.
                          Ex. 5,10 or 5:oracle,10 [optional]
    hypervisor            set hypervisor. Can be: openstack or vsphere [optional default=openstack]
    meta                  custom metadata [optional]

  optional arguments:
    -h, --help            show this help message and exit
    -y                    Force delete
    -e ENV, --env ENV     Execution environment
    -f FORMAT             Output format
    -k KEY, --key KEY     Secret key file to use for encryption/decryption
    --vault VAULT         Ansible vault password to use for inventory decryption
    --time                Print command execution time
    --notruncate          Disable truncate of output
    --curl                Print api requst as curl command in console log

add example:

The example we are going to use for explain how to create a Virtual Machine has like as goal the VM named vm-demo inside account Datacenter.account-demo. All variables used in this example are mandatories. There are three steps that you could use to create a usable VM:

  • To get account id, type, subnet and image
  • To use add comand for creating the VM
  • To use the list command to verify that everything is OK

First Step

You are going to find the Account id using list command

$ beehive3 bu accounts get

   Account list obtained

   id                                    name          division    contact    managed      core services    base services  status    date
   ------------------------------------  ------------  ----------  ---------  ---------  ---------------  ---------------  --------  --------------------
   930aa960-374a-427b-9a33-a7869251e14e  account-demo  Datacenter  -          True                     0                0  ACTIVE    2019-02-20T08:49:15Z

List command help you to get from Nivola the Types that you can use within account-demo

$  beehive3 bu cpaas vms types


   VM Types list obtained

   id                                    instance_type    desc                           vcpus  disk    ram
   1bc4e93c-2130-4843-937b-01a44d80422d  vm.l16.5xlarge   vcpus:16 ram:64GB disk:80GB       16  80GB    64GB
   0ab0ce63-b3b7-4a5b-92f7-1d9bbcb4dd98  vm.l16.4xlarge   vcpus:16 ram:56GB disk:80GB       16  80GB    56GB
   cf63bf74-1355-463d-b785-3b93eb28718d  vm.l16.3xlarge   vcpus:16 ram:48GB disk:80GB       16  80GB    48GB
   c6af9f07-65a7-4ebb-aab2-17bf6772d2c5  vm.l16.2xlarge   vcpus:16 ram:40GB disk:80GB       16  80GB    40GB
   625a4c5a-506b-44b6-8384-97e19725d850  vm.l16.xlarge    vcpus:16 ram:32GB disk:80GB       16  80GB    32GB
   d35d19b3-d6b8-4208-b690-a51da2525497  vm.l16.large     vcpus:16 ram:24GB disk:80GB       16  80GB    24GB
   af209b92-d5e6-4e60-8139-5b2492f569a3  vm.c1.one        vcpus:12 ram:8GB disk:40GB        12  40GB    8GB
   be4aea04-2758-41ad-aeeb-931b83369388  vm.l8.7xlarge    vcpus:8 ram:128GB disk:80GB        8  80GB    128GB
   50ede1ca-cea7-4d15-b2ff-db7ce96ff36d  vm.l8.6xlarge    vcpus:8 ram:96GB disk:80GB         8  80GB    96GB
   38ff9b80-7ba6-4aa8-b6db-3cdaeb17247f  vm.l8.5xlarge    vcpus:8 ram:64GB disk:80GB         8  80GB    64GB
   9bb61461-f6e6-4540-99ea-2de3c0eac141  vm.l8.4xlarge    vcpus:8 ram:56GB disk:80GB         8  80GB    56GB
   d509186d-0b9a-45ad-8da4-64aa4a0b5284  vm.l8.3xlarge    vcpus:8 ram:48GB disk:80GB         8  80GB    48GB
   76a9b1da-b118-40ad-b0f8-31450b696f99  vm.l8.2xlarge    vcpus:8 ram:40GB disk:80GB         8  80GB    40GB
   e040ac12-86f5-41b1-a329-f3c3213b183a  vm.l8.xlarge     vcpus:8 ram:32GB disk:80GB         8  80GB    32GB
   7ddd3c4c-0b32-401f-bf3b-e90519ef6a34  vm.l8.large      vcpus:8 ram:24GB disk:80GB         8  80GB    24GB
   8b8c93a2-376d-4a5b-94d0-48cc5700333b  vm.m8.3xlarge    vcpus:8 ram:48GB disk:40GB         8  40GB    48GB
   860e7430-5244-4179-9e09-d8d8e97fe57c  vm.m8.2xlarge    vcpus:8 ram:40GB disk:40GB         8  40GB    40GB
   6affa6af-5c6d-4725-8311-354837a6ed8a  vm.m8.xlarge     vcpus:8 ram:32GB disk:40GB         8  40GB    32GB
   d15850cb-6ae7-4569-bdbb-27e8558c56f0  vm.m8.large      vcpus:8 ram:24GB disk:40GB         8  40GB    24GB
   526ff3e0-ceb7-4f3c-9c35-ba2274b0f59a  vm.m4.6xlarge    vcpus:4 ram:48GB disk:40GB         4  40GB    48GB

List command help you to get from Nivola the Subnets that you can use within account-demo

$  beehive3 bu netaas subnets list -accounts Acc_demo1_nmsflike -accounts account-demo

   Subnets list obtained

   id                                    name                     state      account    availabilityZone    vpc          cidr
   ------------------------------------  -----------------------  ---------  ---------  ------------------  -----------  ---------------
   015514b4-9533-4aa3-a449-91a02c45940x  SubnetInternet-torino01  available  gaetest    SiteTorino01        VpcInternet  84.240.190.0/24
   6f22eb27-3aea-40e2-be6b-af5ad1c4290x  SubnetWEB-vercelli01     available  gaetest    SiteVercelli01      VpcWEB       10.138.200.0/21
   85d9dc49-285e-426a-9bcb-ef56e90f498j  SubnetWEB-torino02       available  gaetest    SiteTorino02        VpcWEB       10.138.168.0/21
   8b64ee86-eda4-40d9-a206-e64c3aeba6a9  SubnetWEB-torino01       available  gaetest    SiteTorino01        VpcWEB       10.138.136.0/21
   09627b89-c342-4072-8f9f-2cf421e5393c  SubnetBE-vercelli01      available  gaetest    SiteVercelli01      VpcBE        10.138.192.0/21
   76cf51db-70d5-4084-a65e-61c4ab76aa7b  SubnetBE-torino02        available  gaetest    SiteTorino02        VpcBE        10.138.160.0/21
   2f8d7886-e08a-4512-a825-b7ac6bcfc3c6  SubnetBE-torino01        available  gaetest    SiteTorino01        VpcBE        10.138.128.0/21
   b07ef60a-4f64-4640-8d23-5a4e7b9d1920  SubnetInternet-torino01  available  clitest    SiteTorino01        VpcInternet  84.240.190.0/24
   e3cc531c-125f-40a2-8eb8-be3f81505369  SubnetWEB-vercelli01     available  clitest    SiteVercelli01      VpcWEB       10.138.200.0/21

List command help you to get from Nivola the Images that you can use within account-demo

$  beehive3 bu cpaas images list -accounts account-demo

   Images list obtained

   id                                    name                    state      type     account       platform       hypervisor
   24d58a6a-3828-4bcf-a003-a885d135d33c  Oracle19EE              available  machine  account-demo  OracleLinux 7  vsphere
   6686379b-bc54-4826-9a5f-2fc895077ebf  Oracle12EE              available  machine  account-demo  OracleLinux 7  vsphere
   ed3918ed-938c-4155-bf68-ea62b2d666ef  Oracle19                available  machine  account-demo  None None
   8bb43ffd-4385-438a-abbd-7991f04fae77  Oracle12                available  machine  account-demo  OracleLinux 7  vsphere
   3dd93fe2-0d81-4657-bc7b-1d61352e38e0  Oracle11                available  machine  account-demo  OracleLinux 7  vsphere
   2f330fcd-f0d2-4711-a4ec-b8ebac94a43e  RedhatLinux8            available  machine  account-demo  RedhatLinux 8  openstack
   ddc7aa6d-26fd-413f-b7ed-056c6e6d25a7  Centos8                 available  machine  account-demo  centos 8       openstack
   50276360-e996-40f1-a395-f801bc561767  MicrosoftSqlServer2017  available  machine  account-demo  Windows 2016   vsphere
   40f89578-4e90-4363-9898-cf86e0092062  Windows2019             available  machine  account-demo  Windows 2019   vsphere
   48d5bdbd-7876-44ab-b040-f107c9944d63  Windows2012             available  machine  account-demo  Windows 2012   vsphere
   96755454-1d2a-40dc-8744-d557f8156a76  Windows2016             available  machine  account-demo  Windows 2016   vsphere
   c612bbe9-ec94-46d7-978a-ab5d7e61543d  OracleLinux7            available  machine  account-demo  OracleLinux 7  openstack
   111ffa24-0729-48ff-b1a2-e23ade0fa77d  Ubuntu18                available  machine  account-demo  ubuntu 18      openstack
   e2d0edb7-6f6a-498e-9c02-cede3fb9074d  Centos6-nmsf            available  machine  account-demo  centos 6.10    openstack
   64adf40f-7378-4951-95cc-ea364dffe8c8  Centos7-docker          available  machine  account-demo  centos 7.7     openstack
   766a58cb-6c92-44d8-b997-c44ebaf07cb1  Centos7                 available  machine  account-demo  centos 7.5     openstack,vsphere
   79064aba-8627-4e6b-af09-53d166154335  Ubuntu16                available  machine  account-demo  ubuntu 16      openstack
   c3508165-9c39-4c71-9ce8-7efe7457bd49  Centos7-nmsf            available  machine  account-demo  centos 7.6     openstack
   7c392c75-3b7c-4591-8af3-a7550f1f8ec9  Centos6                 available  machine  account-demo  centos 6.9     openstack

At last you have to know the ssh key using the command ssh key list

$  beehive ssh keys list

   ssh keys list obtained

   id                                    name        desc    date                  pub_key
   ------------------------------------  ----------  ------  --------------------  -----------------------------------------------------------------------------------
   f057bff8-4d62-40fe-9b77-73ccb1b8e6fx  sshkey-demo         2018-09-05T11:16:23Z  c3NoLXJzYSBBQUFBQjNOemFDMXljMkVBQUFBREFRQUJBQUFCQVFDbXQyTmU3TXlFYUJLQ1VKOXBJR3dM...

Step two

You can create a VM using the add command obtaining the id from Nivola

$ beehive business cpaas vms add name=vm-demo account=Datacenter.account-demo type=vm.l8.large subnet=SubnetBE-torino02 image=Centos7 security-group=SecurityGroupBE key-name=sshkey-gae

  The VM vm-demo is created and Nivola will show you his id using the message follow

  msg
  ---------------------------------------------------------
  Add virtual machine: b0633d20-399e-4168-9f13-60fba49a40fe

To see the VM is running use the list command with the following syntax

$ beehive business cpaas vms list account=account-demo

  id                                    name              type         state    launchTime            account    availabilityZone    privateIp      privateDnsName                               image    subnet
  ------------------------------------  ----------------  -----------  -------  --------------------  ---------  ------------------  -------------  -------------------------------------------  -------  -------------------
  b0633d20-399e-4168-9f13-60fba49a40fe  vm-demo           vm.l8.large  running  2019-02-27T09:44:34Z  account-demo  SiteTorino02     10.138.160.62  vm-demo.site02.nivolapiemonte.it             Centos7  SubnetBE-torino02

How to List Virtual Machine

The command below is used to acces on Virtual machine instantiated into your account.

Access:

$  beehive ssh nodes connect <node> [nodeuser=..] [options ...]

  <node> is node name or uuid or ipadress
  <nodeuser> is node user default is is root

    optional arguments:
    -h, --help            show this help message and exit
    --debug               toggle debug output
    --quiet               suppress all output
    -o {json}             output handler
    -v, --version         show program's version number and exit
    -k KEY, --key KEY     Secret key file to use for encryption/decryption
    --vault VAULT         Ansible vault password to use for inventory decryption
    -e ENV, --env ENV     Execution environment
    -E ENVS, --envs ENVS  Comma separated execution environments
    -f FRMT, --frmt FRMT  response format
    --color COLOR         response colered. Can be true or false. [default=true]
    --verbose VERBOSITY   ansible verbosity
    --cmds                list available commands
    --notruncate          disable long string truncation
    --truncate TRUNCATE   set max length of long string
    --curl                log curl request
    --fields FIELDS       response fields
    --afields AFIELDS     response additional fields
    -y, --assumeyes       Assume that the answer to any question which would be
                          asked is yes.
    -rt, --runtime        Enable command duration log.

How to List Virtual Machine

The command below is used to ontain the list Virtual machine instantiated into your account.

list:

$ beehive business cpaas vms list account=account-demo

  id                                    name              type         state    launchTime            account    availabilityZone    privateIp      privateDnsName                               image    subnet
  ------------------------------------  ----------------  -----------  -------  --------------------  ---------  ------------------  -------------  -------------------------------------------  -------  -------------------
  b0633d20-399e-4168-9f13-60fba49a40fe  vm-demo           vm.l8.large  running  2019-02-27T09:44:34Z  account-demo  SiteTorino02     10.138.160.62  vm-demo.site02.nivolapiemonte.it             Centos7  SubnetBE-torino02

How to Update Virtual Machine

The commands below are used to update Virtual machine.

update:

The command is used to modify Virtual Machine attributes.

$ beehive bu cpaas vms update <vm> [field=..] [options ...]

  Update VM

  Fields:

    vm                   vm id
    type                 vm type

   optional arguments:   are the same described into add command

In this example we are going to change the type attribute.

$ beehive bu cpaas vms update b0633d20-399e-4168-9f13-60fba49a40fe type=vm.m8.xlarge

  update

This is the Nivola response when the type was changed

$ msg
  -----------------------------------------------------------
  Modify virtual machine b0633d20-399e-4168-9f13-60fba49a40fe

How to Start Virtual Machine

If it is necessary to start the VM, you have to use next command from CLi:

$ beehive bu cpaas vms start <vm>

  <vm> is a vm's id

    optional arguments:
    -h, --help            show this help message and exit
    --debug               toggle debug output
    --quiet               suppress all output
    -o {json}             output handler
    -v, --version         show program's version number and exit
    -k KEY, --key KEY     Secret key file to use for encryption/decryption
    --vault VAULT         Ansible vault password to use for inventory decryption
    -e ENV, --env ENV     Execution environment
    -E ENVS, --envs ENVS  Comma separated execution environments
    -f FRMT, --frmt FRMT  response format
    --color COLOR         response colered. Can be true or false. [default=true]
    --verbose VERBOSITY   ansible verbosity
    --cmds                list available commands
    --notruncate          disable long string truncation
    --truncate TRUNCATE   set max length of long string
    --curl                log curl request
    --fields FIELDS       response fields
    --afields AFIELDS     response additional fields
    -y, --assumeyes       Assume that the answer to any question which would be
                          asked is yes.
    -rt, --runtime        Enable command duration log.

How to Stop Virtual Machine

If you need to stop the VM, you have to use next command:

$ beehive bu cpaas vms stop <vm>

  <vm> is a vm's id

    optional arguments:
    -h, --help            show this help message and exit
    --debug               toggle debug output
    --quiet               suppress all output
    -o {json}             output handler
    -v, --version         show program's version number and exit
    -k KEY, --key KEY     Secret key file to use for encryption/decryption
    --vault VAULT         Ansible vault password to use for inventory decryption
    -e ENV, --env ENV     Execution environment
    -E ENVS, --envs ENVS  Comma separated execution environments
    -f FRMT, --frmt FRMT  response format
    --color COLOR         response colered. Can be true or false. [default=true]
    --verbose VERBOSITY   ansible verbosity
    --cmds                list available commands
    --notruncate          disable long string truncation
    --truncate TRUNCATE   set max length of long string
    --curl                log curl request
    --fields FIELDS       response fields
    --afields AFIELDS     response additional fields
    -y, --assumeyes       Assume that the answer to any question which would be
                          asked is yes.
    -rt, --runtime        Enable command duration log.

How to Delete Virtual Machine

The commands below are used to erase Virtual machine from Nivola.

delete:

The command is used to erase Virtual Machine from the cloud-system

$ beehive bu cpaas vms delete <vm> [options ...]


  Delete a Virtual Machine

  Fields:

    vm                   is the vm id


  optional arguments:     are the same described into add command

Next example show you how to use delete command

$ beehive bu cpaas vms delete 59e7e61c-665d-48a5-8ca3-a769e45f8e1b


  Delete VM

Below the nivola’s response after VM was deleted

$ msg
  -----------------------------------------------------------
  Delete virtual machine 59e7e61c-665d-48a5-8ca3-a769e45f8e1b