File: XL.pm

package info (click to toggle)
ocsinventory-agent 2%3A2.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,424 kB
  • sloc: perl: 26,492; xml: 773; objc: 528; sh: 386; ansic: 333; makefile: 12
file content (84 lines) | stat: -rw-r--r-- 2,203 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package Ocsinventory::Agent::Backend::Virtualization::Xen::XL;

use strict;

sub check { 

    my $params = shift;
    my $common = $params->{common};
    my $can_run = $common->can_run('xl');
    if ($can_run) {
        system('xl list');
        my $exit_val = $? >> 8;
        return $exit_val eq 0;
    }
    return $can_run;
}

sub run {
    my $params = shift;
    my $common = $params->{common};

    # output: xm list
    #
    #    Name                         ID Mem(MiB) VCPUs State  Time(s)
    #    Domain-0                      0       98     1 r-----  5068.6
    #    Fedora3                     164      128     1 r-----     7.6
    #    Fedora4                     165      128     1 ------     0.6
    #    Mandrake2006                166      128     1 -b----     3.6
    #    Mandrake10.2                167      128     1 ------     2.5
    #    Suse9.2                     168      100     1 ------     1.8

    # xl status
    my %status_list = (
        'r' => 'running',
        'b' => 'blocked',
        'p' => 'paused',
        's' => 'shutdown',
        'c' => 'crashed',
        'd' => 'dying',
    );

    my $vmtype    = 'xen';
    my $subsystem = 'xl';

    my @xl_list = `xl list`;

    # remove first line
    shift @xl_list;

    foreach my $vm (@xl_list) {
        chomp $vm;
        my ($name, $vmid, $memory, $vcpu, $status, $time) = split(' ',$vm);

        $status =~ s/-//g;
        $status = ( $status ? $status_list{$status} : 'off');

        my @vm_info =  `xl list -l $name`;
        my $uuid;
            foreach my $value (@vm_info) {
            chomp $value;
            if ($value =~ /uuid/) {
                $value =~ s/"//g;
                $value =~ s/,//g;
                $value =~ s/\s+.*uuid:\s+(.*)/\1/;
                $uuid = $value;
                last;
            }
        }

        my $machine = {
            MEMORY    => $memory,
            NAME      => $name,
            UUID      => $uuid,
            STATUS    => $status,
            SUBSYSTEM => $subsystem,
            VMTYPE    => $vmtype,
            VCPU      => $vcpu,
            VMID      => $vmid,
        };
        $common->addVirtualMachine($machine);
    }
}

1;