libcloud.compute.drivers.kubevirt module

kubevirt driver with support for nodes (vms)

class libcloud.compute.drivers.kubevirt.KubeVirtNodeDriver(key=None, secret=None, secure=False, host='localhost', port=4243, key_file=None, cert_file=None, ca_cert=None, ex_token_bearer_auth=False)[source]

Bases: KubernetesDriverMixin, NodeDriver

Parameters:
  • key (str) – API key or username to be used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • key_file (str) – Path to the key file used to authenticate (when using key file auth).

  • cert_file (str) – Path to the cert file used to authenticate (when using key file auth).

  • ex_token_bearer_auth (bool) – True to use token bearer auth.

Returns:

None

NODE_STATE_MAP: Dict[str, NodeState] = {'pending': NodeState.PENDING, 'running': NodeState.RUNNING, 'stopped': NodeState.STOPPED}
attach_volume(node, volume, device='disk', ex_bus='virtio', ex_name=None)[source]

params: bus, name , device (disk or lun)

connectionCls

alias of KubernetesBasicAuthConnection

create_node(name, image, location=None, ex_memory=128, ex_cpu=1, ex_disks=None, ex_network=None, ex_termination_grace_period=0, ports=None)[source]

Creating a VM with a containerDisk. :param name: A name to give the VM. The VM will be identified by

this name and atm it cannot be changed after it is set.

Parameters:
  • image (str) – Either a libcloud NodeImage or a string. In both cases it must point to a Docker image with an embedded disk. May be a URI like kubevirt/cirros-registry-disk-demo, kubevirt will automatically pull it from https://hub.docker.com/u/URI. For more info visit: https://kubevirt.io/user-guide/docs/latest/creating-virtual-machines/disks-and-volumes.html#containerdisk

  • location (str) – The namespace where the VM will live. (default is ‘default’)

  • ex_memory (int) – The RAM in MB to be allocated to the VM

  • ex_cpu (int) – The amount of cpu to be allocated in miliCPUs ie: 400 will mean 0.4 of a core, 1000 will mean 1 core and 3000 will mean 3 cores.

  • ex_disks (list of dict. For each dict the types for its keys are: -bus: str -device: str -disk_type: str -name: str -claim_name: str (for creating a claim:) -size: int -storage_class_name: str -volume_mode: str -access_mode: str) –

    A list containing disk dictionaries.

    Each dictionaries should have the following optional keys: -bus: can be “virtio”, “sata”, or “scsi” -device: can be “lun” or “disk” The following are required keys: -disk_type: atm only “persistentVolumeClaim”

    is supported

    -name: The name of the disk configuration -claim_name: the name of the

    Persistent Volume Claim

    If you wish a new Persistent Volume Claim can be created by providing the following: required: -size: the desired size (implied in GB) -storage_class_name: the name of the storage class to # NOQA

    be used for the creation of the Persistent Volume Claim. Make sure it allows for dymamic provisioning.

    optional:

    -access_mode: default is ReadWriteOnce -volume_mode: default is Filesystem,

    it can also be Block

  • ex_network (iterable (tuple or list) [network_type, interface, name] network_type: str | only “pod” is accepted atm interface: str | “masquerade” or “bridge” name: str) – Only the pod type is supported, and in the configuration masquerade or bridge are the accepted values. The parameter must be a tuple or list with (network_type, interface, name)

  • ports (dict with keys ‘ports_tcp`: list of int ‘ports_udp`: list of int) – A dictionary with keys: ‘ports_tcp’ and ‘ports_udp’ ‘ports_tcp’ value is a list of ints that indicate the ports to be exposed with TCP protocol, and ‘ports_udp’ is a list of ints that indicate the ports to be exposed with UDP protocol.

