Subversion Repositories havirt

Rev

Rev 10 | Rev 13 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 12
Line 48... Line 48...
48
   my @return;
48
   my @return;
49
   push @return, "domain update [domainname|-t domainname]";
49
   push @return, "domain update [domainname|-t domainname]";
50
   push @return, "\tUpdates capabilities on one or more domains, default is all domains";
50
   push @return, "\tUpdates capabilities on one or more domains, default is all domains";
51
   push @return, "domain list [--format|-f screen|tsv]";
51
   push @return, "domain list [--format|-f screen|tsv]";
52
   push @return, "\tLists all domains with some statistics about them as screen or tsv (default screen)";
52
   push @return, "\tLists all domains with some statistics about them as screen or tsv (default screen)";
-
 
53
   push @return, "domain start domainname [node]";
-
 
54
   push @return, "\tstarts domainname on node. If node not set, will pick a node.";
53
   return join( "\n", @return ) . "\n";
55
   return join( "\n", @return ) . "\n";
54
}
56
}
55
 
57
 
56
 
58
 
57
sub list {
59
sub list {
58
   &main::loadVirtDB();
60
   &main::readDB();
59
   &main::loadNodePopulations();
-
 
60
   print Dumper( $main::nodePopulations ) if $main::DEBUG > 2;
61
   print Dumper( $main::statusDB->{'nodePopulation'} ) if $main::DEBUG > 2;
61
 
62
 
62
   my @header;
63
   my @header;
63
   my @data;
64
   my @data;
64
   
65
   
65
   foreach my $node ( keys %$main::nodePopulations ) {
66
   foreach my $node ( keys %{$main::statusDB->{'nodePopulation'}} ) {
66
      foreach my $virt (keys %{$main::nodePopulations->{$node}->{'running'}} ) {
67
      foreach my $virt (keys %{$main::statusDB->{'nodePopulation'}->{$node}->{'running'}} ) {
67
         unless ( @header ) {
68
         unless ( @header ) {
68
            # if we don't have a header yet, create it from the keys in this one. Assumes every entry has same keys
69
            # if we don't have a header yet, create it from the keys in this one. Assumes every entry has same keys
69
            @header = sort keys %{ $main::virtDB->{$virt} };
70
            @header = sort keys %{ $main::statusDB->{'virt'}->{$virt} };
70
            unshift @header, 'Node';
-
 
71
            unshift @header, 'Domain';
71
            unshift @header, 'Domain';
-
 
72
            unshift @header, 'Node';
72
         } # unless
73
         } # unless
73
         my @line;
74
         my @line;
74
         push @line, $node;
75
         push @line, $node;
75
         push @line, $virt;
76
         push @line, $virt;
76
         foreach my $column ( sort keys %{ $main::virtDB->{$virt} } ) {
77
         foreach my $column ( sort keys %{ $main::statusDB->{'virt'}->{$virt} } ) {
77
            push @line, $main::virtDB->{$virt}->{$column};
78
            push @line, $main::statusDB->{'virt'}->{$virt}->{$column};
78
         }
79
         }
79
         push @data, \@line;
80
         push @data, \@line;
80
      }
81
      }
81
   }
82
   }
82
   
83
   
83
   return &main::report( \@header, \@data );
84
   return &main::report( \@header, \@data );
84
}
85
}
85
 
86
 
86
sub update {
87
sub update {
87
   &main::loadVirtDB();
88
   &main::readDB(1); # loading it for write, so lock
88
   unless ( @_ ) {
89
   unless ( @_ ) {
89
      # they didn't pass in anything, so do everything
90
      # they didn't pass in anything, so do everything
90
      @_ = keys %{ $main::virtDB }
91
      @_ = keys %{ $main::statusDB->{'virt'} }
91
   } # unless
92
   } # unless
92
   print "Preparing to update " . join( "\n", @_ ) . "\n" if $main::DEBUG > 1;
93
   print "Preparing to update " . join( "\n", @_ ) . "\n" if $main::DEBUG > 1;
93
   while ( my $virt = shift ) {
94
   while ( my $virt = shift ) {
94
      &parseDomain( $virt );
95
      &parseDomain( $virt );
95
   } # while
96
   } # while
96
   &main::writeDB( $main::domainDBName, $main::virtDB );
97
   &main::writeDB( $main::domainDBName, $main::statusDB->{'virt'} );
97
   return "Updated\n";
98
   return "Updated\n";
98
}
99
}
99
 
100
 
