Created
July 28, 2015 13:39
-
-
Save rvrangel/81b75dfe89b59410ff7b to your computer and use it in GitHub Desktop.
XenServer 6.x script to set VM auto poweron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use Term::ANSIColor; | |
&print_usage && exit if $ARGV[0] =~ /^-{1,2}h(elp)?/; | |
if ($ARGV[0]) { | |
&print_usage && die "error: poweron must be true or false\n" if $ARGV[1] !~ /^(false|true)$/; | |
my ($name, $poweron) = @ARGV; | |
my $uuid = `xe vm-list name-label=\"$name\" | grep uuid`; | |
if ($uuid =~ s/.*: ([\w-]+)\n$/$1/) { | |
my $return = `xe vm-param-set uuid=$uuid other-config:auto_poweron=$poweron`; | |
print $return; | |
} else { | |
&print_usage && die "error: failed to get VM uuid\n"; | |
} | |
} else { | |
my @uuid = `xe vm-list | grep uuid`; | |
@uuid = map {s/.*: ([\w-]+)\n$/$1/; $_} @uuid; | |
for (@uuid) { | |
my $name = `xe vm-param-get uuid=$_ param-name=name-label`; | |
my $param = `xe vm-param-get uuid=$_ param-name=other-config`; | |
print "Server: $name"; | |
if ($param =~ /auto_poweron: true/) { | |
print 'auto_poweron: ', color('green'), "true\n\n"; | |
} else { | |
print 'auto_poweron: ', color('red'), "false\n\n"; | |
} | |
print color 'reset'; | |
} | |
} | |
sub print_usage { | |
warn "\nUSAGE:\n============\n"; | |
warn "List poweron setting for all VMs:\n\$ $0 \n\n"; | |
warn "Set VM to power on during boot:\n\$ $0 <vmname> <true|false>\n\n"; | |
warn "Don't forget to configure your XenServer pool to auto start VMs: http://support.citrix.com/article/CTX133910\n\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
at line 12 You can simply get the uuid of the vm without the extra grep, and processing of the output with:
xe vm-list params=uuid name-label=\"$name\" is-control-domain=false --minimal
at line 22 To filter out the xenserver host itself, and to get the uuid-s in one step you could use following command:
xe vm-list params=uuid is-control-domain=false --minimal
this would present you a comma-delimited listing of the uuid-s which would be lot more easy to map the list.