Michal Novotny
2010-May-25 14:39 UTC
[Xen-devel] [PATCH] pyGrub: Use proper bootloader class when entering command manually
Hi, this is the patch to use the proper bootloader class when entering the boot commands manually (i.e. using the ''c'' option). Before this patch the bootloader was always treated to be Grub but when user is using Grub2/ExtLinux or Lilo it''s rather confusing. After applying this patch the proper bootloader image class is being used, e.g. Grub2Image for Grub2 etc. when you define the boot commands manually using the ''c'' command in pyGrub. Also, fix for using isconfig has been applied since if there is not fs set in the run_grub() method the read_config() would fail since it''s trying to access undefined self.cf which is now being set to parser() from cfg_list. Signed-off-by: Michal Novotny <minovotn@redhat.com> -- Michal Novotny<minovotn@redhat.com>, RHCE Virtualization Team (xen userspace), Red Hat _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Michal Novotny
2010-May-25 15:13 UTC
Re: [Xen-devel] [PATCH] pyGrub: Use proper bootloader class when entering command manually
Ok, I found that the infrastructure of ExtLinuxImage and LiloImage is different so I rewrote it a little (but according to the code the old behaviour should be preserved) and also fixed the isconfig bug (since no img.initrd is accessible that time). So please ignore the previous version of my patch and use this one. Thanks, Michal Signed-off-by: Michal Novotny <minovotn@redhat.com> On 05/25/2010 04:39 PM, Michal Novotny wrote:> Hi, > this is the patch to use the proper bootloader class when entering the > boot commands manually (i.e. using the ''c'' option). Before this patch > the bootloader was always treated to be Grub but when user is using > Grub2/ExtLinux or Lilo it''s rather confusing. After applying this > patch the proper bootloader image class is being used, e.g. Grub2Image > for Grub2 etc. when you define the boot commands manually using the > ''c'' command in pyGrub. > > Also, fix for using isconfig has been applied since if there is not fs > set in the run_grub() method the read_config() would fail since it''s > trying to access undefined self.cf which is now being set to parser() > from cfg_list. > > Signed-off-by: Michal Novotny <minovotn@redhat.com> > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel >-- Michal Novotny<minovotn@redhat.com>, RHCE Virtualization Team (xen userspace), Red Hat _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-May-25 16:22 UTC
Re: [Xen-devel] [PATCH] pyGrub: Use proper bootloader class when entering command manually
On Tue, 2010-05-25 at 16:13 +0100, Michal Novotny wrote:> Ok, I found that the infrastructure of ExtLinuxImage and LiloImage is > different so I rewrote it a little (but according to the code the old > behaviour should be preserved) and also fixed the isconfig bug (since no > img.initrd is accessible that time). > > So please ignore the previous version of my patch and use this one.Perhaps instead of these two hunks: --- a/tools/pygrub/src/pygrub Tue May 25 11:28:58 2010 +0100 +++ b/tools/pygrub/src/pygrub Tue May 25 17:10:32 2010 +0200 @@ -356,7 +356,7 @@ class Grub: continue # if we got boot, then we want to boot the entered image - img = grub.GrubConf.GrubImage(lines) + img = self.imgcl("entered", lines) self.cf.add_image(img) self.selected_image = len(self.cf.images) - 1 self.isdone = True [...] self.cf = parser() self.cf.filename = f + + # Get the bootloader image file constructor to imgcl + if type(self.cf) == grub.LiloConf.LiloConfigFile: + self.imgcl = grub.LiloConf.LiloImage + elif type(self.cf) == grub.GrubConf.Grub2ConfigFile: + self.imgcl = grub.GrubConf.Grub2Image + elif type(self.cf) =grub.ExtLinuxConf.ExtLinuxConfigFile: + self.imgcl = grub.ExtLinuxConf.ExtLinuxImage + else: + self.imgcl = grub.GrubConf.GrubImage + break if self.__dict__.get(''cf'', None) is None: raise RuntimeError, "couldn''t find bootloader config file in the image provided." We could add a method to each of the self.cf classes which returns a new image from the title+lines given. Then the first hunk becomes something like: - img = grub.GrubConf.GrubImage(lines) + img = self.cf.new_image("entered", lines) and the second bit goes away. This would be nice since it avoids hardcoding another list of bootloaders. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Michal Novotny
2010-May-26 09:27 UTC
Re: [Xen-devel] [PATCH] pyGrub: Use proper bootloader class when entering command manually
Yeah, that''s right Ian. However adding a new method called new_image() to all of the boot loader configuration classes (*ConfigFile classes) will still be necessary. I wrote a new version of my patch to add support for new_image() method all the existing classes and did the modifications to pygrub. As in previous version of my patch, the isconfig debug option has been fixed too. Keir, please use this version to be committed. Thanks, Michal Signed-off-by: Michal Novotny <minovotn@redhat.com> On 05/25/2010 06:22 PM, Ian Campbell wrote:> On Tue, 2010-05-25 at 16:13 +0100, Michal Novotny wrote: > >> Ok, I found that the infrastructure of ExtLinuxImage and LiloImage is >> different so I rewrote it a little (but according to the code the old >> behaviour should be preserved) and also fixed the isconfig bug (since no >> img.initrd is accessible that time). >> >> So please ignore the previous version of my patch and use this one. >> > Perhaps instead of these two hunks: > > --- a/tools/pygrub/src/pygrub Tue May 25 11:28:58 2010 +0100 > +++ b/tools/pygrub/src/pygrub Tue May 25 17:10:32 2010 +0200 > @@ -356,7 +356,7 @@ class Grub: > continue > > # if we got boot, then we want to boot the entered image > - img = grub.GrubConf.GrubImage(lines) > + img = self.imgcl("entered", lines) > self.cf.add_image(img) > self.selected_image = len(self.cf.images) - 1 > self.isdone = True > > [...] > self.cf = parser() > self.cf.filename = f > + > + # Get the bootloader image file constructor to imgcl > + if type(self.cf) == grub.LiloConf.LiloConfigFile: > + self.imgcl = grub.LiloConf.LiloImage > + elif type(self.cf) == grub.GrubConf.Grub2ConfigFile: > + self.imgcl = grub.GrubConf.Grub2Image > + elif type(self.cf) => grub.ExtLinuxConf.ExtLinuxConfigFile: > + self.imgcl = grub.ExtLinuxConf.ExtLinuxImage > + else: > + self.imgcl = grub.GrubConf.GrubImage > + > break > if self.__dict__.get(''cf'', None) is None: > raise RuntimeError, "couldn''t find bootloader config file > in the image provided." > > We could add a method to each of the self.cf classes which returns a new > image from the title+lines given. Then the first hunk becomes something > like: > > - img = grub.GrubConf.GrubImage(lines) > + img = self.cf.new_image("entered", lines) > > and the second bit goes away. This would be nice since it avoids > hardcoding another list of bootloaders. > > Ian. > >-- Michal Novotny<minovotn@redhat.com>, RHCE Virtualization Team (xen userspace), Red Hat _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-May-26 09:29 UTC
Re: [Xen-devel] [PATCH] pyGrub: Use proper bootloader class when entering command manually
On Wed, 2010-05-26 at 10:27 +0100, Michal Novotny wrote:> Yeah, that''s right Ian. However adding a new method called new_image() > to all of the boot loader configuration classes (*ConfigFile classes) > will still be necessary. I wrote a new version of my patch to add > support for new_image() method all the existing classes and did the > modifications to pygrub. > > As in previous version of my patch, the isconfig debug option has been > fixed too. > > Keir, please use this version to be committed. > > Thanks, > Michal > > Signed-off-by: Michal Novotny <minovotn@redhat.com>Acked-by: Ian Campbell <ian.campbell@citrix.com>> > On 05/25/2010 06:22 PM, Ian Campbell wrote: > > On Tue, 2010-05-25 at 16:13 +0100, Michal Novotny wrote: > > > >> Ok, I found that the infrastructure of ExtLinuxImage and LiloImage is > >> different so I rewrote it a little (but according to the code the old > >> behaviour should be preserved) and also fixed the isconfig bug (since no > >> img.initrd is accessible that time). > >> > >> So please ignore the previous version of my patch and use this one. > >> > > Perhaps instead of these two hunks: > > > > --- a/tools/pygrub/src/pygrub Tue May 25 11:28:58 2010 +0100 > > +++ b/tools/pygrub/src/pygrub Tue May 25 17:10:32 2010 +0200 > > @@ -356,7 +356,7 @@ class Grub: > > continue > > > > # if we got boot, then we want to boot the entered image > > - img = grub.GrubConf.GrubImage(lines) > > + img = self.imgcl("entered", lines) > > self.cf.add_image(img) > > self.selected_image = len(self.cf.images) - 1 > > self.isdone = True > > > > [...] > > self.cf = parser() > > self.cf.filename = f > > + > > + # Get the bootloader image file constructor to imgcl > > + if type(self.cf) == grub.LiloConf.LiloConfigFile: > > + self.imgcl = grub.LiloConf.LiloImage > > + elif type(self.cf) == grub.GrubConf.Grub2ConfigFile: > > + self.imgcl = grub.GrubConf.Grub2Image > > + elif type(self.cf) => > grub.ExtLinuxConf.ExtLinuxConfigFile: > > + self.imgcl = grub.ExtLinuxConf.ExtLinuxImage > > + else: > > + self.imgcl = grub.GrubConf.GrubImage > > + > > break > > if self.__dict__.get(''cf'', None) is None: > > raise RuntimeError, "couldn''t find bootloader config file > > in the image provided." > > > > We could add a method to each of the self.cf classes which returns a new > > image from the title+lines given. Then the first hunk becomes something > > like: > > > > - img = grub.GrubConf.GrubImage(lines) > > + img = self.cf.new_image("entered", lines) > > > > and the second bit goes away. This would be nice since it avoids > > hardcoding another list of bootloaders. > > > > Ian. > > > > > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel