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:
- get_group(name: str, *, cluster: str) spicerack.ganeti.GanetiGroup [source]¶
Get a GanetiGroup instance for the given group name.
- Parameters:
- Raises:
spicerack.ganeti.GanetiError -- if unable to find the group.
- Return type:
- 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:
- Return type:
- 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:
- 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.
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
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 (
typing.Union
[int
,float
]) -- the amount of RAM to assign to the instance in gigabytes.disk (
int
) -- the amount of disk to assign to the instance in gigabytes.net (
typing.Union
[str
,ipaddress.IPv4Address
]) -- either the IP or the type of network link to use (fromspicerack.ganeti.INSTANCE_LINKS
).ip6 (
ipaddress.IPv6Address
) -- the IPv6 assigned to the VM.
- Raises:
spicerack.ganeti.GanetiError -- on parameter validation error.
- Return type:
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:
Note
This action requires few minutes, inform the user about the waiting time when using this method.