ganeti

Ganeti module.

exception spicerack.ganeti.GanetiError[source]

Bases: SpicerackError

Raised on errors from Ganeti operations.

class spicerack.ganeti.Ganeti(username: str, password: str, timeout: int, remote: Remote, netbox: Netbox)[source]

Bases: object

Class which wraps all Ganeti clusters operations.

Initialize the instance.

Parameters:
  • username (str) -- The RAPI username to use.

  • password (str) -- The RAPI password to use.

  • timeout (int) -- The timeout in seconds for each request to the API.

  • remote (spicerack.remote.Remote) -- the remote instance to connect to Ganeti hosts.

  • netbox (spicerack.netbox.Netbox) -- the Netbox instance to gather data from the source of truth.

get_cluster(name: str) GanetiCluster[source]

Get a GanetiCluster instance for the given cluster name.

Parameters:

name (str) -- the name of the Ganeti cluster, equivalent to the cluster group in Netbox.

Returns:

the cluster instance

Return type:

spicerack.ganeti.GanetiCluster

Raises:

spicerack.ganeti.GanetiError -- if unable to find the cluster endpoint.

get_group(name: str, *, cluster: str) GanetiGroup[source]

Get a GanetiGroup instance for the given group name.

Parameters:
  • name (str) -- the name of the Ganeti group, equivalent to the cluster in Netbox.

  • cluster (str) -- the name of the Ganeti cluster where to look for the group, equivalent to the cluster group in Netbox.

Returns:

the group instance.

Return type:

spicerack.ganeti.GanetiGroup

Raises:

spicerack.ganeti.GanetiError -- if unable to find the group.

instance(instance: str, *, cluster: str = '') GntInstance[source]

Return an instance of GntInstance to perform RW operation on the given Ganeti VM instance.

Parameters:
  • instance (str) -- the FQDN of the Ganeti VM instance to act upon.

  • cluster (str, optional) -- the name of the Ganeti cluster to which the instance belongs, or will belong in case of a new instance to be created. If not provided it will be auto-detected for existing instances.

Returns:

ready to perform RW actions.

Return type:

spicerack.ganeti.GntInstance

rapi(cluster: str) GanetiRAPI[source]

Return a RAPI object for a particular cluster.

Parameters:

cluster (str) -- the name of the cluster group in Netbox for this Ganeti cluster.

Returns:

the RAPI interface object

Return type:

spicerack.ganeti.GanetiRAPI

Raises:

spicerack.ganeti.GanetiError -- if unable to find the cluster endpoint.

class spicerack.ganeti.GanetiCluster(name: str, fqdn: str, rapi: str)[source]

Bases: object

Represents a Ganeti cluster with all the related attributes.

Parameters:
  • name (str) -- the Ganeti cluster short name, equivalent to the Netbox cluster group name.

  • fqdn (str) -- the FQDN of the Ganeti cluster VIP.

  • rapi (str) -- the Ganeti RAPI endpoint URL to connect to.

class spicerack.ganeti.GanetiGroup(name: str, site: str, cluster: GanetiCluster)[source]

Bases: object

Represents a Ganeti group with all the related attributes.

Parameters:
  • name (str) -- the Ganeti group name, equivalent to the Netbox cluster name.

  • site (str) -- the Datacenter of the Ganeti group short name, equivalent of the Netbox site slug.

  • cluster (spicerack.ganeti.GanetiCluster) -- the Ganeti cluster the group belongs to.

class spicerack.ganeti.GanetiRAPI(cluster_url: str, username: str, password: str, timeout: int, ca_path: str)[source]

Bases: object

Class which wraps the read-only Ganeti RAPI.

Initialize the instance.

Parameters:
  • cluster_url (str) -- the URL of the RAPI endpoint.

  • username (str) -- the RAPI user name

  • password (str) -- the RAPI user's password

  • timeout (int) -- the timeout in seconds for each request

  • ca_path (str) -- the path to the signing certificate authority

fetch_instance(fqdn: str) Dict[source]

Return full information about an instance.

Parameters:

fqdn -- the FQDN of the instance in question

Returns:

host information

Return type:

dict

Raises:

spicerack.ganeti.GanetiError -- API errors

fetch_instance_mac(fqdn: str) str[source]

Convenience method to return the 0th adapter's MAC address for an instance.

Note that we don't allow the creation of instances with more than one MAC address at this time.

Parameters:

fqdn -- the FQDN of the instance in question

Returns:

MAC address

Return type:

str

Raises:

GanetiError -- API errors

property info: Dict

Return complete cluster information.

Returns:

Cluster information dictionary

Return type:

dict

Raises:

spicerack.ganeti.GanetiError -- API errors

property master: str | None

Return the internal name for the current ganeti master node.

Returns:

The hostname of the master node (or None if the data is missing).

Return type:

str

Raises:

spicerack.ganeti.GanetiError -- API errors

class spicerack.ganeti.GntInstance(master: RemoteHosts, cluster: str, instance: str)[source]

Bases: object

Class that wraps gnt-instance command execution on a Ganeti cluster master host.

Initialize the instance.

Parameters:
  • master (spicerack.remote.RemoteHosts) -- the Ganeti cluster master remote instance.

  • cluster (str) -- the Ganeti cluster name.

  • instance (str) -- the FQDN of the Ganeti VM instance to act upon.

add(*, group: str, vcpus: int, memory: int, disk: int, link: str) None[source]

Create the VM for the instance in the Ganeti cluster with the specified characteristic.

Parameters:
  • group (str) -- the Ganeti group that matches the Datacenter physical row or rack where to allocate the instance.

  • vcpus (int) -- the number of virtual CPUs to assign to the instance.

  • memory (int) -- the amount of RAM to assign to the instance in gigabytes.

  • disk (int) -- the amount of disk to assign to the instance in gigabytes.

  • link (str) -- the type of network link to use, one of spicerack.ganeti.INSTANCE_LINKS.

Raises:

spicerack.ganeti.GanetiError -- on parameter validation error.

Note

This action requires few minutes, inform the user about the waiting time when using this method.

remove(*, shutdown_timeout: int = 2) None[source]

Shutdown and remove the VM instance from the Ganeti cluster, including its disks.

Parameters:

shutdown_timeout (int) -- time in minutes to wait for a clean shutdown before pulling the plug.

Note

This action requires few minutes, inform the user about the waiting time when using this method.

set_boot_media(boot: str) None[source]

Set the boot media of the Ganeti VM to the given media.

Parameters:

boot (str) -- the boot media to use. Use disk to boot from disk and network to boot from PXE.

shutdown(*, timeout: int = 2) None[source]

Shutdown the Ganeti VM instance.

Parameters:

timeout (int) -- time in minutes to wait for a clean shutdown before pulling the plug.

startup() None[source]

Start the Ganeti VM instance.

property cluster: str

Getter for the Ganeti cluster property.

Returns:

the Ganeti cluster name the instance belongs to.

Return type:

str

the list of possible instance link types.

Type:

tuple

spicerack.ganeti.RAPI_URL_FORMAT: str = 'https://{cluster}:5080'

the template string to construct the Ganeti RAPI URL.

Type:

str