Commit 62506bed authored by Daniel P. Berrange's avatar Daniel P. Berrange

Support disk encyption in domains / storage volumes

parent 719c7673
......@@ -18,7 +18,7 @@ sub new {
my $ostype = $params{ostype} ? $params{ostype} : die "ostype parameter is required";
my $self = {
name => $params{name} ? $params{name} : "test" ,
name => $params{name} ? $params{name} : "tck" ,
type => $domain,
ostype => $ostype,
boot => { type => "disk" },
......@@ -300,6 +300,10 @@ sub as_xml {
type => $disk->{type},
$disk->{device} ? (device => $disk->{device}) : ());
if ($disk->{format}) {
$w->emptyTag("driver", name => $disk->{format}->[0], type => $disk->{format}->[1]);
}
if ($disk->{type} eq "block") {
$w->emptyTag("source",
dev => $disk->{src});
......@@ -310,6 +314,11 @@ sub as_xml {
$w->emptyTag("target",
dev => $disk->{dst},
$disk->{bus} ? (bus => $disk->{bus}) : ());
if ($disk->{secret}) {
$w->startTag("encryption", format => "qcow");
$w->emptyTag("secret", type => "passphrase", uuid => $disk->{secret});
$w->endTag("encryption");
}
$w->endTag("disk");
}
foreach my $fs (@{$self->{filesystems}}) {
......
......@@ -13,7 +13,7 @@ sub new {
my %params = @_;
my $self = {
name => $params{name} ? $params{name} : "test" ,
name => $params{name} ? $params{name} : "tck" ,
};
bless $self, $class;
......
......@@ -13,7 +13,7 @@ sub new {
my %params = @_;
my $self = {
name => $params{name} ? $params{name} : "test" ,
name => $params{name} ? $params{name} : "tck" ,
type => $params{type} ? $params{type} : "dir",
source => {},
};
......
......@@ -13,7 +13,7 @@ sub new {
my %params = @_;
my $self = {
name => $params{name} ? $params{name} : "test" ,
name => $params{name} ? $params{name} : "tck" ,
};
bless $self, $class;
......@@ -47,6 +47,14 @@ sub format {
return $self;
}
sub secret {
my $self = shift;
$self->{secret} = shift;
return $self;
}
sub as_xml {
my $self = shift;
......@@ -61,9 +69,16 @@ sub as_xml {
$w->dataElement("capacity", $self->{capacity});
$w->dataElement("allocation", $self->{allocation});
if ($self->{format}) {
if ($self->{format} || $self->{secret}) {
$w->startTag("target");
$w->emptyTag("format", type => $self->{format});
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");
}
......
......@@ -9,7 +9,7 @@ BEGIN {
my $xml = <<EOF;
<domain type="xen">
<name>test</name>
<name>tck</name>
<memory>512500</memory>
<currentMemory>512500</currentMemory>
<vcpu>3</vcpu>
......@@ -22,8 +22,12 @@ my $xml = <<EOF;
</features>
<devices>
<disk type="block">
<driver name="qemu" type="qcow2" />
<source dev="/dev/hda1" />
<target dev="/dev/xvda" bus="xen" />
<encryption format="qcow">
<secret type="passphrase" uuid="0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f" />
</encryption>
</disk>
<console type="pty" />
</devices>
......@@ -35,7 +39,7 @@ my $conn = Sys::Virt->new(address => "test:///default");
my $b = Sys::Virt::TCK::DomainBuilder->new(conn => $conn, domain => "xen", ostype => 'hvm')
->with_acpi->memory(500*1025)->vcpu(3)
->disk(type => 'block', src => "/dev/hda1", dst => "/dev/xvda", bus => "xen")
->disk(format => ["qemu", "qcow2"], type => 'block', src => "/dev/hda1", dst => "/dev/xvda", bus => "xen", secret => "0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f")
->as_xml;
......
......@@ -9,7 +9,7 @@ BEGIN {
my $xml = <<EOF;
<network>
<name>test</name>
<name>tck</name>
<bridge name="virbr0" />
<forward dev="eth0" />
<ip address="192.168.100.1" netmask="255.255.255.0">
......
......@@ -11,7 +11,7 @@ BEGIN {
my $xmlDir = <<EOF;
<pool type="dir">
<name>test</name>
<name>tck</name>
<source>
<dir path="/var/lib/libvirt/images" />
</source>
......@@ -33,7 +33,7 @@ is ($builtDir, $xmlDir);
my $xmlFS = <<EOF;
<pool type="fs">
<name>test</name>
<name>tck</name>
<source>
<dev path="/dev/sda1" />
</source>
......@@ -55,7 +55,7 @@ is ($builtFS, $xmlFS);
my $xmlNetFS = <<EOF;
<pool type="netfs">
<name>test</name>
<name>tck</name>
<source>
<host name="nfs.example.com" />
<dir path="/var/lib/libvirt/images" />
......@@ -79,15 +79,15 @@ is ($builtNetFS, $xmlNetFS);
my $xmlLogical = <<EOF;
<pool type="logical">
<name>test</name>
<name>tck</name>
<source>
<dev path="/dev/sda1" />
<dev path="/dev/sdb1" />
<dev path="/dev/sdc1" />
<name>test</name>
<name>tck</name>
</source>
<target>
<path>/dev/test</path>
<path>/dev/tck</path>
</target>
</pool>
EOF
......@@ -95,8 +95,8 @@ chomp $xmlLogical;
my $builtLogical = Sys::Virt::TCK::StoragePoolBuilder->new(type => "logical")
->source_device("/dev/sda1", "/dev/sdb1", "/dev/sdc1")
->source_name("test")
->target("/dev/test")
->source_name("tck")
->target("/dev/tck")
->as_xml;
......@@ -105,7 +105,7 @@ is ($builtLogical, $xmlLogical);
my $xmlDisk = <<EOF;
<pool type="disk">
<name>test</name>
<name>tck</name>
<source>
<dev path="/dev/sda" />
</source>
......@@ -127,7 +127,7 @@ is ($builtDisk, $xmlDisk);
my $xmlSCSI = <<EOF;
<pool type="scsi">
<name>test</name>
<name>tck</name>
<source>
<adapter name="scsi1" />
</source>
......@@ -149,10 +149,10 @@ is ($builtSCSI, $xmlSCSI);
my $xmlISCSI = <<EOF;
<pool type="iscsi">
<name>test</name>
<name>tck</name>
<source>
<host name="iscsi.example.com" />
<dev path="test.target" />
<dev path="tck.target" />
</source>
<target>
<path>/dev</path>
......@@ -163,7 +163,7 @@ chomp $xmlISCSI;
my $builtISCSI = Sys::Virt::TCK::StoragePoolBuilder->new(type => "iscsi")
->source_host("iscsi.example.com")
->source_device("test.target")
->source_device("tck.target")
->target("/dev")
->as_xml;
......
......@@ -9,11 +9,14 @@ BEGIN {
my $xml = <<EOF;
<volume>
<name>test</name>
<name>tck</name>
<capacity>1000000</capacity>
<allocation>1000000</allocation>
<target>
<format type="qcow2" />
<encryption format="qcow">
<secret type="passphrase" uuid="0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f" />
</encryption>
</target>
</volume>
EOF
......@@ -22,6 +25,7 @@ chomp $xml;
my $b = Sys::Virt::TCK::StorageVolBuilder->new()
->capacity(1000000)->allocation(1000000)
->format("qcow2")
->secret("0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f")
->as_xml;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment