Tutorial: VM Lifecycle

The normal lifecycle of a virtual machine involves starting a machine instance, interacting with that instance (either by logging in or using services provided by the instance), and then shutting the machine down. The section of the tutorial walks you through this lifecycle and demonstrates the associated commands.

Note: You must have a username/password for the StratusLab cloud installation that you are using. Contact the support mailing list if you want access to the StratusLab reference cloud infrastructure.

Configure User Parameters

User parameters configuration depends on how you installed the StratusLab client tools:

  • from an RPM package or,
  • from a standalone tarball.

Installation from an RPM

mkdir $HOME/.stratuslab
cp /etc/stratuslab/stratuslab-user.cfg.ref $HOME/.stratuslab/stratuslab-user.cfg 

Installation from tarball

mkdir $HOME/.stratuslab
cp $HOME/stratuslab/conf/stratuslab-user.cfg.ref  $HOME/.stratuslab/stratuslab-user.cfg 

In stratuslab-user.cfg, in case you chose rpm or tarball installation, provide the Cloud frontend, your username/password, and your ssh public key.

endpoint = <Cloud endpoint URL>
username = <StratusLab username>
password = <StratusLab password>
user_public_key_file = <ssh public key filename>

Other information could be provided (aren't mandatory to create VM instance), like:

  • PEM key/cert if you want to use authentication with grid certificate, if username/password and PEM key/cert are both enabled, PEM key/cert takes precedence.
  • marketplace_endpoint: Marketplace endpoint to be used when uploading metadata, and/or when creating instance of VM
  • p12_certificate: PKSC12-formatted certificate, for signing and validating image metadata
  • apprepo_endpoint, apprepo_username, apprepo_password: Appliance repository endpoint, username and password to be able to upload images and appliances to the Appliance repository.

Don't want to use stratuslab-user.cfg

Setup the environment with this information:

export STRATUSLAB_KEY=<ssh public key filename>
export STRATUSLAB_USERNAME=<StratusLab username>
export STRATUSLAB_PASSWORD=<StratusLab password>
export STRATUSLAB_ENDPOINT=<Cloud endpoint URL>

Create a Virtual Machine Instance

To demonstrate how to launch a simple machine, we will use the ttylinux-10.0 image from the appliance repository, identified in the Marketplace by BzrqtDb2pYxA5_jha4IXG4WLyD3 .

The command stratus-run-instance allows you to create a new instance of an image stored in the appliances repository and identified by an ID in the Marketplace. Here is how you can create a new instance of the ttylinux base image:

export TTYLINUX_MarketplaceID=GOaxJFdoEXvqAm9ArJgnZ0_ky6F

The –key allows you to specify a public key to be inserted in the new instance, such that you can SSH to it using your private key. The <public-key-filename> value should correspond to the id_rsa.pub file created earlier during this tutorial.

Creating new instance of ttylinux by passing it's ID in the Marketplace:

stratus-run-instance $TTYLINUX_MarketplaceID 

By default StratusLab Marketplace endpoint is: http://marketplace.stratuslab.eu.

If you are using another Marketplace, please provide it in your $HOME/.stratuslab/stratuslab-user.cfg,

or set the environment variable STRATUSLAB_MARKETPLACE_ENDPOINT with the Markeplace endpoint you want to use,

or pass it as argument to stratus-run-instance command when starting instance.

If provided in your $HOME/.stratuslab/stratuslab-user.cfg

stratus-run-instance $TTYLINUX_MarketplaceID 

If set up as environment variable, like:

export STRATUSLAB_MARKETPLACE_ENDPOINT=http://yourMarketplace

Then

stratus-run-instance  $TTYLINUX_MarketplaceID 

Else

stratus-run-instance --marketplace-endpoint=http://yourMarketplace $TTYLINUX_MarketplaceID 

Like all StratusLab commands, -h or –help will give you the list of options the command supports.

Issuing the above command will produce an output similar to this:

 ::::::::::::::::::::::::
 :: Starting 1 machine ::
 ::::::::::::::::::::::::

 :: Machine 1 (vm ID: 17)
        public IP: 134.158.73.236
 :::::::::::
 :: Done! ::
 :::::::::::

Once the new instance has been created, you should be able to log into it as soon as it is fully booted.

You can choose between public (default), local and private IP assignment for your new instances. Using stratus-run-instance add –local–ip or –private-ip to instruct StratusLab to assign a local IP address (i.e. locally accessible from inside the site but not from outside), or private IP address (i.e. unreachable machine, which implies that the instance will initiate the communication with other machines/instances).

Interact with Machine Instance

Determining the Status

To determine the status of one or several instances, you can use the stratus-describe-instance command. With the environment variables defined as above you can simply issue the following command to query the status of all of your active instances:

$ stratus-describe-instance
id  state           cpu       memory    public ip
16  Running         1         128       134.158.73.235  
17  Running         1         128       134.158.73.236  

You can also specify a particular vm-id to see the information for a single machine instance. This will also provide information for inactive machines that no longer appear in the list.

$ stratus-describe-instance 17
id  state           cpu       memory    public ip
17  Running         1         128       134.158.73.236  

Logging into the Instance

Once the instance is running, you should be able to ping the machine instance or log into using SSH. Here's an example:

$ ping <ip-address>
$ ssh -i <private-key-file> root@<ip-address>

The <ip-address> corresponding to your instance is provided by the stratus-run-instance, the Web Monitor application or stratus-describe-instance command. The private key file must be the one which corresponds to the public key that you gave when starting the machine.

You can also log into your VM using stratus-connect-instance command and VM identifier:

$ stratus-connect-instance VM_ID

You log into the machine using the root account. All of the default base images have only the root account configured. As you have root access, you can install new software, change the configuration, etc. Reboot the instance will preserve those changes; however, those changes will be lost when the instance is killed.

Terminating an Instance

Graceful Shutdown

You can shutdown the instance gracefully from within the machine, issue either the halt or shutdown commands. You should use a command that powers down the machine for the OS that you have running. For ttylinux, the command is:

$ shutdown -h 

This will execute the normal shutdown sequence and then free the resources associated with the instance. If you halt the machine rather than power it down, you can kill the instance with the StratusLab client.

Using stratus-shutdown-instance, shutdown could also be performed on machines supporting ACPI, just launch:

$ stratus-shutdown-instance VM_ID 

NB. ttylinux doesn't support ACPI.

Killing an Instance

To terminate an instance from the outside, you can use the StratusLab client:

$ stratus-kill-instance <vm-id> ...

This command allows you to specifiy one or more <vm-id>.

Note that this is the equivalent of yanking the powercord from the socket. Use a graceful shutdown if there is any chance of leaving resources in a bad state (e.g. having external data mounted in the instance).

  • Bookmark at
  • Bookmark "Tutorial: VM Lifecycle" at del.icio.us
  • Bookmark "Tutorial: VM Lifecycle" at Digg
  • Bookmark "Tutorial: VM Lifecycle" at Reddit
  • Bookmark "Tutorial: VM Lifecycle" at Google
  • Bookmark "Tutorial: VM Lifecycle" at StumbleUpon
  • Bookmark "Tutorial: VM Lifecycle" at Facebook
  • Bookmark "Tutorial: VM Lifecycle" at Twitter