Tutorials

How to Correctly Use Stop, Start, Reset on ProfitBricks

Table of Contents

Introduction

Some of the common questions fielded by the support team at ProfitBricks is how to correctly use the stop, start, and reset features. These features are accessible from the DCD or through the API.

In our code examples we will show you how to invoke these methods using the Libcloud library for Python. Libcloud is a Python module that unifies multiple cloud providers into a single namespace, e.g. create_node.

Stopping a VM

If your desired goal is to issue a hard reboot to the machine you would use the "reset" feature. Stopping a virtual machine will have the following impact on that instance:

  • Any DHCP assigned IP addresses will be deallocated. This includes any public IP addresses.
  • All billing for cores (cpu) and memory will halt. You will continue to be billed for the storage of the volume attached to the server.

In most situations you would not need to stop a virtual machine unless you do not wish to be billed for the machine.

Using Libcloud to Stop a VM

You will need to first do

pip install apache-libcloud

Once that is done, you can then create a simple python script to stop a VM.

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

username = 'username'
password = 'password'

cls = get_driver(Provider.PROFIT_BRICKS)
driver = cls(username, password)

nodes = driver.list_nodes()

node = [n for n in nodes if 'yourservername' in n.name][0]

driver.ex_stop(node=node)

Starting a VM

Starting a virtual machine can be performed within the DCD or through the API. When you issue a start request to a stopped virtual machine the following will happen:

  • If the instance is using DHCP for private or public IPs those IPs will be allocated at that time.
  • Billing will begin again for any memory and core resources assigned to the virtual machine.

Using Libcloud to Start a VM

You can re-purpose the above code sample to start a virtual machine by doing:

node = [n for n in nodes if 'yourservername' in n.name][0]

driver.ex_start(node=node)

Restarting a Virtual Instance

You can issue a reset command in the DCD or through the API. This is the equivalent of a hard reboot of the server. If you wish to initiate a graceful reboot of the server you would need to use the OS provided method for rebooting the machine.

In both Windows and Linux this could be as simple as issuing the following commands:

Windows

shutdown -r

Linux

reboot

It is recommended that you do not make it a common practice to forcibly reboot your servers. You should be using the OS supported method to ensure integrity of your data.

Using Libcloud to Restart a VM

You can re-purpose the above code sample to reset a virtual machine by doing:

node = [n for n in nodes if 'yourservername' in n.name][0]

driver.reboot_node(node=node)

 
  • I’m trying to use the ProfitBricks’ Libcloud library to issue various commands to my server. Namely, I want to reboot it automatically via script, but would also like to know how to stop and start it, too.

Log In, Add a Comment