def buildimagetype(self, imagetype, baseid, imgopts={}): """ This method compliments the builder method by taking its uuid and outputputting various image formats """ print "Working on a {0} for {1}".format(imagetype, baseid) bd = BuildDispatcher() imagebuilder = bd.builder_for_target_image(imagetype, image_id=baseid, template=None, parameters=imgopts) target_image = imagebuilder.target_image thread = imagebuilder.target_thread thread.join() if target_image.status != "COMPLETE": fail_msg("Failed image status: " + target_image.status) print target_image.identifier # Now doing the OVA print "Creating OVA for {0}".format(imagetype) bdi = BuildDispatcher() ovabuilder = bdi.builder_for_target_image("ova", image_id=target_image.identifier, template=None, parameters=imgopts) target_ova = ovabuilder.target_image ovathread = ovabuilder.target_thread ovathread.join() if target_ova.status != "COMPLETE": fail_msg("Failed image status: " + target_ova.status) return target_ova
def buildimagetype(self, imagetype, baseid, imgopts={}): """ This method compliments the builder method by taking its uuid and outputputting various image formats """ # This dict maps the imagetype to an imageformat imageformats = { 'kvm': 'kvm', 'rhevm': 'rhevm', 'vsphere': 'vsphere', 'vagrant-libvirt': 'rhevm', 'vagrant-virtualbox': 'vsphere' } log("Working on a {0} for {1}".format(imagetype, baseid)) vagrant = True if imagetype in [ 'vagrant-virtualbox', 'vagrant-libvirt' ] else False if vagrant: # Absent this directive, Vagrant will attempt to sync to /vagrant # which is not writeable in a normal rpm-ostree host imgopts['vagrant_sync_directory'] = '/home/vagrant/sync' bd = BuildDispatcher() imagebuilder = bd.builder_for_target_image(imageformats[imagetype], image_id=baseid, template=None, parameters=imgopts) target_image = imagebuilder.target_image thread = imagebuilder.target_thread thread.join() if target_image.status != "COMPLETE": fail_msg("Failed image status: " + target_image.status) # Now doing the OVA log("Creating OVA for {0}".format(imagetype)) bdi = BuildDispatcher() if imagetype == 'vagrant-virtualbox': imgopts['vsphere_ova_format'] = 'vagrant-virtualbox' if imagetype == 'vagrant-libvirt': imgopts['rhevm_ova_format'] = 'vagrant-libvirt' ovabuilder = bdi.builder_for_target_image( "ova", image_id=target_image.identifier, template=None, parameters=imgopts) target_ova = ovabuilder.target_image ovathread = ovabuilder.target_thread ovathread.join() if target_ova.status != "COMPLETE": fail_msg("Failed image status: " + target_ova.status) return target_ova
def buildimagetype(self, imagetype, baseid, imgopts={}): """ This method compliments the builder method by taking its uuid and outputputting various image formats """ # This dict maps the imagetype to an imageformat imageformats = { "kvm": "kvm", "rhevm": "rhevm", "vsphere": "vsphere", "vagrant-libvirt": "rhevm", "vagrant-virtualbox": "vsphere", } log("Working on a {0} for {1}".format(imagetype, baseid)) vagrant = True if imagetype in ["vagrant-virtualbox", "vagrant-libvirt"] else False if vagrant: # Absent this directive, Vagrant will attempt to sync to /vagrant # which is not writeable in a normal rpm-ostree host imgopts["vagrant_sync_directory"] = "/home/vagrant/sync" bd = BuildDispatcher() imagebuilder = bd.builder_for_target_image( imageformats[imagetype], image_id=baseid, template=None, parameters=imgopts ) target_image = imagebuilder.target_image thread = imagebuilder.target_thread thread.join() if target_image.status != "COMPLETE": fail_msg("Failed image status: " + target_image.status) # Now doing the OVA log("Creating OVA for {0}".format(imagetype)) bdi = BuildDispatcher() if imagetype == "vagrant-virtualbox": imgopts["vsphere_ova_format"] = "vagrant-virtualbox" if imagetype == "vagrant-libvirt": imgopts["rhevm_ova_format"] = "vagrant-libvirt" ovabuilder = bdi.builder_for_target_image( "ova", image_id=target_image.identifier, template=None, parameters=imgopts ) target_ova = ovabuilder.target_image ovathread = ovabuilder.target_thread ovathread.join() if target_ova.status != "COMPLETE": fail_msg("Failed image status: " + target_ova.status) return target_ova
def buildimagetype(self, imagetype, baseid, imgopts={}): """ This method compliments the builder method by taking its uuid and outputputting various image formats """ # This dict maps the imagetype to an imageformat imageformats = {'kvm':'kvm', 'rhevm': 'rhevm', 'vsphere':'vsphere', 'vagrant-libvirt':'rhevm', 'vagrant-virtualbox': 'vsphere' } print "Working on a {0} for {1}".format(imagetype, baseid) vagrant = True if imagetype in ['vagrant-virtualbox', 'vagrant-libvirt'] else False bd = BuildDispatcher() imagebuilder = bd.builder_for_target_image(imageformats[imagetype], image_id=baseid, template=None, parameters=imgopts) target_image = imagebuilder.target_image thread = imagebuilder.target_thread thread.join() if target_image.status != "COMPLETE": fail_msg("Failed image status: " + target_image.status) print target_image.identifier # Now doing the OVA print "Creating OVA for {0}".format(imagetype) bdi = BuildDispatcher() if imagetype == 'vagrant-virtualbox' : imgopts['vsphere_ova_format'] = 'vagrant-virtualbox' if imagetype == 'vagrant-libvirt': imgopts['rhevm_ova_format'] = 'vagrant-libvirt' ovabuilder = bdi.builder_for_target_image("ova", image_id=target_image.identifier, template=None, parameters=imgopts) target_ova = ovabuilder.target_image ovathread = ovabuilder.target_thread ovathread.join() if target_ova.status != "COMPLETE": fail_msg("Failed image status: " + target_ova.status) return target_ova
def buildimagetype(self, imagetype, baseid, imgopts={}): """ This method compliments the builder method by taking its uuid and outputputting various image formats """ # This dict maps the imagetype to an imageformat imageformats = {'kvm':'kvm', 'rhevm': 'rhevm', 'vsphere':'vsphere', 'vagrant-libvirt':'rhevm', 'vagrant-virtualbox': 'vsphere' } log("Working on a {0} for {1}".format(imagetype, baseid)) vagrant = True if imagetype in ['vagrant-virtualbox', 'vagrant-libvirt'] else False bd = BuildDispatcher() imagebuilder = bd.builder_for_target_image(imageformats[imagetype], image_id=baseid, template=None, parameters=imgopts) target_image = imagebuilder.target_image thread = imagebuilder.target_thread thread.join() if target_image.status != "COMPLETE": fail_msg("Failed image status: " + target_image.status) # Now doing the OVA log("Creating OVA for {0}".format(imagetype)) bdi = BuildDispatcher() if imagetype == 'vagrant-virtualbox' : imgopts['vsphere_ova_format'] = 'vagrant-virtualbox' if imagetype == 'vagrant-libvirt': imgopts['rhevm_ova_format'] = 'vagrant-libvirt' ovabuilder = bdi.builder_for_target_image("ova", image_id=target_image.identifier, template=None, parameters=imgopts) target_ova = ovabuilder.target_image ovathread = ovabuilder.target_thread ovathread.join() if target_ova.status != "COMPLETE": fail_msg("Failed image status: " + target_ova.status) return target_ova
def create(self, installer_outputdir, args, cmd, profile, post=None): imgfunc = AbstractImageFactoryTask(args, cmd, profile) repos = self.getrepos(self.jsonfilename) util_xml = self.template_xml( repos, os.path.join(self.pkgdatadir, 'lorax-indirection-repo.tmpl')) lorax_repos = [] if self.lorax_additional_repos: if getattr(self, 'yum_baseurl') not in self.lorax_additional_repos: self.lorax_additional_repos += ", {0}".format( getattr(self, 'yum_baseurl')) for repourl in self.lorax_additional_repos.split(','): lorax_repos.extend(['-s', repourl.strip()]) else: lorax_repos.extend(['-s', getattr(self, 'yum_baseurl')]) port_file_path = self.workdir + '/repo-port' if not self.ostree_repo_is_remote: # Start trivial-httpd trivhttp = TrivialHTTP() trivhttp.start(self.ostree_repo) httpd_port = str(trivhttp.http_port) print "trivial httpd port=%s, pid=%s" % (httpd_port, trivhttp.http_pid) else: httpd_port = str(self.httpd_port) substitutions = { 'OSTREE_PORT': httpd_port, 'OSTREE_REF': self.ref, 'OSTREE_OSNAME': self.os_name, 'LORAX_REPOS': " ".join(lorax_repos), 'OS_PRETTY': self.os_pretty_name, 'OS_VER': self.release } if '@OSTREE_HOSTIP@' in util_xml: if not self.ostree_repo_is_remote: host_ip = getDefaultIP() else: host_ip = self.httpd_host substitutions['OSTREE_HOSTIP'] = host_ip if '@OSTREE_PATH' in util_xml: substitutions['OSTREE_PATH'] = self.httpd_path print type(util_xml) for subname, subval in substitutions.iteritems(): util_xml = util_xml.replace('@%s@' % (subname, ), subval) # Dump util_xml to workdir for logging self.dumpTempMeta(os.path.join(self.workdir, "lorax.xml"), util_xml) global verbosemode imgfacbuild = ImgFacBuilder(verbosemode=verbosemode) imgfacbuild.verbosemode = verbosemode imgfunc.checkoz("qcow2") util_ks = self.createUtilKS(self.tdl) # Building of utility image parameters = { "install_script": util_ks, "generate_icicle": False, "oz_overrides": json.dumps(imgfunc.ozoverrides) } if self.util_uuid is None: print "Starting Utility image build" util_image = imgfacbuild.build(template=open(self.util_tdl).read(), parameters=parameters) print "Created Utility Image: {0}".format(util_image.data) else: pim = PersistentImageManager.default_manager() util_image = pim.image_with_id(self.util_uuid) print "Re-using Utility Image: {0}".format(util_image.identifier) # Now lorax bd = BuildDispatcher() lorax_parameters = { "results_location": "/lorout/output.tar", "utility_image": util_image.identifier, "utility_customizations": util_xml, "oz_overrides": json.dumps(imgfunc.ozoverrides) } print "Building the lorax image" loraxiso_builder = bd.builder_for_target_image( "indirection", image_id=util_image.identifier, template=None, parameters=lorax_parameters) loraxiso_image = loraxiso_builder.target_image thread = loraxiso_builder.target_thread thread.join() # Extract the tarball of built images print "Extracting images to {0}/images".format(installer_outputdir) t = tarfile.open(loraxiso_image.data) t.extractall(path=installer_outputdir) if not self.ostree_repo_is_remote: trivhttp.stop()
def create(self, outputdir, post=None): imgfunc = ImageFunctions() repos = self.getrepos(self.jsonfilename) util_xml = self.template_xml(repos, os.path.join(self.pkgdatadir, 'lorax-indirection-repo.tmpl')) lorax_repos = [] if self.lorax_additional_repos: if getattr(self, 'yum_baseurl') not in self.lorax_additional_repos: self.lorax_additional_repos += ", {0}".format(getattr(self, 'yum_baseurl')) for repourl in self.lorax_additional_repos.split(','): lorax_repos.extend(['-s', repourl.strip()]) else: lorax_repos.extend(['-s', getattr(self, 'yum_baseurl')]) port_file_path = self.workdir + '/repo-port' # Start trivial-httpd trivhttp = TrivialHTTP() trivhttp.start(self.ostree_repo) httpd_port = str(trivhttp.http_port) print "trivial httpd port=%s, pid=%s" % (httpd_port, trivhttp.http_pid) substitutions = {'OSTREE_PORT': httpd_port, 'OSTREE_REF': self.ref, 'OSTREE_OSNAME': self.os_name, 'LORAX_REPOS': " ".join(lorax_repos), 'OS_PRETTY': self.os_pretty_name, 'OS_VER': self.release } if '@OSTREE_HOSTIP@' in util_xml: host_ip = getDefaultIP() substitutions['OSTREE_HOSTIP'] = host_ip print type(util_xml) for subname, subval in substitutions.iteritems(): util_xml = util_xml.replace('@%s@' % (subname, ), subval) # Dump util_xml to workdir for logging self.dumpTempMeta(os.path.join(self.workdir, "lorax.xml"), util_xml) global verbosemode imgfacbuild = ImgFacBuilder(verbosemode=verbosemode) imgfacbuild.verbosemode = verbosemode imgfunc.checkoz() util_ks = self.createUtilKS(self.tdl) # Building of utility image parameters = {"install_script": util_ks, "generate_icicle": False, "oz_overrides": json.dumps(imgfunc.ozoverrides) } print "Starting build" if self.util_uuid is None: util_image = imgfacbuild.build(template=open(self.util_tdl).read(), parameters=parameters) print "Created Utility Image: {0}".format(util_image.data) else: pim = PersistentImageManager.default_manager() util_image = pim.image_with_id(self.util_uuid) print "Re-using Utility Image: {0}".format(util_image.identifier) # Now lorax bd = BuildDispatcher() lorax_parameters = {"results_location": "/lorout/output.tar", "utility_image": util_image.identifier, "utility_customizations": util_xml, "oz_overrides": json.dumps(imgfunc.ozoverrides) } print "Building the lorax image" loraxiso_builder = bd.builder_for_target_image("indirection", image_id=util_image.identifier, template=None, parameters=lorax_parameters) loraxiso_image = loraxiso_builder.target_image thread = loraxiso_builder.target_thread thread.join() # Extract the tarball of built images print "Extracting images to {0}/images".format(outputdir) t = tarfile.open(loraxiso_image.data) t.extractall(path=outputdir) trivhttp.stop()