def _create_node_disks()

in libcloud/compute/drivers/kubevirt.py [0:0]


    def _create_node_disks(self, vm, ex_disks, image, namespace, location):
        """
        A part of create_node that deals with the disks (and volumes) of the VM.
        It will fill the vm with disk information.
        OS image is added to the disks as well.

        :param vm: The VM template to be filled.
        :type vm: ``dict``
        :param ex_disks: The disk configuration of the VM.
                            See also the ex_disks parameter in create_node.
        :type ex_disks: ``list``
        :param image: The image to be used as the OS disk.
                        See also the image parameter in create_node.
        :param namespace: The namespace where the VM will live.
                            See also the location parameter in create_node.
        :type namespace: ``str``
        :param location: The location where the VM will live.
                            See also the location parameter in create_node.
        :type location: ``str``

        :return: None
        """
        # ex_disks -> disks and volumes

        ex_disks = ex_disks or []

        for i, disk in enumerate(ex_disks):
            disk_type = disk.get("disk_type")
            bus = disk.get("bus", "virtio")
            disk_name = disk.get("name", "disk{}".format(i))
            device = disk.get("device", "disk")

            if disk_type not in DISK_TYPES:
                raise ValueError("The possible values for this " "parameter are: ", DISK_TYPES)

            # depending on disk_type, in the future,
            # when more will be supported,
            # additional elif should be added

            if disk_type == "containerDisk":
                try:
                    image = disk["volume_spec"]["image"]
                except KeyError:
                    raise KeyError("A container disk needs a " "containerized image")

                volumes_dict = {"containerDisk": {"image": image}, "name": disk_name}
            elif disk_type == "persistentVolumeClaim":
                if "volume_spec" not in disk:
                    raise KeyError("You must provide a volume_spec dictionary")

                if "claim_name" not in disk["volume_spec"]:
                    msg = (
                        "You must provide either a claim_name of an "
                        "existing claim or if you want one to be "
                        "created you must additionally provide size "
                        "and the storage_class_name of the "
                        "cluster, which allows dynamic provisioning, "
                        "so a Persistent Volume Claim can be created. "
                        "In the latter case please provide the desired "
                        "size as well."
                    )
                    raise KeyError(msg)

                claim_name = disk["volume_spec"]["claim_name"]

                if claim_name not in self.ex_list_persistent_volume_claims(namespace=namespace):
                    if (
                        "size" not in disk["volume_spec"]
                        or "storage_class_name" not in disk["volume_spec"]
                    ):
                        msg = (
                            "disk['volume_spec']['size'] and "
                            "disk['volume_spec']['storage_class_name'] "
                            "are both required to create "
                            "a new claim."
                        )
                        raise KeyError(msg)
                    size = disk["volume_spec"]["size"]
                    storage_class = disk["volume_spec"]["storage_class_name"]
                    volume_mode = disk["volume_spec"].get("volume_mode", "Filesystem")
                    access_mode = disk["volume_spec"].get("access_mode", "ReadWriteOnce")
                    self.create_volume(
                        size=size,
                        name=claim_name,
                        location=location,
                        ex_storage_class_name=storage_class,
                        ex_volume_mode=volume_mode,
                        ex_access_mode=access_mode,
                    )

                volumes_dict = {
                    "persistentVolumeClaim": {"claimName": claim_name},
                    "name": disk_name,
                }
            else:
                warnings.warn(
                    "The disk type {} is not tested. Use at your own risk.".format(disk_type)
                )
                volumes_dict = {disk_type: disk.get("volume_spec", {}), "name": disk_name}

            disk_dict = {device: {"bus": bus}, "name": disk_name}
            vm["spec"]["template"]["spec"]["domain"]["devices"]["disks"].append(disk_dict)
            vm["spec"]["template"]["spec"]["volumes"].append(volumes_dict)
        # end of for disk in ex_disks

        # image -> containerDisk -> add as the first disk
        self._create_node_image(vm, image)