Debian Codegraph @

lib/Sys/Virt/Interface.pm

raw
1 # -*- perl -*-
2 #
3 # Copyright (C) 2006-2009 Red Hat
4 # Copyright (C) 2006-2007 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::Interface - Represent & manage a libvirt host network interface
25
26 =head1 DESCRIPTION
27
28 The C<Sys::Virt::Interface> module represents a host network interface
29 allowing configuration of IP addresses, bonding, vlans and bridges.
30
31 =head1 METHODS
32
33 =over 4
34
35 =cut
36
37 package Sys::Virt::Interface;
38
39 use strict;
40 use warnings;
41
42
43 sub _new {
44 my $proto = shift;
45 my $class = ref($proto) || $proto;
46 my %params = @_;
47
48 my $con = exists $params{connection} ? $params{connection} : die "connection parameter is required";
49 my $self;
50 if (exists $params{name}) {
51 $self = Sys::Virt::Interface::_lookup_by_name($con, $params{name});
52 } elsif (exists $params{mac}) {
53 $self = Sys::Virt::Interface::_lookup_by_mac($con, $params{mac});
54 } elsif (exists $params{xml}) {
55 $self = Sys::Virt::Interface::_define_xml($con, $params{xml}, $params{flags});
56 } else {
57 die "name, mac or xml parameters are required";
58 }
59
60 bless $self, $class;
61
62 return $self;
63 }
64
65
66 =item my $name = $iface->get_name()
67
68 Returns a string with a locally unique name of the network
69
70 =item $iface->is_active()
71
72 Returns a true value if the interface is currently running
73
74 =item my $name = $iface->get_mac()
75
76 Returns a string with the hardware MAC address of the interface
77
78 =item my $xml = $iface->get_xml_description()
79
80 Returns an XML document containing a complete description of
81 the network's configuration
82
83 =item $iface->create()
84
85 Start a network whose configuration was previously defined using the
86 C<define_network> method in L<Sys::Virt>.
87
88 =item $iface->undefine()
89
90 Remove the configuration associated with a network previously defined
91 with the C<define_network> method in L<Sys::Virt>. If the network is
92 running, you probably want to use the C<shutdown> or C<destroy>
93 methods instead.
94
95 =item $iface->destroy()
96
97 Immediately terminate the machine, and remove it from the virtual
98 machine monitor. The C<$iface> handle is invalid after this call
99 completes and should not be used again.
100
101 =back
102
103 =head1 CONSTANTS
104
105 This section documents constants that are used with various
106 APIs described above
107
108 =head2 LIST FILTERING
109
110 The following constants are used to filter object lists
111
112 =over 4
113
114 =item Sys::Virt::Interface::LIST_ACTIVE
115
116 Include interfaces that are active
117
118 =item Sys::Virt::Interface::LIST_INACTIVE
119
120 Include interfaces that are not active
121
122 =back
123
124 =head2 INTERFACE DEFINE
125
126 The following constants can be used to control the behaviour
127 of interface define operations
128
129 =over 4
130
131 =item Sys::Virt::Interface::DEFINE_VALIDATE
132
133 Validate the XML document against the XML schema
134
135 =back
136
137 =head2 XML CONSTANTS
138
139 The following constants are used when querying XML
140
141 =over 4
142
143 =item Sys::Virt::Interface::XML_INACTIVE
144
145 Request the inactive XML, instead of the current possibly live config.
146
147 =back
148
149 =cut
150
151 1;
152
153 =head1 AUTHORS
154
155 Daniel P. Berrange <[email protected]>
156
157 =head1 COPYRIGHT
158
159 Copyright (C) 2006-2009 Red Hat
160 Copyright (C) 2006-2007 Daniel P. Berrange
161
162 =head1 LICENSE
163
164 This program is free software; you can redistribute it and/or modify
165 it under the terms of either the GNU General Public License as published
166 by the Free Software Foundation (either version 2 of the License, or at
167 your option any later version), or, the Artistic License, as specified
168 in the Perl README file.
169
170 =head1 SEE ALSO
171
172 L<Sys::Virt>, L<Sys::Virt::Error>, C<http://libvirt.org>
173
174 =cut