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: spicerack.remote.Remote, netbox: spicerack.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) spicerack.ganeti.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.

Raises:

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

Return type:

spicerack.ganeti.GanetiCluster

get_group(name: str, *, cluster: str) spicerack.ganeti.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.

Raises:

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

Return type:

spicerack.ganeti.GanetiGroup

instance(instance: str, *, cluster: str = '') spicerack.ganeti.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, default: '') -- 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.

Return type:

spicerack.ganeti.GntInstance

rapi(cluster: str) spicerack.ganeti.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.

Raises:

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

Return type:

spicerack.ganeti.GanetiRAPI

class spicerack.ganeti.GanetiCluster(name: str, fqdn: str, rapi: str, routed: bool) None[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.

  • routed (bool) -- Whether the cluster's network is in routed mode or switched mode.

class spicerack.ganeti.GanetiGroup(name: str, site: str, cluster: spicerack.ganeti.GanetiCluster) None[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 (str) -- the FQDN of the instance in question.

Raises:

spicerack.ganeti.GanetiError -- on API errors.

Return type:

dict

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 (str) -- the FQDN of the instance in question.

Raises:

spicerack.ganeti.GanetiError -- on API errors.

Return type:

str

groups(bulk: bool = False) dict[source]

Get a list of Cluster groups.

Parameters:

bulk (bool, default: False) -- if true set bulk=1 to return detailed information. see https://docs.ganeti.org/docs/ganeti/2.9/html/rapi.html#bulk

Return type:

dict

nodes(bulk: bool = False) dict[source]

Get a list of Cluster nodes.

Parameters:

bulk (bool, default: False) -- if true set bulk=1 to return detailed information. see https://docs.ganeti.org/docs/ganeti/2.9/html/rapi.html#bulk

Return type:

dict

property info: dict

Return the complete cluster information.

Raises:

spicerack.ganeti.GanetiError -- on API errors.

property master: str | None

Return the internal name for the current ganeti master node or none if the data is missing.

Raises:

spicerack.ganeti.GanetiError -- on API errors.

class spicerack.ganeti.GntInstance(master: spicerack.remote.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 | float, disk: int, net: str | ipaddress.IPv4Address, ip6: ipaddress.IPv6Address) None[source]

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

Parameters:
Raises:

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

Return type:

None

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, default: 2) -- time in minutes to wait for a clean shutdown before pulling the plug.

Return type:

None

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.

Return type:

None

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

Shutdown the Ganeti VM instance.

Parameters:

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

Return type:

None

startup() None[source]

Start the Ganeti VM instance.

Return type:

None

property cluster: str

Getter for the Ganeti cluster name the instance belongs to.

The list of possible instance link types.

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

The template string to construct the Ganeti RAPI URL.