create_volume(size, name, location=None, ex_storage_class_name='', ex_volume_mode='Filesystem', ex_access_mode='ReadWriteOnce', ex_dynamic=True, ex_reclaim_policy='Recycle', ex_volume_type=None, ex_volume_params=None)[source]
Parameters:
  • size (int) – The size in Gigabytes

  • volume_type (str) –

    This is the type of volume to be created that is dependent on the underlying cloud where Kubernetes is deployed. K8s is supporting the following types: -gcePersistentDisk -awsElasticBlockStore -azureFile -azureDisk -csi -fc (Fibre Channel) -flexVolume -flocker -nfs -iSCSI -rbd (Ceph Block Device) -cephFS -cinder (OpenStack block storage) -glusterfs -vsphereVolume -quobyte Volumes -hostPath (Single node testing only – local storage is not supported in any way and WILL NOT WORK in a multi-node cluster) # NOQA -portworx Volumes -scaleIO Volumes -storageOS This parameter is a dict in the form {type: {key1:value1, key2:value2,…}}, where type is one of the above and key1, key2… are type specific keys and their corresponding values. eg: {nsf: {server: “172.0.0.0”, path: “/tmp”}}

    {awsElasticBlockStore: {fsType: ‘ext4’, volumeID: “1234”}}

  • volume_params – A dict with the key:value that the volume_type needs. This parameter is a dict in the form {key1:value1, key2:value2,…}, where type is one of the above and key1, key2… are type specific keys and their corresponding values. eg: for nsf volume_type {server: “172.0.0.0”, path: “/tmp”} for awsElasticBlockStore volume_type {fsType: ‘ext4’, volumeID: “1234”}

destroy_node(node)[source]

Terminating a VMI and deleting the VM resource backing it

destroy_volume(volume)[source]

Destroys a storage volume.

Parameters:

volume (StorageVolume) – Volume to be destroyed

Return type:

bool

detach_volume(volume, ex_node)[source]

Detaches a volume from a node but the node must be given since a PVC can have more than one VMI’s pointing to it

ex_create_service(node, ports, service_type='NodePort', cluster_ip=None, load_balancer_ip=None, override_existing_ports=False)[source]

Each node has a single service of one type on which the exposed ports are described. If a service exists then the port declared will be exposed alongside the existing ones, set override_existing_ports=True to delete existing exposed ports and expose just the ones in the port variable.

param node: the libcloud node for which the ports will be exposed type node: libcloud Node class

param ports: a list of dictionaries with keys –> values:

‘port’ –> port to be exposed on the service ‘target_port’ –> port on the pod/node, optional

if empty then it gets the same value as ‘port’ value

‘protocol’ —> either ‘UDP’ or ‘TCP’, defaults to TCP ‘name’ –> A name for the service If ports is an empty list and a service exists of this type then the service will be deleted.

type ports: list of dict where each dict has keys –> values:

‘port’ –> int ‘target_port’ –> int ‘protocol’ –> str ‘name’ –> str

param service_type: Valid types are ClusterIP, NodePort, LoadBalancer type service_type: str

param cluster_ip: This can be set with an IP string value if you want

manually set the service’s internal IP. If the value is not correct the method will fail, this value can’t be updated.

type cluster_ip: str

param override_existing_ports: Set to True if you want to delete the

existing ports exposed by the service and keep just the ones declared in the present ports argument. By default it is false and if the service already exists the ports will be added to the existing ones.

type override_existing_ports: boolean

ex_delete_service(namespace, service_name)[source]
ex_list_persistent_volume_claims(namespace='default')[source]
ex_list_services(namespace='default', node_name=None, service_name=None)[source]

If node_name is given then the services returned will be those that concern the node

ex_list_storage_classes()[source]
get_node(id=None, name=None)[source]

get a vm by name or id

list_images(location=None)[source]

If location (namespace) is provided only the images in that location will be provided. Otherwise all of them.

list_locations()[source]

By locations here it is meant namespaces.

list_nodes(location=None)[source]

List all nodes.

Returns:

list of node objects

Return type:

list of Node

list_sizes(location=None)[source]

List sizes on a provider

Parameters:

location (NodeLocation) – The location at which to list sizes

Returns:

list of node size objects

Return type:

list of NodeSize

list_volumes()[source]

Location is a namespace of the cluster.

name: str = 'kubevirt'
reboot_node(node)[source]

Rebooting a node.

start_node(node)[source]

Start a node.

Parameters:

node (Node) – The node to be started

Returns:

True if the start was successful, otherwise False

Return type:

bool

stop_node(node)[source]

Stop a node

Parameters:

node (Node) – The node to be stopped.

Returns:

True if the stop was successful, otherwise False

Return type:

bool

type: Provider | str = 'kubevirt'
website: str = 'https://www.kubevirt.io'