100
sub getXMLValue {
101
sub getXMLValue {
101
   my ( $key, $string ) = @_;
102
   my ( $key, $string ) = @_;
Line 111... Line 112...
111
 
112
 
112
   my @keysToSave = ( 'uuid', 'memory', 'vcpu','vnc' );
113
   my @keysToSave = ( 'uuid', 'memory', 'vcpu','vnc' );
113
   my $filename = "$main::confDir/$virt.xml";
114
   my $filename = "$main::confDir/$virt.xml";
114
   my $xml = &getVirtConfig( $virt, $filename );
115
   my $xml = &getVirtConfig( $virt, $filename );
115
   my ($param,$value) = &getXMLValue( 'uuid', $xml );
116
   my ($param,$value) = &getXMLValue( 'uuid', $xml );
116
   $main::virtDB->{$virt}->{'uuid'} = $value;
117
   $main::statusDB->{'virt'}->{$virt}->{'uuid'} = $value;
117
   ($param,$value) = &getXMLValue( 'memory', $xml );
118
   ($param,$value) = &getXMLValue( 'memory', $xml );
118
   $main::virtDB->{$virt}->{'memory'} = $value;
119
   $main::statusDB->{'virt'}->{$virt}->{'memory'} = $value;
119
   ($param,$value) = &getXMLValue( 'vcpu', $xml );
120
   ($param,$value) = &getXMLValue( 'vcpu', $xml );
120
   $main::virtDB->{$virt}->{'vcpu'} = $value;
121
   $main::statusDB->{'virt'}->{$virt}->{'vcpu'} = $value;
121
 
122
 
122
   $xml =~ m/type='vnc' port='(\d+)'/;
123
   $xml =~ m/type='vnc' port='(\d+)'/;
123
   $main::virtDB->{$virt}->{'vnc'} = $1;
124
   $main::statusDB->{'virt'}->{$virt}->{'vnc'} = $1;
124
}
125
}
125
 
126
 
126
# get the XML definition file of a running domain off of whatever
127
# get the XML definition file of a running domain off of whatever
127
# node it is running on, and save it to disk
128
# node it is running on, and save it to disk
128
sub getVirtConfig {
129
sub getVirtConfig {
Line 132... Line 133...
132
   if ( -f $filename ) {
133
   if ( -f $filename ) {
133
      open XML, "<$filename" or die "Could not read from $filename: $!\n";
134
      open XML, "<$filename" or die "Could not read from $filename: $!\n";
134
      $return = join( '', <XML> );
135
      $return = join( '', <XML> );
135
      close XML;
136
      close XML;
136
   } else {
137
   } else {
137
      &main::loadNodePopulations();
138
      &main::readDB();
138
      foreach my $node ( keys %$main::nodePopulations ) {
139
      foreach my $node ( keys %{$main::statusDB->{'nodePopulation'}} ) {
139
         print "getVirtConfig Looking on $node for $virt\n" if $main::DEBUG > 1;;
140
         print "getVirtConfig Looking on $node for $virt\n" if $main::DEBUG > 1;;
140
         if ( exists( $main::nodePopulations->{$node}->{'running'}->{$virt} ) ) { # we found it
141
         if ( exists( $main::statusDB->{'nodePopulation'}->{$node}->{'running'}->{$virt} ) ) { # we found it
141
            print "Found $virt on node $node\n" if $main::DEBUG;;
142
            print "Found $virt on node $node\n" if $main::DEBUG;;
142
            $return = `ssh $node 'virsh dumpxml $virt'`;
143
            $return = `ssh $node 'virsh dumpxml $virt'`;
143
            print "Writing config for $virt from $node into $filename\n" if $main::DEBUG;
144
            print "Writing config for $virt from $node into $filename\n" if $main::DEBUG;
144
            open XML,">$filename" or die "Could not write to $filename: $!\n";
145
            open XML,">$filename" or die "Could not write to $filename: $!\n";
145
            print XML $return;
146
            print XML $return;
Line 147... Line 148...
147
         } # if
148
         } # if
148
      } # foreach
149
      } # foreach
149
   } # if..else
150
   } # if..else
150
   return $return;
151
   return $return;
151
} # sub getVirtConfig
152
} # sub getVirtConfig
-
 
153
 
-
 
154
# start a domain
-
 
155
sub start {
-
 
156
   my ( $virt, $node ) = @_;
-
 
157
   $node = `hostname` unless $node;
-
 
158
   chomp $node;
-
 
159
   &main::readDB();
-
 
160
   for my $myNode ( keys %{$main::statusDB->{'nodePopulation'} } ) {
-
 
161
      die "$virt already running on $myNode, not starting\n" if ( $main::statusDB->{'nodePopulation'}->{$myNode}->{'running'}->{$virt} );
-
 
162
   }
-
 
163
   die "I do not have a definition for $virt\n" unless exists( $main::statusDB->{'virt'}->{$virt} );
-
 
164
   print Dumper( $main::statusDB->{'nodePopulation'} ) if $main::DEBUG > 2;
-
 
165
   my $filename = "$main::confDir/$virt.xml";
-
 
166
   return "ssh $node 'virsh create $filename'\n";
-
 
167
}