Revision: bfbf409beab0
Author: Schlomo Schapiro <
l...@schlomo.schapiro.org>
Date: Tue Jun 5 06:25:18 2012
Log: * New functions to set custom attributes
* New HTTP API to unset Force Boot flags.
* Configuration for Force Boot flag name comes from /etc/lml.conf
* Use like this in %post of your kickstart to deactivate Force Boot after
successful installation:
curl -f http://<LML
server>/boot/lml/unsetForceBoot.pl\?uuid=$(dmidecode -s system-uuid)
http://code.google.com/p/lml/source/detail?r=bfbf409beab0
Added:
/web/www/boot/lml/tools/setCustomValue.pl
/web/www/boot/lml/unsetForceBoot.pl
Modified:
/web/www/boot/lml/lib/LML/VMware.pm
=======================================
--- /dev/null
+++ /web/www/boot/lml/tools/setCustomValue.pl Tue Jun 5 06:25:18 2012
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+#
+#
+# setCustomValue.pl Lab Manager Light unset Force Boot
+#
+# Authors:
+# GSS Schlomo Schapiro <
l...@schlomo.schapiro.org>
+#
+# Copyright: Schlomo Schapiro, Immobilien Scout GmbH
+# License: GNU General Public License, see
http://www.gnu.org/licenses/gpl.txt for full text
+#
+#
+
+use strict;
+use warnings;
+
+
+# place DLLs and PMs with the required subdirectory structure into lib/
next to this script
+use FindBin;
+use lib "$FindBin::RealBin/../lib";
+
+use CGI ':standard';
+use LML::Common;
+use LML::Subversion;
+use LML::VMware;
+use LML::DHCP;
+
+# connect to vSphere
+connect_vi();
+
+# input parameter, UUID of a VM
+my $search_uuid=param('uuid')?lc(param('uuid')):lc($ARGV[0]);
+my $key=param('key')?param('key'):$ARGV[1];
+my $value=param('value')?param('value'):$ARGV[2];
+
+if ($search_uuid and $key and $value) {
+ print header('text/plain');
+ setVmCustomValueU($search_uuid,$key,$value);
+} else {
+ print header(-status=>404,-type=>'text/plain');
+ print "URL call: uuid=...&key=...value=...\nCLI call: <uuid> <key>
<value>\n";
+}
=======================================
--- /dev/null
+++ /web/www/boot/lml/unsetForceBoot.pl Tue Jun 5 06:25:18 2012
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+#
+#
+# unsetForceBoot.pl Lab Manager Light unset Force Boot
+#
+# Authors:
+# GSS Schlomo Schapiro <
l...@schlomo.schapiro.org>
+#
+# Copyright: Schlomo Schapiro, Immobilien Scout GmbH
+# License: GNU General Public License, see
http://www.gnu.org/licenses/gpl.txt for full text
+#
+#
+
+use strict;
+use warnings;
+
+
+# place DLLs and PMs with the required subdirectory structure into lib/
next to this script
+use FindBin;
+use lib "$FindBin::RealBin/lib";
+
+use CGI ':standard';
+use LML::Common;
+use LML::Subversion;
+use LML::VMware;
+use LML::DHCP;
+
+# connect to vSphere
+connect_vi();
+
+# input parameter, UUID of a VM
+my $search_uuid=param('uuid')?lc(param('uuid')):lc($ARGV[0]);
+
+die "No forceboot_field parameter set in [vsphere] section" unless
(exists($CONFIG{vsphere}{forceboot_field}) and
$CONFIG{vsphere}{forceboot_field});
+
+if ($search_uuid) {
+ print header('text/plain');
+ setVmCustomValueU($search_uuid,$CONFIG{vsphere}{forceboot_field},"");
+} else {
+ print header(-status=>404,-type=>'text/plain');
+ print "Give UUID address as query parameter 'uuid' or as command line
parameter\n";
+}
=======================================
--- /web/www/boot/lml/lib/LML/VMware.pm Tue Dec 27 07:45:01 2011
+++ /web/www/boot/lml/lib/LML/VMware.pm Tue Jun 5 06:25:18 2012
@@ -11,9 +11,9 @@
@ISA
@EXPORT
);
-our $VERSION = 1.00;
+our $VERSION = 1.10;
our @ISA = qw(Exporter);
-our @EXPORT = qw(connect_vi get_vm_data search_vm custom_fields
setVmExtraOptsU setVmExtraOptsM);
+our @EXPORT = qw(connect_vi get_vm_data search_vm custom_fields
setVmExtraOptsU setVmExtraOptsM setVmCustomValueU setVmCustomValueM);
use VMware::VIRuntime;
@@ -401,4 +401,72 @@
}
}
}
+
+############################### sub #################
+##
+## setVmCustomValue (<VM object>,<option key>,<option value>)
+##
+##
+sub setVmCustomValue {
+ my $vm = shift;
+ my $key = shift;
+ my $value = shift;
+ eval {
+ if($vm) {
+ $vm->setCustomValue(key=>$key,value=>$value);
+ }
+ };
+ if ($@) {
+ Util::trace(0, "\nsetCustomValue($key,$value) failed: ");
+ if (ref($@) eq 'SoapFault') {
+ if (ref($@->detail) eq 'TooManyDevices') {
+ Util::trace(0, "\nNumber of virtual devices exceeds "
+ . "the maximum for a given controller.\n");
+ }
+ elsif (ref($@->detail) eq 'InvalidDeviceSpec') {
+ Util::trace(0, "The Device configuration is not valid\n");
+ Util::trace(0, "\nFollowing is the detailed error: \n\n$@");
+ }
+ elsif (ref($@->detail) eq 'FileAlreadyExists') {
+ Util::trace(0, "\nOperation failed because file already exists");
+ }
+ else {
+ Util::trace(0, "\n" . $@ . "\n");
+ }
+ } else {
+ Util::trace(0, "\n" . $@ . "\n");
+ }
+ }
+}
+
+############################### sub #################
+##
+## setVmCustomValueM (<moref of VM>,<option key>,<option value>)
+##
+##
+sub setVmCustomValueM {
+ my $mo_ref = shift;
+ my $key = shift;
+ my $value = shift;
+ my $vm_view = Vim::get_view(mo_ref=>$mo_ref);
+ if($vm_view) {
+ setVmCustomValue($vm_view,$key,$value)
+ }
+}
+
+############################### sub #################
+##
+## setVmCustomValueU (<uuid of VM>,<option key>,<option value>)
+##
+##
+sub setVmCustomValueU {
+ my $uuid = shift;
+ my $key = shift;
+ my $value = shift;
+ my $vm_view = Vim::find_entity_view(view_type => 'VirtualMachine',
+ filter => {"config.uuid"
=> $uuid});
+ if($vm_view) {
+ setVmCustomValue($vm_view,$key,$value)
+ }
+}
1;