| 1 |
# -*- perl -*- |
| 2 |
# |
| 3 |
# Copyright (C) 2019 Red Hat |
| 4 |
# |
| 5 |
# This program is free software; You can redistribute it and/or modify |
| 6 |
# it under either: |
| 7 |
# |
| 8 |
# a) the GNU General Public License as published by the Free |
| 9 |
# Software Foundation; either version 2, or (at your option) any |
| 10 |
# later version, |
| 11 |
# |
| 12 |
# or |
| 13 |
# |
| 14 |
# b) the "Artistic License" |
| 15 |
# |
| 16 |
# The file "LICENSE" distributed along with this file provides full |
| 17 |
# details of the terms and conditions of the two licenses. |
| 18 |
|
| 19 |
=pod |
| 20 |
|
| 21 |
=head1 NAME |
| 22 |
|
| 23 |
Sys::Virt::NetworkPort - Represent & manage a libvirt virtual network port |
| 24 |
|
| 25 |
=head1 DESCRIPTION |
| 26 |
|
| 27 |
The C<Sys::Virt::NetworkPort> module represents a port in a virtual network. |
| 28 |
|
| 29 |
=head1 METHODS |
| 30 |
|
| 31 |
=over 4 |
| 32 |
|
| 33 |
=cut |
| 34 |
|
| 35 |
package Sys::Virt::NetworkPort; |
| 36 |
|
| 37 |
use strict; |
| 38 |
use warnings; |
| 39 |
|
| 40 |
|
| 41 |
sub _new { |
| 42 |
my $proto = shift; |
| 43 |
my $class = ref($proto) || $proto; |
| 44 |
my %params = @_; |
| 45 |
|
| 46 |
my $net = exists $params{network} ? $params{network} : die "network parameter is required"; |
| 47 |
my $self; |
| 48 |
if (exists $params{uuid}) { |
| 49 |
if (length($params{uuid}) == 16) { |
| 50 |
$self = Sys::Virt::NetworkPort::_lookup_by_uuid($net, $params{uuid}); |
| 51 |
} elsif (length($params{uuid}) == 32 || |
| 52 |
length($params{uuid}) == 36) { |
| 53 |
$self = Sys::Virt::NetworkPort::_lookup_by_uuid_string($net, $params{uuid}); |
| 54 |
} else { |
| 55 |
die "UUID must be either 16 unsigned bytes, or 32/36 hex characters long"; |
| 56 |
} |
| 57 |
} elsif (exists $params{xml}) { |
| 58 |
my $flags = $params{flags} || 0; |
| 59 |
$self = Sys::Virt::NetworkPort::_create_xml($net, $params{xml}, $flags); |
| 60 |
} else { |
| 61 |
die "uuid or xml parameters are required"; |
| 62 |
} |
| 63 |
|
| 64 |
bless $self, $class; |
| 65 |
|
| 66 |
return $self; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
=item my $uuid = $port->get_uuid() |
| 71 |
|
| 72 |
Returns a 16 byte long string containing the raw globally unique identifier |
| 73 |
(UUID) for the network port. |
| 74 |
|
| 75 |
=item my $uuid = $port->get_uuid_string() |
| 76 |
|
| 77 |
Returns a printable string representation of the raw UUID, in the format |
| 78 |
'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'. |
| 79 |
|
| 80 |
=item my $xml = $port->get_xml_description() |
| 81 |
|
| 82 |
Returns an XML document containing a complete description of |
| 83 |
the network port's configuration |
| 84 |
|
| 85 |
=item $port->delete() |
| 86 |
|
| 87 |
Delete the network port from the managed network. |
| 88 |
|
| 89 |
=item my $params = $port->get_parameters($flags=0); |
| 90 |
|
| 91 |
Get tunable parameters associated with the network port. The C<$flags> |
| 92 |
parameter is currently unused and defaults to zero. The returned |
| 93 |
C<$params> is a hash reference whose keys are one or more of the |
| 94 |
following constants: |
| 95 |
|
| 96 |
=over 4 |
| 97 |
|
| 98 |
=item Sys::Virt::NetworkPort::BANDWIDTH_IN_AVERAGE |
| 99 |
|
| 100 |
The average inbound bandwidth |
| 101 |
|
| 102 |
=item Sys::Virt::NetworkPort::BANDWIDTH_IN_BURST |
| 103 |
|
| 104 |
The burstable inbound bandwidth |
| 105 |
|
| 106 |
=item Sys::Virt::NetworkPort::BANDWIDTH_IN_FLOOR |
| 107 |
|
| 108 |
The minimum inbound bandwidth |
| 109 |
|
| 110 |
=item Sys::Virt::NetworkPort::BANDWIDTH_IN_PEAK |
| 111 |
|
| 112 |
The peak inbound bandwidth |
| 113 |
|
| 114 |
=item Sys::Virt::NetworkPort::BANDWIDTH_OUT_AVERAGE |
| 115 |
|
| 116 |
The average outbound bandwidth |
| 117 |
|
| 118 |
=item Sys::Virt::NetworkPort::BANDWIDTH_OUT_BURST |
| 119 |
|
| 120 |
The burstable outbound bandwidth |
| 121 |
|
| 122 |
=item Sys::Virt::NetworkPort::BANDWIDTH_OUT_PEAK |
| 123 |
|
| 124 |
The peak outbound bandwidth |
| 125 |
|
| 126 |
=back |
| 127 |
|
| 128 |
=item $port->set_parameters($params, $flags=0); |
| 129 |
|
| 130 |
Set tunable parameters associated with the network port. The C<$flags> |
| 131 |
parameter is currently unused and defaults to zero. The C<$params> |
| 132 |
parameter is a hash reference whose keys are one or more of the |
| 133 |
constants listed for C<get_parameters>. |
| 134 |
|
| 135 |
=back |
| 136 |
|
| 137 |
=head2 NETWORK PORT CREATION CONSTANTS |
| 138 |
|
| 139 |
When creating network ports zero or more of the following |
| 140 |
constants may be used |
| 141 |
|
| 142 |
=over 4 |
| 143 |
|
| 144 |
=item Sys::Virt::NetworkPort::CREATE_RECLAIM |
| 145 |
|
| 146 |
Providing configuration reclaiming a pre-existing network port. |
| 147 |
|
| 148 |
=item Sys::Virt::NetworkPort::CREATE_VALIDATE |
| 149 |
|
| 150 |
Validate the XML document against the XML schema |
| 151 |
|
| 152 |
=back |
| 153 |
|
| 154 |
|
| 155 |
=cut |
| 156 |
|
| 157 |
|
| 158 |
1; |
| 159 |
|
| 160 |
|
| 161 |
=head1 AUTHORS |
| 162 |
|
| 163 |
Daniel P. Berrange <[email protected]> |
| 164 |
|
| 165 |
=head1 COPYRIGHT |
| 166 |
|
| 167 |
Copyright (C) 2019 Red Hat |
| 168 |
|
| 169 |
=head1 LICENSE |
| 170 |
|
| 171 |
This program is free software; you can redistribute it and/or modify |
| 172 |
it under the terms of either the GNU General Public License as published |
| 173 |
by the Free Software Foundation (either version 2 of the License, or at |
| 174 |
your option any later version), or, the Artistic License, as specified |
| 175 |
in the Perl README file. |
| 176 |
|
| 177 |
=head1 SEE ALSO |
| 178 |
|
| 179 |
L<Sys::Virt>, L<Sys::Virt::Network>, L<Sys::Virt::Error>, C<http://libvirt.org> |
| 180 |
|
| 181 |
=cut |