File: StorageVolBuilder.pm

package info (click to toggle)
libvirt-tck 0.1.0~2.git890d1c-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,128 kB
  • sloc: perl: 2,885; sh: 1,180; xml: 992; makefile: 6
file content (130 lines) | stat: -rw-r--r-- 2,521 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#
# Copyright (C) 2009, 2010 Red Hat, Inc.
# Copyright (C) 2009 Daniel P. Berrange
#
# This program is free software; You can redistribute it and/or modify
# it under the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any
# later version
#
# The file "LICENSE" distributed along with this file provides full
# details of the terms and conditions
#

package Sys::Virt::TCK::StorageVolBuilder;

use strict;
use warnings;
use Sys::Virt;

use IO::String;
use XML::Writer;

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my %params = @_;

    my $self = {
	name => $params{name} ? $params{name} : "tck" ,
    };

    bless $self, $class;

    return $self;
}

sub capacity {
    my $self = shift;

    $self->{capacity} = shift;

    return $self;
}


sub allocation {
    my $self = shift;

    $self->{allocation} = shift;

    return $self;
}


sub format {
    my $self = shift;

    $self->{format} = shift;

    return $self;
}

sub secret {
    my $self = shift;

    $self->{secret} = shift;

    return $self;
}

sub backing_format {
    my $self = shift;
    $self->{backingFormat} = shift;
    return $self;
}

sub backing_file {
    my $self = shift;
    $self->{backingFile} = shift;
    return $self;
}


sub as_xml {
    my $self = shift;

    my $data;
    my $fh = IO::String->new(\$data);
    my $w = XML::Writer->new(OUTPUT => $fh,
			     DATA_MODE => 1,
			     DATA_INDENT => 2);
    $w->startTag("volume");
    $w->dataElement("name" => $self->{name});

    $w->dataElement("capacity", $self->{capacity});
    $w->dataElement("allocation", $self->{allocation});

    if ($self->{format} || $self->{secret}) {
	$w->startTag("target");
	if ($self->{format}) {
	    $w->emptyTag("format", type => $self->{format});
	}
	if ($self->{secret}) {
	    $w->startTag("encryption", format => "qcow");
	    $w->emptyTag("secret", type => "passphrase", uuid => $self->{secret});
	    $w->endTag("encryption");
	}
	$w->endTag("target");
    }

    if ($self->{backingFile}) {
	$w->startTag("backingStore");
	$w->dataElement("path", $self->{backingFile});
	if ($self->{backingFormat}) {
	    $w->emptyTag("format", type => $self->{backingFormat});
	}
	if ($self->{secret}) {
	    $w->startTag("encryption", format => "qcow");
	    $w->emptyTag("secret", type => "passphrase", uuid => $self->{secret});
	    $w->endTag("encryption");
	}
	$w->endTag("backingStore");
    }

    $w->endTag("volume");

    return $data;
}

1;