Source code for cobbler.items.image

import string

from cobbler import autoinstall_manager
from cobbler.items import item
from cobbler import utils
from cobbler.cexceptions import CX
from cobbler.utils import _


# this data structure is described in item.py
FIELDS = [
    # non-editable in UI (internal)
    ['ctime', 0, 0, "", False, "", 0, "float"],
    ['depth', 0, 0, "", False, "", 0, "int"],
    ['mtime', 0, 0, "", False, "", 0, "float"],
    ['parent', '', 0, "", False, "", 0, "str"],
    ['uid', "", 0, "", False, "", 0, "str"],

    # editable in UI
    ['arch', 'x86_64', 0, "Architecture", True, "", utils.get_valid_archs(), "str"],
    ['autoinstall', '', 0, "Automatic installation file", True, "Path to autoinst/answer file template", 0, "str"],
    ['breed', 'redhat', 0, "Breed", True, "", utils.get_valid_breeds(), "str"],
    ['comment', '', 0, "Comment", True, "Free form text description", 0, "str"],
    ['file', '', 0, "File", True, "Path to local file or nfs://user@host:path", 0, "str"],
    ['image_type', "iso", 0, "Image Type", True, "", ["iso", "direct", "memdisk", "virt-image"], "str"],
    ['name', '', 0, "Name", True, "", 0, "str"],
    ['network_count', 1, 0, "Virt NICs", True, "", 0, "int"],
    ['os_version', '', 0, "OS Version", True, "ex: rhel4", utils.get_valid_os_versions(), "str"],
    ['owners', "SETTINGS:default_ownership", 0, "Owners", True, "Owners list for authz_ownership (space delimited)", [], "list"],
    ['virt_auto_boot', "SETTINGS:virt_auto_boot", 0, "Virt Auto Boot", True, "Auto boot this VM?", 0, "bool"],
    ['virt_bridge', "SETTINGS:default_virt_bridge", 0, "Virt Bridge", True, "", 0, "str"],
    ['virt_cpus', 1, 0, "Virt CPUs", True, "", 0, "int"],
    ["virt_disk_driver", "SETTINGS:default_virt_disk_driver", 0, "Virt Disk Driver Type", True, "The on-disk format for the virtualization disk", "raw", "str"],
    ['virt_file_size', "SETTINGS:default_virt_file_size", 0, "Virt File Size (GB)", True, "", 0, "float"],
    ['virt_path', '', 0, "Virt Path", True, "Ex: /directory or VolGroup00", 0, "str"],
    ['virt_ram', "SETTINGS:default_virt_ram", 0, "Virt RAM (MB)", True, "", 0, "int"],
    ['virt_type', "SETTINGS:default_virt_type", 0, "Virt Type", True, "", ["xenpv", "xenfv", "qemu", "kvm", "vmware"], "str"],
]


[docs]class Image(item.Item): """ A Cobbler Image. Tracks a virtual or physical image, as opposed to a answer file (autoinst) led installation. """ TYPE_NAME = _("image") COLLECTION_TYPE = "image" # # override some base class methods first (item.Item) #
[docs] def make_clone(self): _dict = self.to_dict() cloned = Image(self.collection_mgr) cloned.from_dict(_dict) return cloned
[docs] def get_fields(self): return FIELDS
[docs] def get_parent(self): """ Images have no parent object. """ return None
# # specific methods for item.Image #
[docs] def set_arch(self, arch): """ The field is mainly relevant to PXE provisioning. see comments for set_arch in item_distro.py, this works the same. """ return utils.set_arch(self, arch)
[docs] def set_autoinstall(self, autoinstall): """ Set the automatic installation file path, this must be a local file. It may not make sense for images to have automatic installation templates. It really doesn't. However if the image type is 'iso' koan can create a virtual floppy and shove an answer file on it, to script an installation. This may not be a automatic installation template per se, it might be a Windows answer file (SIF) etc. @param str local automatic installation template file path """ autoinstall_mgr = autoinstall_manager.AutoInstallationManager(self.collection_mgr) self.autoinstall = autoinstall_mgr.validate_autoinstall_template_file_path(autoinstall)
[docs] def set_file(self, filename): """ Stores the image location. This should be accessible on all nodes that need to access it. Format: can be one of the following: * username:password@hostname:/path/to/the/filename.ext * username@hostname:/path/to/the/filename.ext * hostname:/path/to/the/filename.ext * /path/to/the/filename.ext """ uri = "" auth = hostname = path = "" # validate file location format if filename.find("://") != -1: raise CX("Invalid image file path location, it should not contain a protocol") uri = filename if filename.find("@") != -1: auth, filename = filename.split("@") # extract the hostname # 1. if we have a colon, then everything before it is a hostname # 2. if we don't have a colon, there is no hostname if filename.find(":") != -1: hostname, filename = filename.split(":") elif filename[0] != '/': raise CX(_("invalid file: %s" % filename)) # raise an exception if we don't have a valid path if len(filename) > 0 and filename[0] != '/': raise CX(_("file contains an invalid path: %s" % filename)) if filename.find("/") != -1: path, filename = filename.rsplit("/", 1) if len(filename) == 0: raise CX(_("missing filename")) if len(auth) > 0 and len(hostname) == 0: raise CX(_("a hostname must be specified with authentication details")) self.file = uri
[docs] def set_os_version(self, os_version): return utils.set_os_version(self, os_version)
[docs] def set_breed(self, breed): return utils.set_breed(self, breed)
[docs] def set_image_type(self, image_type): """ Indicates what type of image this is. direct = something like "memdisk", physical only iso = a bootable ISO that pxe's or can be used for virt installs, virtual only virt-clone = a cloned virtual disk (FIXME: not yet supported), virtual only memdisk = hdd image (physical only) """ if image_type not in self.get_valid_image_types(): raise CX(_("image type must be on of the following: %s") % string.join(self.get_valid_image_types(), ", ")) self.image_type = image_type
[docs] def set_virt_cpus(self, num): return utils.set_virt_cpus(self, num)
[docs] def set_network_count(self, num): if num is None or num == "": num = 1 try: self.network_count = int(num) except: raise CX("invalid network count (%s)" % num)
[docs] def set_virt_auto_boot(self, num): return utils.set_virt_auto_boot(self, num)
[docs] def set_virt_file_size(self, num): return utils.set_virt_file_size(self, num)
[docs] def set_virt_disk_driver(self, driver): return utils.set_virt_disk_driver(self, driver)
[docs] def set_virt_ram(self, num): return utils.set_virt_ram(self, num)
[docs] def set_virt_type(self, vtype): return utils.set_virt_type(self, vtype)
[docs] def set_virt_bridge(self, vbridge): return utils.set_virt_bridge(self, vbridge)
[docs] def set_virt_path(self, path): return utils.set_virt_path(self, path)
[docs] def get_valid_image_types(self): return ["direct", "iso", "memdisk", "virt-clone"]
# EOF