summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2006-10-13 12:30:43 -0400
committerJim Meyering <jim@meyering.net>2006-10-13 12:30:43 -0400
commitcd9b923b946c45c5a732fa6e053a59c0f9fcb40e (patch)
tree6bc459a428a53416c4aa55a68553dd3c9c5e48aa
parent6e84895b828b4fa5e3c45464dd08949fa382dfa5 (diff)
downloadthird_party-cobbler-cd9b923b946c45c5a732fa6e053a59c0f9fcb40e.tar.gz
third_party-cobbler-cd9b923b946c45c5a732fa6e053a59c0f9fcb40e.tar.xz
third_party-cobbler-cd9b923b946c45c5a732fa6e053a59c0f9fcb40e.zip
Import feature added (usable for things like /mnt/redhat)
-rw-r--r--cobbler.pod25
-rw-r--r--cobbler/action_import.py89
-rw-r--r--cobbler/action_sync.py14
-rw-r--r--cobbler/api.py6
-rwxr-xr-xcobbler/cobbler.py9
-rw-r--r--cobbler/item.py4
-rw-r--r--cobbler/item_distro.py28
-rw-r--r--cobbler/item_system.py20
8 files changed, 109 insertions, 86 deletions
diff --git a/cobbler.pod b/cobbler.pod
index f4d3b2f..6d2ab85 100644
--- a/cobbler.pod
+++ b/cobbler.pod
@@ -30,7 +30,7 @@ For PXE, if DHCP is run from the cobbler server, the dhcp configuration file sho
=head2 ADDING A DISTRIBUTION
-B<cobbler distro add --name=<string> --kernel=<path> --initrd=<path> [--kopts=<string>] [--ksmeta=<string>]>
+B<cobbler distro add --name=<string> --kernel=<path> --initrd=<path> [--kopts=<string>] [--ksmeta=<string>] [--arch=<x86|x86_64|ia64>]
=over
@@ -54,6 +54,14 @@ an absolute filesystem path to a initrd image
Example: --ksmeta="foo=bar baz=3 asdf"
+=item arch
+
+(optional) sets the architecture for the PXE bootloader
+
+x86 and x86_64 are interchangable, both use syslinux.
+
+ia64 uses the IA64 build of elilo.
+
=item ksmeta
(optional)
@@ -105,7 +113,7 @@ the name of a previously defined cobbler distribution
=head2 ADDING A SYSTEM
-B<cobbler system add --name=<ip|mac|hostname> --profile=<string> [--kopts=<string>] [--pxe-arch=<standard|ia64>] [--pxe-address=<string>] [--ksmeta=<string>]
+B<cobbler system add --name=<ip|mac|hostname> --profile=<string> [--kopts=<string>] [--pxe-address=<string>] [--ksmeta=<string>]
=over
=over
@@ -120,17 +128,6 @@ The system name must be either a currently-resolvable hostname, an IP address, o
When defining Xen systems, using a MAC address causes the Xen MAC address to be used for creation,
so that is the preferred usage.
-=item pxe-arch
-
-Advanced feature. Applies only if manage-dhcp is set to 1 in /var/lib/cobbler/settings and only for PXE provisioning.
-
-Setting the pxe-arch to "ia64" will use elilo.efi as the boot loader instead of
-"pxelinux.0". The default, "standard", uses "pxelinux.0", which does not work for IA-64 (Itanium) systems.
-
-When using this setting, be sure the "--name" given to the "system add" command must be a MAC address or no per-system record in dhcpd.conf can be generated..
-
-Example: --pxe-arch=ia64
-
=item pxe-address
Advanced feature.
@@ -234,7 +231,7 @@ If this flag is set, it enables two things:
Per-system records in DHCP will only be written if the cobbler system name is a MAC address, so it's recommended that those be used if manage_dhcp is turned on.
-Itanium systems also need to be specified by the MAC address, and in addition need to be given the "--pxe-arch=ia64" parameter.
+Itanium systems names also need to be specified by the MAC address, and their distribution needs to be created with the "--arch=ia64" parameter.
The dhcpd.conf file will be updated each time "cobbler sync" is run.
diff --git a/cobbler/action_import.py b/cobbler/action_import.py
index 456f358..e50ffd8 100644
--- a/cobbler/action_import.py
+++ b/cobbler/action_import.py
@@ -19,12 +19,15 @@ import os
import os.path
import traceback
+import api
+
class Importer:
- def __init__(self,config,path):
+ def __init__(self,config,path,mirror):
# FIXME: consider a basename for the import
self.config = config
self.path = path
+ self.mirror = mirror
if path is None:
raise cexceptions.CobblerException("import_failed","no path specified")
self.distros = config.distros()
@@ -32,70 +35,76 @@ class Importer:
self.systems = config.systems()
def run(self):
+ if self.path is None and self.mirror is None:
+ raise cexceptions.CobblerException("import_failed","no path specified")
if not os.path.isdir(self.path):
raise cexceptions.CobblerException("import_failed","bad path")
- arg = None
- os.path.walk(self.path, self.walker, arg)
- return True
+ if self.path is not None:
+ arg = None
+ os.path.walk(self.path, self.walker, arg)
+ return True
+ return False
def walker(self,arg,dirname,fnames):
# FIXME: requires getting an arch out of the path
# FIXME: requires making sure the path contains "pxe" somewhere
print "dirname: %s" % dirname
- if self.is_leaf(dirname,fnames):
- print "is_leaf"
- initrd = None
- kernel = None
- for x in fnames:
- if x.startswith("initrd"):
- initrd = os.path.join(dirname,x)
- if x.startswith("vmlinuz"):
- kernel = os.path.join(dirname,x)
- if initrd is not None and kernel is not None:
- print "kernel: %s" % kernel
- print "initrd: %s" % initrd
- self.consider(dirname,kernel,initrd)
-
- def consider(self,dirname,kernel,initrd):
- if not self.is_pxe_dir(dirname):
+ initrd = None
+ kernel = None
+ if not self.is_pxe_or_xen_dir(dirname):
return
+ for x in fnames:
+ if x.startswith("initrd"):
+ initrd = os.path.join(dirname,x)
+ if x.startswith("vmlinuz"):
+ kernel = os.path.join(dirname,x)
+ if initrd is not None and kernel is not None:
+ self.add_entry(dirname,kernel,initrd)
+
+ def add_entry(self,dirname,kernel,initrd):
pxe_arch = self.get_pxe_arch(dirname)
name = self.get_proposed_name(dirname)
if self.distros.find(name) is not None:
print "already registered: %s" % name
else:
- print "adding: %s" % name
- # FIXME
+ distro = self.config.new_distro()
+ distro.set_name(name)
+ distro.set_kernel(kernel)
+ distro.set_initrd(initrd)
+ distro.set_arch(pxe_arch)
+ self.distros.add(distro)
+ print "*** DISTRO ADDED ***"
if self.profiles.find(name) is not None:
print "already registered: %s" % name
else:
- print "adding: %s" % name
- # FIXME
-
+ profile = self.config.new_profile()
+ profile.set_name(name)
+ profile.set_distro(name)
+ self.profiles.add(profile)
+ print "*** PROFILE ADDED ***"
+
def get_proposed_name(self,dirname):
- # FIXME
+ # FIXME: how can this name be nicer?
str = "_".join(dirname.split("/"))
if str.startswith("_"):
- return str[1:-1]
+ return str[1:]
return str
def get_pxe_arch(self,dirname):
- # FIXME
+ tokens = os.path.split(dirname)
+ tokens = [x.lower() for x in tokens]
+ for t in tokens:
+ if t == "i386" or t == "386" or t == "x86":
+ return "x86"
+ if t == "x86_64":
+ return "x86_64"
+ if t == "ia64":
+ return "ia64"
return "x86"
- def is_pxe_dir(self,dirname):
+ def is_pxe_or_xen_dir(self,dirname):
tokens = os.path.split(dirname)
for x in tokens:
- if x.lower() == "pxe" or x.lower() == "pxeboot":
+ if x.lower() == "pxe" or x.lower() == "pxeboot" or x.lower() == "xen":
return True
- print "not a pxe directory: %s" % dirname
return False
-
- def is_leaf(self,dirname,fnames):
- for x in fnames:
- if os.path.isdir(x):
- print "not a leaf directory: %s" % dirname
- return False
- return True
-
-
diff --git a/cobbler/action_sync.py b/cobbler/action_sync.py
index 11d60d8..4fda5b3 100644
--- a/cobbler/action_sync.py
+++ b/cobbler/action_sync.py
@@ -126,7 +126,9 @@ class BootSync:
systxt = ""
counter = counter + 1
systxt = "\nhost label%d {\n" % counter
- if system.pxe_arch == "ia64":
+ profile = self.profiles.find(system.profile)
+ distro = self.distros.find(profile.distro)
+ if distro.arch == "ia64":
# can't use pxelinux.0 anymore
systxt = systxt + " filename \"/%s\";\n" % elilo
systxt = systxt + " hardware ethernet %s;\n" % system.name
@@ -388,10 +390,12 @@ class BootSync:
f1 = self.get_pxe_filename(system.name)
# tftp only
- if system.pxe_arch == "standard":
+
+
+ if distro.arch in [ "x86", "x86_64", "standard"]:
# pxelinux wants a file named $name under pxelinux.cfg
f2 = os.path.join(self.settings.tftpboot, "pxelinux.cfg", f1)
- if system.pxe_arch == "ia64":
+ if distro.arch == "ia64":
# elilo expects files to be named "$name.conf" in the root
# and can not do files based on the MAC address
if system.pxe_address == "" or system.pxe_address is None or not utils.is_ip(system.pxe_address):
@@ -403,9 +407,9 @@ class BootSync:
f3 = os.path.join(self.settings.webdir, "systems", f1)
- if system.pxe_arch == "standard":
+ if distro.arch in [ "x86", "x86_64", "standard"]:
self.write_pxe_file(f2,system,profile,distro,False)
- if system.pxe_arch == "ia64":
+ if distro.arch == "ia64":
self.write_pxe_file(f2,system,profile,distro,True)
self.write_system_file(f3,system)
diff --git a/cobbler/api.py b/cobbler/api.py
index f4387eb..18ed9e0 100644
--- a/cobbler/api.py
+++ b/cobbler/api.py
@@ -116,11 +116,13 @@ class BootAPI:
enchant = action_enchant.Enchant(self._config,sysname,password)
return enchant.run()
- def import_tree(self,tree_path):
+ def import_tree(self,tree_path,mirror_url):
"""
Automatically import a directory tree full of distribution files.
+ Imports either a tree (path) or mirror (ftp/http).
+ Mirror support really doesn't exist yet... TBA.
"""
- importer = action_import.Importer(self._config, tree_path)
+ importer = action_import.Importer(self._config, tree_path, mirror_url)
return importer.run()
def serialize(self):
diff --git a/cobbler/cobbler.py b/cobbler/cobbler.py
index c991ece..e7a512c 100755
--- a/cobbler/cobbler.py
+++ b/cobbler/cobbler.py
@@ -151,15 +151,19 @@ class BootCLI:
'cobbler
"""
self.temp_path = None
+ self.temp_mirror = None
+ def set_mirror(a):
+ self.temp_mirror = a
def set_path(a):
if os.path.isdir(a):
self.temp_path = a
return True
return False
def go_import():
- return self.api.import_tree(self.temp_path)
+ return self.api.import_tree(self.temp_path,self.temp_mirror)
commands = {
- '--path' : lambda(a): set_path(a)
+ '--path' : lambda(a): set_path(a),
+ '--mirror' : lambda(a): set_mirror(a)
}
on_ok = lambda: go_import()
return self.apply_args(args,commands,on_ok)
@@ -213,6 +217,7 @@ class BootCLI:
'--kernel' : lambda(a) : distro.set_kernel(a),
'--initrd' : lambda(a) : distro.set_initrd(a),
'--kopts' : lambda(a) : distro.set_kernel_options(a),
+ '--arch' : lambda(a) : distro.set_arch(a),
'--ksmeta' : lambda(a) : distro.set_ksmeta(a)
}
on_ok = lambda: self.api.distros().add(distro)
diff --git a/cobbler/item.py b/cobbler/item.py
index 0bec45f..6dad205 100644
--- a/cobbler/item.py
+++ b/cobbler/item.py
@@ -48,7 +48,7 @@ class Item(serializable.Serializable):
return False
return True
- def load_item(self,datastruct,key):
+ def load_item(self,datastruct,key,default=''):
"""
Used in subclass from_datastruct functions to load items from
a hash. Intented to ease backwards compatibility of config
@@ -56,7 +56,7 @@ class Item(serializable.Serializable):
"""
if datastruct.has_key(key):
return datastruct[key]
- return ''
+ return default
def to_datastruct(self):
"""
diff --git a/cobbler/item_distro.py b/cobbler/item_distro.py
index 0d0f26d..9af47f4 100644
--- a/cobbler/item_distro.py
+++ b/cobbler/item_distro.py
@@ -38,6 +38,7 @@ class Distro(item.Item):
self.initrd = None
self.kernel_options = ""
self.ks_meta = ""
+ self.arch = "x86"
def from_datastruct(self,seed_data):
"""
@@ -48,6 +49,7 @@ class Distro(item.Item):
self.initrd = self.load_item(seed_data,'initrd')
self.kernel_options = self.load_item(seed_data,'kernel_options')
self.ks_meta = self.load_item(seed_data,'ks_meta')
+ self.arch = self.load_item(seed_data,'arch',"x86")
return self
def set_kernel(self,kernel):
@@ -73,6 +75,28 @@ class Distro(item.Item):
return True
raise cexceptions.CobblerException("no_initrd")
+ def set_arch(self,arch):
+ """
+ The field is mainly relevant to PXE provisioning.
+
+ Should someone have Itanium machines on a network, having
+ syslinux (pxelinux.0) be the only option in the config file causes
+ problems.
+
+ Using an alternative distro type allows for dhcpd.conf templating
+ to "do the right thing" with those systems -- this also relates to
+ bootloader configuration files which have different syntax for different
+ distro types (because of the bootloaders).
+
+ This field is named "arch" because mainly on Linux, we only care about
+ the architecture, though if (in the future) new provisioning types
+ are added, an arch value might be something like "bsd_x86".
+ """
+ if arch in [ "standard", "ia64", "x86", "x86_64" ]:
+ self.arch = arch
+ return True
+ raise cexceptions.CobblerException("exc_pxe_arch")
+
def is_valid(self):
"""
A distro requires that the kernel and initrd be set. All
@@ -91,7 +115,8 @@ class Distro(item.Item):
'kernel': self.kernel,
'initrd' : self.initrd,
'kernel_options' : self.kernel_options,
- 'ks_meta' : self.ks_meta
+ 'ks_meta' : self.ks_meta,
+ 'arch' : self.arch
}
def printable(self, id):
@@ -112,6 +137,7 @@ class Distro(item.Item):
buf = buf + "kernel : %s\n" % kstr
buf = buf + "initrd : %s\n" % istr
buf = buf + "kernel options : %s\n" % self.kernel_options
+ buf = buf + "architecture : %s\n" % self.arch
buf = buf + "ks metadata : %s\n" % self.ks_meta
return buf
diff --git a/cobbler/item_system.py b/cobbler/item_system.py
index 2568959..74ea7c7 100644
--- a/cobbler/item_system.py
+++ b/cobbler/item_system.py
@@ -27,7 +27,6 @@ class System(item.Item):
self.profile = None # a name, not a reference
self.kernel_options = ""
self.ks_meta = ""
- self.pxe_arch = "standard"
self.pxe_address = ""
def from_datastruct(self,seed_data):
@@ -35,7 +34,6 @@ class System(item.Item):
self.profile = self.load_item(seed_data,'profile')
self.kernel_options = self.load_item(seed_data,'kernel_options')
self.ks_meta = self.load_item(seed_data,'ks_meta')
- self.pxe_arch = self.load_item(seed_data,'pxe_arch')
self.pxe_address = self.load_item(seed_data,'pxe_address')
return self
@@ -75,22 +73,6 @@ class System(item.Item):
return True
raise cexceptions.CobblerException("exc_profile")
- def set_pxe_arch(self,new_arch):
- """
- The PXE architecture field is naturally relevant to PXE only.
- Should someone have Itanium machines on a network, having
- pxelinux.0 be the only option in the config file causes
- problems. Using an alternative architecture here allows
- for dhcpd.conf templating to "do the right thing" with
- those systems. If manage_dhcp is off in /var/lib/cobbler/settings
- this parameter is meaningless. It only has value when
- generating a dhcp file.
- """
- if new_arch == "standard" or new_arch == "ia64":
- self.pxe_arch = new_arch
- return True
- raise cexceptions.CobblerException("exc_pxe_arch")
-
def is_valid(self):
"""
A system is valid when it contains a valid name and a profile.
@@ -107,7 +89,6 @@ class System(item.Item):
'profile' : self.profile,
'kernel_options' : self.kernel_options,
'ks_meta' : self.ks_meta,
- 'pxe_arch' : self.pxe_arch,
'pxe_address' : self.pxe_address
}
@@ -116,7 +97,6 @@ class System(item.Item):
buf = buf + "profile : %s\n" % self.profile
buf = buf + "kernel options : %s\n" % self.kernel_options
buf = buf + "ks metadata : %s\n" % self.ks_meta
- buf = buf + "pxe arch : %s\n" % self.pxe_arch
buf = buf + "pxe address : %s\n" % self.pxe_address
return buf