# limitations under the License. import os import xmlrpc.client import lib.logger as logger import lib.utilities as util import lib.genesis as gen OS_IMAGES_DIR = gen.get_container_os_images_path() + '/' OS_CONFIG_DIR = OS_IMAGES_DIR + 'config/' APACHE2_HTML_DIR = '/var/www/html/' KICKSTARTS_DIR = '/var/lib/cobbler/kickstarts/' SNIPPETS_DIR = '/var/lib/cobbler/snippets/' COBBLER_USER = gen.get_cobbler_user() COBBLER_PASS = gen.get_cobbler_pass() def extract_iso_images(path, html_dir): """Extract ISO images into webserver directory Args: path (str): Directory path containing ISOs or path to single ISO file html_dir (str): Path to root http directory Returns: list: List of tuples ('str: Extracted image directory name', 'str: Relative path to kernel', 'str: Relative path to initrd')
def cobbler_add_systems(cfg_file=None): LOG = logger.getlogger() cobbler_user = gen.get_cobbler_user() cobbler_pass = gen.get_cobbler_pass() cobbler_server = xmlrpclib.Server("http://127.0.0.1/cobbler_api") token = cobbler_server.login(cobbler_user, cobbler_pass) inv = Inventory(cfg_file=cfg_file) for index, hostname in enumerate(inv.yield_nodes_hostname()): ipv4_ipmi = inv.get_nodes_ipmi_ipaddr(0, index) userid_ipmi = inv.get_nodes_ipmi_userid(index) password_ipmi = inv.get_nodes_ipmi_password(index) ipv4_pxe = inv.get_nodes_pxe_ipaddr(0, index) mac_pxe = inv.get_nodes_pxe_mac(0, index) cobbler_profile = gen.check_os_profile( re.sub("[.]iso", "", inv.get_nodes_os_profile(index))) raid1_enabled = False new_system_create = cobbler_server.new_system(token) cobbler_server.modify_system(new_system_create, "name", hostname, token) cobbler_server.modify_system(new_system_create, "hostname", hostname, token) cobbler_server.modify_system(new_system_create, "power_address", ipv4_ipmi, token) cobbler_server.modify_system(new_system_create, "power_user", userid_ipmi, token) cobbler_server.modify_system(new_system_create, "power_pass", password_ipmi, token) cobbler_server.modify_system(new_system_create, "power_type", "ipmilan", token) cobbler_server.modify_system(new_system_create, "profile", cobbler_profile, token) cobbler_server.modify_system( new_system_create, 'modify_interface', { "macaddress-eth0": mac_pxe, "ipaddress-eth0": ipv4_pxe, "dnsname-eth0": hostname }, token) ks_meta = "" disks = inv.get_nodes_os_install_device(index) if disks is not None: if isinstance(disks, basestring): ks_meta += 'install_disk=%s ' % disks elif isinstance(disks, list) and len(disks) == 2: ks_meta += ('install_disk=%s install_disk_2=%s ' % (disks[0], disks[1])) raid1_enabled = True else: LOG.error('%s: Invalid install_device value: %s ' 'Must be string or two item list.' % (hostname, disks)) if raid1_enabled: ks_meta += 'raid1_enabled=true ' users = inv.get_nodes_os_users(index) if users is not None: for user in users: if 'name' in user and user['name'] != 'root': ks_meta += 'default_user=%s ' % user['name'] LOG.debug("%s: Using \'%s\' as default user" % (hostname, user['name'])) if 'password' in user: ks_meta += ('passwd=%s passwdcrypted=true ' % user['password']) break else: LOG.debug("%s: No default user found" % hostname) else: LOG.debug("%s: No users defined" % hostname) if ks_meta != "": cobbler_server.modify_system(new_system_create, "ks_meta", ks_meta, token) kernel_options = inv.get_nodes_os_kernel_options(index) if kernel_options is not None: cobbler_server.modify_system(new_system_create, "kernel_options", kernel_options, token) comment = "" cobbler_server.modify_system(new_system_create, "comment", comment, token) cobbler_server.save_system(new_system_create, token) LOG.info("Cobbler Add System: name=%s, profile=%s" % (hostname, cobbler_profile)) cobbler_server.sync(token) LOG.info("Running Cobbler sync")