Re: [webmin-devel] Solaris Zones module
Todd Kennedy <[email protected]> Tue, 30 Jun 2009 17:57:07 -0400
| Newsgroups | gmane.comp.web.webmin.devel |
|---|---|
| Message-ID | <[email protected]> |
Hey Jamie,
I finished making some changes to the Solaris Zones module. The biggest
change is so that it could support branding. I also fixed a few additional
issues:
1. Return link in the edit create and save pages were missing someplace to
return to, so I added index.cgi as a return point.
2. The get_confirm_page subroutine in forms-lib.pl is using
Webmin::ConfirmPage with only one button. This produced the regular sized
button with the correct action label and also another button which should be
cancel but there wasn't any text defined. So the cancel button was really
small. Kind of looked like a radio button. So I fixed that...
3. When using the ctrun command to boot a zone was causing webmin to
continue polling for a return. This was not a webmin problem, more of how
ctrun was invoked. The command { ctrun zoneadm -z some_zone boot } when run
from a console never exits for some reason. So I added an option to end when
the child command ends thus fixing the problem inside of webmin. This used
to drive me nutz. I'd boot a zone through webmin and it would never return
"done". Sometimes if I let it run for a long time in my browser, the browser
would hang and I'd have to force kill the browser.
So anyway the patch is attached.
There's one caveat to using zones in webmin. The first time you boot the
zone it runs sysconfig so you have to use zlogin in console mode to make the
selections before all the services will start properly. If you don't do this
you can still start the zone but it's in single user mode "hard to tell" and
inetd is waiting on sysconfig to finish. So I'm not sure if there is a way
to allow webmin to interact with zlogin. I think this would be like running
a telnet session from within webmin. not sure how to do that...
Havin' Fun with Code,
-Todd-
On Sun, Jun 28, 2009 at 10:13 PM, Jamie Cameron <[email protected]> wrote:
> I see the bug - the ui_select functions 3rd arg needs to be an array ref,
> you you need to surround the list_brands call with [ ]
>
> - Jamie
>
> On Jun 28, 2009, at 4:34 PM, Todd Kennedy <[email protected]> wrote:
>
> Jamie,
>
> maybe you can help me with something. I'm trying to add the branding
> functionality of zones to the Solaris Zone module. For some reason my select
> box in the create_form.cgi keeps coming up as empty. Here's the code that I
> added below. I know readdir only returns single file / directory
> entries...so I'm not sure it I'm populating the @rv array correctly. The @rv
> array should look like this I'm assuming:
>
> Since the directory entries under /usr/lib/brand are natvie, solaris8,
> solaris9 and the parent and current. I'm filtering out the parent and
> current which should leave me with the three remaining directories. So maybe
> you can point something out to me that I'm missing....
>
> @rv = (native,solaris8,solaris9)
>
> ------------------create_form.cgi-------------------
> print &ui_table_row($text{'create_brand'},
> &ui_select("brand",undef, &list_brands(), 0, 0, $value ? 1 :
> 0));
> -----------------------------------------------------------
>
> ------------------forms-lib.pl-------------------------
> local $brand = new Webmin::Select("brand",undef, &list_brands(), 0, 0,
> $value ? 1 : 0);
> $section->add_input($text{'create_brand'}, $brand);
> -----------------------------------------------------------
>
> ------------------zones-lib.pl------------------------
> #list brands()
> #returns a list of valid brands
> sub list_brands
> {
> local @rv;
> opendir(BRND, "/usr/lib/brand");
> foreach (readdir(BRND)) {
> if ($_ !~ /^\./){
> push(@rv, $_);
> }
> }
> close(BRND);
> return @rv;
> }
> ------------------------------------------------------------
>
>
>
>
>
> On Sun, Jun 28, 2009 at 2:50 AM, Jamie Cameron < <[email protected]>
> [email protected]> wrote:
>
>> On 26/Jun/2009 06:22 Todd Kennedy < <[email protected]>
>> [email protected]> wrote ..
>> > Yeah I can add them to SVN....I guess once I have access I'll download
>> the
>> > files I need to change from SVN then upload them once the changes have
>> been
>> > made.
>>
>> Actually, it might be simpler if you just download Webmin 1.480, make your
>> changes, then send me a patch.
>>
>> > Also - There's a problem with the The breadcrumb link in Solaris Zones
>> that
>> > is suppose to get you back to the previous page...but what happens is
>> that
>> > when you click it it reruns the previous selection. So if you created a
>> zone
>> > and then selected the return to zones list link at the bottom of the
>> page it
>> > tries to create the zone again....I can hunt that down but might take me
>> > longer since I'm still trying to familiarize myself with that module.
>>
>> That sounds like a bug. Let me know if you find the cause..
>>
>> - Jamie
>>
>> > On Fri, Jun 26, 2009 at 3:51 AM, Jamie Cameron < <[email protected]>
>> [email protected]> wrote:
>> >
>> > > On 25/Jun/2009 17:40 Todd Kennedy wrote ..
>> > >
>> > > Hey guys,
>> > >
>> > > I've been doing some work on the Solaris Zones module and have added a
>> few
>> > > features and plan on making a few more. Like the ability to define a
>> spare
>> > > root zone or whole root zone before the config, plus I plan adding the
>> > > template feature of zonecfg to the creation process as well. This
>> would help
>> > > out allot since Solaris zones support branding of sol8 and sol9. Once
>> I am
>> > > finished what is the best way to get patches to you Jamie? I've never
>> > > submitted anything before so I'm new to that part of it.
>> > >
>> > > Thanks
>> > >
>> > > Hi Todd,
>> > >
>> > > You can just email a patch to me directly at <[email protected]>
>> [email protected] , and I
>> > > will apply it for inclusion in the next Webmin release. The zones mode
>> > > hasn't been touched for a while, and so is overdue for some new
>> features.
>> > >
>> > > If you plan to do a lot of development, I can grant you commit access
>> to
>> > > the Webmin SVN repository..
>> > >
>> > > - Jamie
>> > >
>> > >
>> > >
>> > >
>> ------------------------------------------------------------------------------
>> > >
>> > > -
>> > > Forwarded by the Webmin development list at <[email protected]>
>> [email protected]
>> > > To remove yourself from this list, go to
>> > > <http://lists.sourceforge.net/lists/listinfo/webadmin-devel>
>> http://lists.sourceforge.net/lists/listinfo/webadmin-devel
>> > >
>> > >
>>
>>
>> ------------------------------------------------------------------------------
>> -
>> Forwarded by the Webmin development list at <[email protected]>
>> [email protected]
>> To remove yourself from this list, go to
>> <http://lists.sourceforge.net/lists/listinfo/webadmin-devel>
>> http://lists.sourceforge.net/lists/listinfo/webadmin-devel
>>
>
>
> ------------------------------------------------------------------------------
>
> -
> Forwarded by the Webmin development list at <[email protected]>
> [email protected]
> To remove yourself from this list, go to
> http://lists.sourceforge.net/lists/listinfo/webadmin-devel
>
>
>
> ------------------------------------------------------------------------------
>
> -
> Forwarded by the Webmin development list at [email protected]
> To remove yourself from this list, go to
> http://lists.sourceforge.net/lists/listinfo/webadmin-devel
>
>
------------------------------------------------------------------------------
-
Forwarded by the Webmin development list at [email protected]
To remove yourself from this list, go to
http://lists.sourceforge.net/lists/listinfo/webadmin-devel
webmin_solaris_zone.patch
(text/x-patch, 8.9 KB)
Index: zones/edit_zone.cgi
===================================================================
RCS file: /usr/local/cvsroot/webmin solaris zone/zones/edit_zone.cgi,v
retrieving revision 1.1
diff -u -r1.1 edit_zone.cgi
--- zones/edit_zone.cgi 30 Jun 2009 17:05:36 -0000 1.1
+++ zones/edit_zone.cgi 30 Jun 2009 17:16:06 -0000
@@ -140,7 +140,7 @@
$gtable->add_link("edit_attr.cgi?zone=$in{'zone'}&new=1",
$text{'edit_attradd'});
-$p->add_footer("", $text{'index_return'});
+$p->add_footer("index.cgi", $text{'index_return'});
$p->print();
Index: zones/forms-lib.pl
===================================================================
RCS file: /usr/local/cvsroot/webmin solaris zone/zones/forms-lib.pl,v
retrieving revision 1.1
diff -u -r1.1 forms-lib.pl
--- zones/forms-lib.pl 30 Jun 2009 17:05:36 -0000 1.1
+++ zones/forms-lib.pl 30 Jun 2009 17:16:06 -0000
@@ -21,6 +21,7 @@
$section->add_input($text{'edit_autoboot'}, $auto);
local $pool = &pool_object("pool", $zinfo->{'pool'});
$section->add_input($text{'edit_pool'}, $pool);
+$section->add_row($text{'edit_brand'}, "$zinfo->{'brand'}");
local @actions = &zone_status_actions($zinfo, 1);
$form->add_button(new Webmin::Submit($text{'save'}, "save"));
@@ -48,9 +49,9 @@
local $p = new Webmin::ConfirmPage(&zone_title($zinfo->{'name'}),
$text{$action.'_title'},
&text($action.'_rusure', "<tt>$zinfo->{'name'}</tt>"),
- "save_zone.cgi", $in, $text{'edit_'.$action});
+ "save_zone.cgi", $in, $text{'edit_'.$action}, $text{'ui_cancel'});
if ($list) {
- $p->add_footer("", $text{'index_return'});
+ $p->add_footer("index.cgi", $text{'index_return'});
}
else {
$p->add_footer("edit_zone.cgi?zone=$zinfo->{'name'}",
@@ -70,7 +71,7 @@
$d->set_message($text{$action.'_doing'});
$d->set_wait(1);
if ($list || $action eq "delete") {
- $p->add_footer("", $text{'index_return'});
+ $p->add_footer("index.cgi", $text{'index_return'});
}
else {
$p->add_footer("edit_zone.cgi?zone=$zinfo->{'name'}",
@@ -466,6 +467,9 @@
$path->set_validation_func(\&validate_zone_path);
$section->add_input($text{'create_path'}, $path);
+local $brand = new Webmin::Select("brand",undef, [ &list_brands() ], 0, 0, $value ? 1 : 0);
+$section->add_input($text{'create_brand'}, $brand);
+
local $address = new Webmin::OptTextbox("address", undef, 20,
$text{'create_noaddress'});
$address->set_validation_func(\&validate_address);
@@ -482,6 +486,11 @@
[ 0, $text{'no'} ] ]);
$section->add_input($text{'create_webmin'}, $webmin);
+local $inherit = new Webmin::Radios("inherit", 1, [ [ 1, $text{'pkg_inherit_yes'} ],
+ [ 0, $text{'pkg_inherit_no'} ] ]);
+$section->add_input($text{'pkg_inherit'}, $inherit);
+
+
local $pkgs = new Webmin::Multiline("pkgs", undef, 5, 50);
$section->add_input($text{'create_pkgs'}, $pkgs);
Index: zones/create_form.cgi
===================================================================
RCS file: /usr/local/cvsroot/webmin solaris zone/zones/create_form.cgi,v
retrieving revision 1.1
diff -u -r1.1 create_form.cgi
--- zones/create_form.cgi 30 Jun 2009 17:05:36 -0000 1.1
+++ zones/create_form.cgi 30 Jun 2009 17:16:06 -0000
@@ -25,6 +25,9 @@
&text('create_auto', $config{'base_dir'}),
$text{'create_sel'})."\n".
&file_chooser_button("path", 1));
+
+print &ui_table_row($text{'create_brand'},
+ &ui_select("brand",undef, [ &list_brands() ], 0, 0, $value ? 1 : 0));
print &ui_table_row($text{'create_address'},
&ui_opt_textbox("address", undef, 20,
@@ -38,6 +41,9 @@
print &ui_table_row($text{'create_webmin'},
&ui_yesno_radio("webmin", 0));
+
+print &ui_table_row($text{'pkg_inherit'},
+ &ui_yesno_radio("inherit", 0));
print &ui_table_row($text{'create_pkgs'},
&ui_textarea("pkgs", undef, 5, 50));
@@ -111,5 +117,5 @@
print &ui_table_end();
print &ui_form_end([ [ "ok", $text{'create_ok'} ] ]);
-&ui_print_footer("", $text{'index_return'});
+&ui_print_footer("index.cgi", $text{'index_return'});
Index: zones/zones-lib.pl
===================================================================
RCS file: /usr/local/cvsroot/webmin solaris zone/zones/zones-lib.pl,v
retrieving revision 1.1
diff -u -r1.1 zones-lib.pl
--- zones/zones-lib.pl 30 Jun 2009 17:05:36 -0000 1.1
+++ zones/zones-lib.pl 30 Jun 2009 17:16:07 -0000
@@ -56,7 +56,7 @@
# Add zone-level variables
local ($p, $r);
-foreach $p ("zonepath", "autoboot", "pool") {
+foreach $p ("zonepath", "autoboot", "pool", "brand") {
local @lines = &get_zonecfg_output($zone, "info $p");
if ($lines[0] =~ /^$p:\s*(.*)/) {
$zinfo->{$p} = $1;
@@ -170,7 +170,12 @@
sub delete_zone_object
{
local ($zinfo, $thing) = @_;
-&get_zonecfg_output($zinfo->{'name'}, "remove $thing->{'keytype'} $thing->{'keyfield'}=$thing->{'key'}", 1);
+if ( !$thing->{'keyfield'}) {
+ &get_zonecfg_output($zinfo->{'name'}, "remove -F $thing->{'keytype'}", 1);
+ }
+ else {
+ &get_zonecfg_output($zinfo->{'name'}, "remove $thing->{'keytype'} $thing->{'keyfield'}=$thing->{'key'}", 1);
+ }
}
# create_zone(name, path)
@@ -313,7 +318,7 @@
sub run_zone_command
{
local ($zinfo, $cmd, $re) = @_;
-local $out = &backquote_logged("ctrun zoneadm -z $zinfo->{'name'} $cmd 2>&1");
+local $out = &backquote_logged("ctrun -l child zoneadm -z $zinfo->{'name'} $cmd 2>&1");
if ($? && !$re) {
&error("<tt>zoneadm</tt> failed : <tt>$out</tt>");
}
@@ -417,6 +422,22 @@
return @rv;
}
+#list_brands()
+#returns a list of valid brands
+sub list_brands
+{
+ local @rv;
+ opendir(BRND, "/usr/lib/brand");
+ foreach (readdir(BRND)) {
+ if ($_ !~ /^\./){
+ push(@rv, $_);
+ }
+ }
+ close(BRND);
+return @rv;
+}
+
+
# run_in_zone(&zinfo, command)
# Runs some command within a zone, and returns the output
sub run_in_zone
Index: zones/create_zone.cgi
===================================================================
RCS file: /usr/local/cvsroot/webmin solaris zone/zones/create_zone.cgi,v
retrieving revision 1.1
diff -u -r1.1 create_zone.cgi
--- zones/create_zone.cgi 30 Jun 2009 17:05:36 -0000 1.1
+++ zones/create_zone.cgi 30 Jun 2009 17:16:06 -0000
@@ -112,19 +112,32 @@
}
}
-# Add extra package directories
-if (@pkgs) {
- $d3 = new Webmin::DynamicHTML(\&execute_pkgs, undef, $text{'create_addingpkgs'});
- $p->add_form($d3);
- sub execute_pkgs
- {
- foreach $p (@pkgs) {
- $pkg = { 'keytype' => 'inherit-pkg-dir',
- 'dir' => $p };
- &create_zone_object($zinfo, $pkg);
+# Add or remove extra package directories
+# add for sparse root zone and remove for whole root zone
+if ($in{'inherit'} eq '0' ) {
+ $d3 = new Webmin::DynamicHTML(\&remove_pkgs, undef, $text{'create_removingpkgs'});
+ $p->add_form($d3);
+ sub remove_pkgs
+ {
+ $pkg = { 'keytype' => 'inherit-pkg-dir' };
+ &delete_zone_object($zinfo,$pkg);
+ $p->add_message_after($d3, $text{'create_done'});
+ }
+}
+ else {
+ if (@pkgs) {
+ $d3 = new Webmin::DynamicHTML(\&execute_pkgs, undef, $text{'create_addingpkgs'});
+ $p->add_form($d3);
+ sub execute_pkgs
+ {
+ foreach $p (@pkgs) {
+ $pkg = { 'keytype' => 'inherit-pkg-dir',
+ 'dir' => $p };
+ &create_zone_object($zinfo, $pkg);
+ }
+ $p->add_message_after($d3, $text{'create_done'});
+ }
}
- $p->add_message_after($d3, $text{'create_done'});
- }
}
if ($in{'install'}) {
@@ -187,7 +200,19 @@
}
}
-$p->add_footer("", $text{'index_return'});
+#set the brand
+if ($in{'brand'}) {
+ $d6 = new Webmin::DynamicHTML(\&create_brand,undef, $text{'create_brandmsg'});
+ $p->add_form($d6);
+
+ sub create_brand
+ {
+ &set_zone_variable($zinfo,"brand",$form->get_value("brand"));
+ $p->add_message_after($d6, $text{'create_done'});
+ }
+}
+
+$p->add_footer("index.cgi", $text{'index_return'});
$p->print();
&webmin_log("create", "zone", $in{'name'});
Index: zones/lang/en
===================================================================
RCS file: /usr/local/cvsroot/webmin solaris zone/zones/lang/en,v
retrieving revision 1.1
diff -u -r1.1 en
--- zones/lang/en 30 Jun 2009 17:05:36 -0000 1.1
+++ zones/lang/en 30 Jun 2009 17:16:07 -0000
@@ -57,6 +57,9 @@
edit_attrnone=No generic attributes have been defined yet.
edit_attradd=Add a new generic attribute.
edit_webmin=Open Webmin
+edit_brand=Brand
+
+ui_cancel=Cancel
save_err=Failed to save zone
save_epool=Missing or invalid pool
@@ -112,6 +115,10 @@
pkg_err=Failed to save package directory
pkg_edir=Invalid or non-existant directory
pkg_eclash=The package directory already exists in this zone
+pkg_inherit=Inherit packages from global zone
+pkg_inherit_yes=Yes (sparse root zone)
+pkg_inherit_no=No (whole root zone)
+
fs_title1=Create Filesystem
fs_title2=Edit Filesystem
@@ -248,6 +255,9 @@
create_eresolvname=The zone's hostname could not be resolved, which will cause automatic configuration to fail. You should add it to the DNS before creating this zone
create_router=Default router
create_erouter=Missing or invalid default router IP address
+create_removingpkgs=removing inherited package directories ...
+create_brand=Brand
+create_brandmsg=Branding zone
log_create_zone=Created zone $1
log_delete_zone=Deleted zone $1