| 1 |
# -*- perl -*- |
| 2 |
# |
| 3 |
# Copyright (C) 2006-2009 Red Hat |
| 4 |
# Copyright (C) 2006-2009 Daniel P. Berrange |
| 5 |
# |
| 6 |
# This program is free software; You can redistribute it and/or modify |
| 7 |
# it under either: |
| 8 |
# |
| 9 |
# a) the GNU General Public License as published by the Free |
| 10 |
# Software Foundation; either version 2, or (at your option) any |
| 11 |
# later version, |
| 12 |
# |
| 13 |
# or |
| 14 |
# |
| 15 |
# b) the "Artistic License" |
| 16 |
# |
| 17 |
# The file "LICENSE" distributed along with this file provides full |
| 18 |
# details of the terms and conditions of the two licenses. |
| 19 |
|
| 20 |
=pod |
| 21 |
|
| 22 |
=head1 NAME |
| 23 |
|
| 24 |
Sys::Virt::NodeDevice - Represent & manage a libvirt storage pool |
| 25 |
|
| 26 |
=head1 DESCRIPTION |
| 27 |
|
| 28 |
The C<Sys::Virt::NodeDevice> module represents a storage pool managed |
| 29 |
by libvirt. There are a variety of storage pool implementations for |
| 30 |
LVM, Local directories/filesystems, network filesystems, disk |
| 31 |
partitioning, iSCSI, and SCSI. |
| 32 |
|
| 33 |
=head1 METHODS |
| 34 |
|
| 35 |
=over 4 |
| 36 |
|
| 37 |
=cut |
| 38 |
|
| 39 |
package Sys::Virt::NodeDevice; |
| 40 |
|
| 41 |
use strict; |
| 42 |
use warnings; |
| 43 |
|
| 44 |
|
| 45 |
sub _new { |
| 46 |
my $proto = shift; |
| 47 |
my $class = ref($proto) || $proto; |
| 48 |
my %params = @_; |
| 49 |
|
| 50 |
my $con = exists $params{connection} ? $params{connection} : die "connection parameter is required"; |
| 51 |
my $self; |
| 52 |
if (exists $params{name}) { |
| 53 |
$self = Sys::Virt::NodeDevice::_lookup_by_name($con, $params{name}); |
| 54 |
} elsif (exists $params{wwnn}) { |
| 55 |
$self = Sys::Virt::NodeDevice::_lookup_scsihost_by_wwn($con, |
| 56 |
$params{wwnn}, |
| 57 |
$params{wwpn}, |
| 58 |
$params{flags}); |
| 59 |
} elsif (exists $params{xml}) { |
| 60 |
if ($params{nocreate}) { |
| 61 |
$self = Sys::Virt::NodeDevice::_define_xml($con, $params{xml}, $params{flags}); |
| 62 |
} else { |
| 63 |
$self = Sys::Virt::NodeDevice::_create_xml($con, $params{xml}, $params{flags}); |
| 64 |
} |
| 65 |
} else { |
| 66 |
die "name parameter is required"; |
| 67 |
} |
| 68 |
|
| 69 |
bless $self, $class; |
| 70 |
|
| 71 |
return $self; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
=item my $name = $dev->get_name() |
| 76 |
|
| 77 |
Returns a string with a locally unique name of the device |
| 78 |
|
| 79 |
=item my $parentname = $dev->get_parent() |
| 80 |
|
| 81 |
Returns a string with a locally unique name of the parent |
| 82 |
of the device, or undef if there is no parent |
| 83 |
|
| 84 |
=item my $xml = $dev->get_xml_description($flags=0) |
| 85 |
|
| 86 |
Returns an XML document containing a complete description of the node |
| 87 |
device's configuration. The optional $flags parameter controls |
| 88 |
generation of the XML document, defaulting to 0 if omitted. It can be |
| 89 |
one or more of the XML DUMP constants listed later in this document. |
| 90 |
|
| 91 |
=item $dev->reattach() |
| 92 |
|
| 93 |
Rebind the node device to the host OS device drivers. |
| 94 |
|
| 95 |
=item $dev->dettach() |
| 96 |
|
| 97 |
Unbind the node device from the host OS device driver |
| 98 |
|
| 99 |
=item $dev->reset() |
| 100 |
|
| 101 |
Reset the node device. The device must be unbound from the host |
| 102 |
OS drivers for this to work |
| 103 |
|
| 104 |
=item $dev->create($flags=0) |
| 105 |
|
| 106 |
Start a node device whose configuration was previously defined using the |
| 107 |
C<define_node_device> method in L<Sys::Virt>. The C<$flags> parameter is |
| 108 |
currently unused and defaults to zero. |
| 109 |
|
| 110 |
=item $dev->undefine($flags=0) |
| 111 |
|
| 112 |
Delete a node device whose configuration was previously defined using the |
| 113 |
C<define_node_device> method in L<Sys::Virt>. The C<$flags> parameter is |
| 114 |
currently unused and defaults to zero. |
| 115 |
|
| 116 |
=item $flag = $dev->get_autostart(); |
| 117 |
|
| 118 |
Return a true value if the node device is configured to automatically |
| 119 |
start upon boot. Return false, otherwise |
| 120 |
|
| 121 |
=item $dev->set_autostart($flag) |
| 122 |
|
| 123 |
Set the state of the autostart flag, which determines whether the |
| 124 |
node device will automatically start upon boot of the host OS. |
| 125 |
|
| 126 |
=item $dev->is_active() |
| 127 |
|
| 128 |
Returns a true value if the node device is currently running |
| 129 |
|
| 130 |
=item $dev->is_persistent() |
| 131 |
|
| 132 |
Returns a true value if the node device has a persistent configuration |
| 133 |
file defined |
| 134 |
|
| 135 |
=item $dev->destroy() |
| 136 |
|
| 137 |
Destroy the virtual device releasing any OS resources associated |
| 138 |
with it. |
| 139 |
|
| 140 |
=item my @caps = $dev->list_capabilities() |
| 141 |
|
| 142 |
Return a list of all capabilities in the device. |
| 143 |
|
| 144 |
=item $dev->update($xml, $flags=0) |
| 145 |
|
| 146 |
Update the definition of an existing node device with C<$xml>. The |
| 147 |
C<$flags> parameter can be use to control which config is affected |
| 148 |
(see XML UPDATE FLAGS) and defaults to zero (affect current state of |
| 149 |
the node device). |
| 150 |
|
| 151 |
=back |
| 152 |
|
| 153 |
=head1 CONSTANTS |
| 154 |
|
| 155 |
This section documents constants that are used with various |
| 156 |
APIs described above |
| 157 |
|
| 158 |
=head2 LIST FILTERING |
| 159 |
|
| 160 |
The following constants are used to filter object lists |
| 161 |
|
| 162 |
=over 4 |
| 163 |
|
| 164 |
=item Sys::Virt::NodeDevice::LIST_CAP_NET |
| 165 |
|
| 166 |
Include devices with the network capability |
| 167 |
|
| 168 |
=item Sys::Virt::NodeDevice::LIST_CAP_PCI_DEV |
| 169 |
|
| 170 |
Include devices with the PCI device capability |
| 171 |
|
| 172 |
=item Sys::Virt::NodeDevice::LIST_CAP_SCSI |
| 173 |
|
| 174 |
Include devices with the SCSI capability |
| 175 |
|
| 176 |
=item Sys::Virt::NodeDevice::LIST_CAP_SCSI_HOST |
| 177 |
|
| 178 |
Include devices with the SCSI host capability |
| 179 |
|
| 180 |
=item Sys::Virt::NodeDevice::LIST_CAP_SCSI_TARGET |
| 181 |
|
| 182 |
Include devices with the SCSI target capability |
| 183 |
|
| 184 |
=item Sys::Virt::NodeDevice::LIST_CAP_STORAGE |
| 185 |
|
| 186 |
Include devices with the storage capability |
| 187 |
|
| 188 |
=item Sys::Virt::NodeDevice::LIST_CAP_SYSTEM |
| 189 |
|
| 190 |
Include devices with the system capability |
| 191 |
|
| 192 |
=item Sys::Virt::NodeDevice::LIST_CAP_USB_DEV |
| 193 |
|
| 194 |
Include devices with the USB device capability |
| 195 |
|
| 196 |
=item Sys::Virt::NodeDevice::LIST_CAP_USB_INTERFACE |
| 197 |
|
| 198 |
Include devices with the USB interface capability |
| 199 |
|
| 200 |
=item Sys::Virt::NodeDevice::LIST_CAP_FC_HOST |
| 201 |
|
| 202 |
Include devices with the fibre channel host capability |
| 203 |
|
| 204 |
=item Sys::Virt::NodeDevice::LIST_CAP_VPORTS |
| 205 |
|
| 206 |
Include devices with the NPIV vport capability |
| 207 |
|
| 208 |
=item Sys::Virt::NodeDevice::LIST_CAP_SCSI_GENERIC |
| 209 |
|
| 210 |
Include devices with the SCSI generic capability |
| 211 |
|
| 212 |
=item Sys::Virt::NodeDevice::LIST_CAP_DRM |
| 213 |
|
| 214 |
Include devices with the DRM capability |
| 215 |
|
| 216 |
=item Sys::Virt::NodeDevice::LIST_CAP_MDEV |
| 217 |
|
| 218 |
Include mediated devices |
| 219 |
|
| 220 |
=item Sys::Virt::NodeDevice::LIST_CAP_MDEV_TYPES |
| 221 |
|
| 222 |
Include devices capable of mediated devices |
| 223 |
|
| 224 |
=item Sys::Virt::NodeDevice::LIST_CAP_CCW_DEV |
| 225 |
|
| 226 |
Include CCW devices |
| 227 |
|
| 228 |
=item Sys::Virt::NodeDevice::LIST_CAP_CSS_DEV |
| 229 |
|
| 230 |
Include CSS devices |
| 231 |
|
| 232 |
=item Sys::Virt::NodeDevice::LIST_CAP_VDPA |
| 233 |
|
| 234 |
Include VDPA devices |
| 235 |
|
| 236 |
=item Sys::Virt::NodeDevice::LIST_CAP_AP_CARD |
| 237 |
|
| 238 |
Include s390 AP card devices |
| 239 |
|
| 240 |
=item Sys::Virt::NodeDevice::LIST_CAP_AP_MATRIX |
| 241 |
|
| 242 |
Include s390 AP matrix devices |
| 243 |
|
| 244 |
=item Sys::Virt::NodeDevice::LIST_CAP_AP_QUEUE |
| 245 |
|
| 246 |
Include s390 AP queue devices |
| 247 |
|
| 248 |
=item Sys::Virt::NodeDevice::LIST_CAP_VPD |
| 249 |
|
| 250 |
Include PCI devices with VPD |
| 251 |
|
| 252 |
=item Sys::Virt::NodeDevice::LIST_CAP_CCWGROUP_DEV |
| 253 |
|
| 254 |
Include s390 CCW group devices |
| 255 |
|
| 256 |
=item Sys::Virt::NodeDevice::LIST_CAP_CCWGROUP_MEMBER |
| 257 |
|
| 258 |
Include s390 CCW group members |
| 259 |
|
| 260 |
=item Sys::Virt::NodeDevice::LIST_ACTIVE |
| 261 |
|
| 262 |
Include active devices |
| 263 |
|
| 264 |
=item Sys::Virt::NodeDevice::LIST_INACTIVE |
| 265 |
|
| 266 |
Include inactive devices |
| 267 |
|
| 268 |
=item Sys::Virt::NodeDevice::LIST_PERSISTENT |
| 269 |
|
| 270 |
Include persistent devices |
| 271 |
|
| 272 |
=item Sys::Virt::NodeDevice::LIST_TRANSIENT |
| 273 |
|
| 274 |
Include transient devices |
| 275 |
|
| 276 |
=back |
| 277 |
|
| 278 |
=head2 EVENT ID CONSTANTS |
| 279 |
|
| 280 |
=over 4 |
| 281 |
|
| 282 |
=item Sys::Virt::NodeDevice::EVENT_ID_LIFECYCLE |
| 283 |
|
| 284 |
Node device lifecycle events |
| 285 |
|
| 286 |
=item Sys::Virt::NodeDevice::EVENT_ID_UPDATE |
| 287 |
|
| 288 |
Node device config update events |
| 289 |
|
| 290 |
=back |
| 291 |
|
| 292 |
=head2 LIFECYCLE CHANGE EVENTS |
| 293 |
|
| 294 |
The following constants allow node device lifecycle change events to be |
| 295 |
interpreted. The events contain both a state change, and a |
| 296 |
reason though the reason is currently unused. |
| 297 |
|
| 298 |
=over 4 |
| 299 |
|
| 300 |
=item Sys::Virt::NodeDevice::EVENT_CREATED |
| 301 |
|
| 302 |
Indicates that a device was created |
| 303 |
|
| 304 |
=item Sys::Virt::NodeDevice::EVENT_DELETED |
| 305 |
|
| 306 |
Indicates that a device has been deleted |
| 307 |
|
| 308 |
=item Sys::Virt::NodeDevice::EVENT_DEFINED |
| 309 |
|
| 310 |
Indicates that a device configuration has been created |
| 311 |
|
| 312 |
=item Sys::Virt::NodeDevice::EVENT_UNDEFINED |
| 313 |
|
| 314 |
Indicates that a device configuration has been deleted |
| 315 |
|
| 316 |
=back |
| 317 |
|
| 318 |
=head2 NODE DEVICE CREATION |
| 319 |
|
| 320 |
=over 4 |
| 321 |
|
| 322 |
=item Sys::Virt::NodeDevice::CREATE_XML_VALIDATE |
| 323 |
|
| 324 |
Validate the XML document against schema |
| 325 |
|
| 326 |
=back |
| 327 |
|
| 328 |
=head2 NODE DEVICE DEFINE |
| 329 |
|
| 330 |
=over 4 |
| 331 |
|
| 332 |
=item Sys::Virt::NodeDevice::DEFINE_XML_VALIDATE |
| 333 |
|
| 334 |
Validate the XML document against schema |
| 335 |
|
| 336 |
=back |
| 337 |
|
| 338 |
=head2 NODE DEVICE UPDATE |
| 339 |
|
| 340 |
=over 4 |
| 341 |
|
| 342 |
=item Sys::Virt::NodeDevice::UPDATE_AFFECT_CURRENT |
| 343 |
|
| 344 |
Affect live if node device is active, config if it's not active |
| 345 |
|
| 346 |
=item Sys::Virt::NodeDevice::UPDATE_AFFECT_LIVE |
| 347 |
|
| 348 |
Affect live state of node device only |
| 349 |
|
| 350 |
=item Sys::Virt::NodeDevice::UPDATE_AFFECT_CONFIG |
| 351 |
|
| 352 |
Affect persistent config only |
| 353 |
|
| 354 |
=back |
| 355 |
|
| 356 |
=head2 XML DUMP OPTIONS |
| 357 |
|
| 358 |
The following constants are used to control the information |
| 359 |
included in the XML configuration dump |
| 360 |
|
| 361 |
=over 4 |
| 362 |
|
| 363 |
=item Sys::Virt::NodeDevice::XML_INACTIVE |
| 364 |
|
| 365 |
Report the persistent inactive configuration for the node device. |
| 366 |
|
| 367 |
=back |
| 368 |
|
| 369 |
=cut |
| 370 |
|
| 371 |
|
| 372 |
1; |
| 373 |
|
| 374 |
=head1 AUTHORS |
| 375 |
|
| 376 |
Daniel P. Berrange <[email protected]> |
| 377 |
|
| 378 |
=head1 COPYRIGHT |
| 379 |
|
| 380 |
Copyright (C) 2006-2009 Red Hat |
| 381 |
Copyright (C) 2006-2009 Daniel P. Berrange |
| 382 |
|
| 383 |
=head1 LICENSE |
| 384 |
|
| 385 |
This program is free software; you can redistribute it and/or modify |
| 386 |
it under the terms of either the GNU General Public License as published |
| 387 |
by the Free Software Foundation (either version 2 of the License, or at |
| 388 |
your option any later version), or, the Artistic License, as specified |
| 389 |
in the Perl README file. |
| 390 |
|
| 391 |
=head1 SEE ALSO |
| 392 |
|
| 393 |
L<Sys::Virt>, L<Sys::Virt::Error>, C<http://libvirt.org> |
| 394 |
|
| 395 |
=cut |