def run_iso(self): t = Template(self.args.template, user=self.args.username) if self.args.use_livecd_creator: iso_creator = 'livecd-creator' install_package = 'livecd-tools' else: iso_creator = 'livemedia-creator' install_package = 'lorax' # check for required software try: subprocess.run([iso_creator, "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) except FileNotFoundError: logging.error( 'You need to install the "{0}" package to create ISOs using {1}.' .format(install_package, iso_creator)) return 1 try: t = self.cs.template_get(t) except ServiceException as e: logging.exception(e) return 1 # calculate name and title for use if not specified arch = os.uname()[4] if arch in ['i386', 'i686']: arch_pretty = '32 bit' arch_pretty_long = '32 bit (%s)' % (arch) elif arch in ['x86_64']: arch_pretty = '64 bit' arch_pretty_long = '64 bit (%s)' % (arch) # we'll use the release version in our names if self.args.releasever is None: if t.version is None or t.version is '': # default to release ver of installed system at / self.args.releasever = dnf.rpm.detect_releasever('/') else: self.args.releasever = t.version name = "{0}".format(t.name) name_long = "{0}-{1}-{2}".format(t.name, self.args.releasever, arch) name_pretty = "{0}-{1}-{2}".format(t.name, self.args.releasever, arch_pretty) title = "{0}".format(t.title) title_long = "{0} - {1} - {2}".format(t.title, self.args.releasever, arch_pretty) title_pretty_long = "{0} - {1} - {2}".format(t.title, self.args.releasever, arch_pretty_long) # build missing strings if self.args.build_dir is None: self.args.build_dir = "/var/tmp/canvas/{0}-{1}".format( name_long.lower(), t.uuid) tmp_dir = os.path.join(self.args.build_dir, 'tmp') if self.args.result_dir is None: self.args.result_dir = os.path.join(self.args.build_dir, 'iso') if self.args.cache_dir is None: self.args.cache_dir = os.path.join(self.args.build_dir, 'cache') if self.args.iso_name is None: self.args.iso_name = "{0}.iso".format(name_long.lower()) if self.args.project is None: self.args.project = title_pretty_long if self.args.volid is None: self.args.volid = name_long.lower() if self.args.title is None: self.args.title = title if self.args.logfile is None: self.args.logfile = os.path.join( self.args.build_dir, "{0}.log".format(name_long.lower())) # build kickstart file ks_file = "canvas-{0}.ks".format(t.uuid) ks_path = os.path.join(self.args.build_dir, "ks", ks_file) try: # ensure our result_dir exists if not os.path.exists(os.path.dirname(ks_path)): os.makedirs(os.path.dirname(ks_path)) with open(ks_path, 'w') as f: f.write(t.to_kickstart(resolved=True)) except IOError as e: logging.error( 'You need root privileges to build iso at this location.') return 1 env = os.environ.copy() logging.info('Build directory: {0}'.format(self.args.build_dir)) logging.info('Cache directory: {0}'.format(self.args.cache_dir)) logging.info('Result directory: {0}'.format(self.args.result_dir)) logging.info('Log file: {0}'.format(self.args.logfile)) logging.info('ISO name: {0}'.format(self.args.iso_name)) logging.info('Project: {0}'.format(self.args.project)) logging.info('Title: {0}'.format(self.args.title)) logging.info('Volumne ID: {0}'.format(self.args.volid)) working_dir = None # livecd-creator if self.args.use_livecd_creator: logging.info('Building via livecd-creator ...') working_dir = self.args.result_dir args = [ iso_creator, '--verbose', '--config', ks_path, '--fslabel', name_long.lower(), '--title', self.args.title, '--releasever', self.args.releasever, '--product', self.args.project, '--cache', self.args.cache_dir, '--tmpdir', tmp_dir, '--logfile', self.args.logfile ] env["setarch"] = arch # livemedia-creator else: logging.info('Building via livemedia-creator ...') args = [ iso_creator, '--no-virt', '--make-iso', '--iso-only', '--macboot', '--ks', ks_path, '--resultdir', self.args.result_dir, '--project', self.args.project, '--volid', self.args.volid, '--iso-name', self.args.iso_name, '--releasever', self.args.releasever, '--title', self.args.title, '--logfile', self.args.logfile ] logging.debug('Build args:', args) # ensure working directory exists if set if working_dir is not None: os.makedirs(working_dir, exist_ok=True) subprocess.run(args, cwd=working_dir, env=env) return 0
def run_dump(self): t = Template(self.args.template, user=self.args.username) try: t = self.cs.template_get( t, resolve_includes=not self.args.no_resolve_includes) except ServiceException as e: logging.exception(e) return 1 if self.args.kickstart: print(t.to_kickstart(resolved=not self.args.no_resolve_includes)) return 0 elif self.args.yaml: print( yaml.dump( t.to_object(resolved=not self.args.no_resolve_includes), indent=4)) return 0 elif self.args.json: print( json.dumps( t.to_object(resolved=not self.args.no_resolve_includes), indent=4, sort_keys=True)) return 0 # pretty general information print('TEMPLATE: {0} ({1})\n'.format(t.name, t.user)) if t.description is not None and len(t.description): print('Description:\n{0}\n'.format(t.description)) # pretty print includes if len(t.includes): l = TextTable(header=['INCLUDE']) for i in t.includes: l.add_row([i]) print(l) print() # pretty print packages repos = list(t.repos_all) repos.sort(key=lambda x: x.stub) if len(repos): l = TextTable(header=["REPO", "NAME", "ENABLED", "TEMPLATE"]) for r in repos: cost = r.cost if cost is None: cost = '-' priority = r.priority if priority is None: priority = '-' enabled = 'N' if r.enabled: enabled = 'Y' template = r.template if template == t.unv: template = '' #l.add_row([r.stub, r.name, priority, cost, enabled]) l.add_row([r.stub, r.name, enabled, template]) print(l) print() # pretty print packages packages = list(t.packages_all) packages.sort(key=lambda x: x.name) if len(packages): l = TextTable(header=["PACKAGE", "ACTION", "TEMPLATE"]) for p in packages: if p.included: p.action = '+' elif p.excluded: p.action = '-' elif p.ignored: p.action = '!' else: p.action = '?' # no template specified indicates it's part of this template if p.template == t.unv: p.template = '' l.add_row([p.name, p.action, p.template]) print(l) print() return 0
def run_iso(self): t = Template(self.args.template, user=self.args.username) try: t = self.cs.template_get(t) except ServiceException as e: logging.exception(e) return 1 # calculate name and title for use if not specified arch = os.uname()[4] if arch in ['i386', 'i686']: arch_pretty = '32 bit' arch_pretty_long = '32 bit (%s)' % (arch) elif arch in ['x86_64']: arch_pretty = '64 bit' arch_pretty_long = '64 bit (%s)' % (arch) # we'll use the release version in our names if self.args.releasever is None: if t.version is None or t.version is '': # default to release ver of installed system at / self.args.releasever = dnf.rpm.detect_releasever('/') else: self.args.releasever = t.version name = "{0}".format(t.name) name_long = "{0}-{1}-{2}".format(t.name, self.args.releasever, arch) name_pretty = "{0}-{1}-{2}".format(t.name, self.args.releasever, arch_pretty) title = "{0}".format(t.title) title_long = "{0} - {1} - {2}".format(t.title, self.args.releasever, arch_pretty) title_pretty_long = "{0} - {1} - {2}".format(t.title, self.args.releasever, arch_pretty_long) # build missing strings if self.args.resultdir is None: self.args.resultdir = "/var/tmp/canvas/isos/{0}-{1}".format(name_long.lower(), ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(8))) if self.args.iso_name is None: self.args.iso_name = "{0}.iso".format(name_long.lower()) if self.args.project is None: self.args.project = title if self.args.volid is None: self.args.volid = name_long.lower() if self.args.title is None: self.args.title = title_pretty_long if self.args.logfile is None: self.args.logfile = "/var/tmp/canvas/{0}.log".format(name_long.lower()) # build kickstart file ks_file = "canvas-{0}.ks".format(t.uuid) ks_path = os.path.join("/var/tmp/canvas/ks", ks_file) try: # ensure our resultdir exists if not os.path.exists(os.path.dirname(ks_path)): os.makedirs(os.path.dirname(ks_path)) with open(ks_path, 'w') as f: f.write(t.to_kickstart(resolved=True)) except IOError as e: logging.error('You need root privileges to build iso at this location.') return 1 env = os.environ.copy() # livecd-creator if self.args.use_livecd_creator: args = [ 'livecd-creator', '--verbose', '--config', ks_path, '--fslabel', name_long.lower(), '--title', self.args.title, '--releasever', self.args.releasever, '--product', self.args.project, '--cache', self.args.resultdir, '--logfile', self.args.logfile ] env["setarch"] = arch # livemedia-creator else: args = [ 'livemedia-creator', '--no-virt', '--make-iso', '--iso-only', '--macboot', '--ks', ks_path, '--resultdir', self.args.resultdir, '--project', self.args.project, '--volid', self.args.volid, '--iso-name', self.args.iso_name, '--releasever', self.args.releasever, '--title', self.args.title, '--logfile', self.args.logfile ] subprocess.run(args, env=env) return 0
def run_dump(self): t = Template(self.args.template, user=self.args.username) try: t = self.cs.template_get(t, resolve_includes=not self.args.no_resolve_includes) except ServiceException as e: logging.exception(e) return 1 if self.args.kickstart: print(t.to_kickstart(resolved=not self.args.no_resolve_includes)) return 0 elif self.args.yaml: print(yaml.dump(t.to_object(resolved=not self.args.no_resolve_includes), indent=4)) return 0 elif self.args.json: print(json.dumps(t.to_object(resolved=not self.args.no_resolve_includes), indent=4, sort_keys=True)) return 0 # pretty general information print('TEMPLATE: {0} ({1})\n'.format(t.name, t.user)) if t.description is not None and len(t.description): print('Description:\n{0}\n'.format(t.description)) # pretty print includes if len(t.includes): l = TextTable(header=['INCLUDE']) for i in t.includes: l.add_row([i]) print(l) print() # pretty print packages repos = list(t.repos_all) repos.sort(key=lambda x: x.stub) if len(repos): l = TextTable(header=["REPO", "NAME", "ENABLED"]) for r in repos: cost = r.cost if cost is None: cost = '-' priority = r.priority if priority is None: priority = '-' enabled = 'N' if r.enabled: enabled = 'Y' #l.add_row([r.stub, r.name, priority, cost, enabled]) l.add_row([r.stub, r.name, enabled]) print(l) print() # pretty print packages packages = list(t.packages_all) packages.sort(key=lambda x: x.name) if len(packages): l = TextTable(header=["PACKAGE", "ACTION"]) for p in packages: if p.included: p.action = '+' else: p.action = '-' l.add_row([p.name, p.action]) print(l) print() return 0
def run_dump(self): t = Template(self.args.template, user=self.args.username) try: t = self.cs.template_get( t, resolve_includes=not self.args.no_resolve_includes) except ServiceException as e: print(e) return 1 if self.args.kickstart: print(t.to_kickstart(resolved=not self.args.no_resolve_includes)) return 0 elif self.args.yaml: print( yaml.dump( t.to_object(resolved=not self.args.no_resolve_includes), indent=4)) return 0 elif self.args.json: print( json.dumps( t.to_object(resolved=not self.args.no_resolve_includes), indent=4, sort_keys=True)) return 0 # pretty general information print('Name: {0} ({1})'.format(t.name, t.user)) if t.description is not None and len(t.description): print('Description:\n{0}\n'.format(t.description)) # pretty print includes if len(t.includes): print('Includes:') for i in t.includes: print(' - {0}'.format(i)) print() # pretty print packages repos = list(t.repos_all) repos.sort(key=lambda x: x.stub) if len(repos): l = prettytable.PrettyTable( ['repo', 'name', 'priority', 'cost', 'enabled']) l.min_table_width = 120 l.hrules = prettytable.HEADER l.vrules = prettytable.NONE l.align = 'l' l.padding_witdth = 1 for r in repos: if r.cost is None: r.cost = '-' if r.priority is None: r.priority = '-' if r.enabled: r.enabled = 'Y' else: r.enabled = 'N' l.add_row([r.stub, r.name, r.priority, r.cost, r.enabled]) print(l) print() # pretty print packages packages = list(t.packages_all) packages.sort(key=lambda x: x.name) if len(packages): l = prettytable.PrettyTable( ['package', 'epoch', 'version', 'release', 'arch', 'action']) l.min_table_width = 120 l.hrules = prettytable.HEADER l.vrules = prettytable.NONE l.align = 'l' l.padding_witdth = 1 for p in packages: if p.epoch is None: p.epoch = '-' if p.version is None: p.version = '-' if p.release is None: p.release = '-' if p.arch is None: p.arch = '-' if p.included: p.action = '+' else: p.action = '-' l.add_row( [p.name, p.epoch, p.version, p.release, p.arch, p.action]) print(l) print() return 0
def run_dump(self): t = Template(self.args.template, user=self.args.username) try: t = self.cs.template_get(t) except ServiceException as e: print(e) return 1 if self.args.kickstart: print(t.to_kickstart()) return 0 elif self.args.yaml: print(yaml.dump(t.to_object(), indent=4)) return 0 elif self.args.json: print(json.dumps(t.to_object(), indent=4)) return 0 # pretty general information print('Name: {0} ({1})'.format(t.name, t.user)) if t.description is not None and len(t.description): print('Description:\n{0}\n'.format(t.description)) # pretty print includes if len(t.includes): print('Includes:') for i in t.includes: print(' - {0}'.format(i)) print() # pretty print packages repos = list(t.repos_all) repos.sort(key=lambda x: x.stub) if len(repos): l = prettytable.PrettyTable(['repo', 'name', 'priority', 'cost', 'enabled']) l.min_table_width = 120 l.hrules = prettytable.HEADER l.vrules = prettytable.NONE l.align = 'l' l.padding_witdth = 1 for r in repos: if r.cost is None: r.cost = '-' if r.priority is None: r.priority = '-' if r.enabled: r.enabled = 'Y' else: r.enabled = 'N' l.add_row([r.stub, r.name, r.priority, r.cost, r.enabled]) print(l) print() # pretty print packages packages = list(t.packages_all) packages.sort(key=lambda x: x.name) if len(packages): l = prettytable.PrettyTable(['package', 'epoch', 'version', 'release', 'arch', 'action']) l.min_table_width = 120 l.hrules = prettytable.HEADER l.vrules = prettytable.NONE l.align = 'l' l.padding_witdth = 1 for p in packages: if p.epoch is None: p.epoch = '-' if p.version is None: p.version = '-' if p.release is None: p.release = '-' if p.arch is None: p.arch = '-' if p.included(): p.action = '+' else: p.action = '-' l.add_row([p.name, p.epoch, p.version, p.release, p.arch, p.action]) print(l) print() return 0