network.c 21 KB
Newer Older
1 2 3 4
/*
 * network.c: virNetwork methods
 *
 * Copyright (C) 2007,2010 Red Hat Inc.
Chris Lalancette's avatar
Chris Lalancette committed
5
 * Copyright (C) 2013-2016 Chris Lalancette <[email protected]>
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
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 */

#include <ruby.h>
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include "common.h"
#include "connect.h"
#include "extconf.h"

#if HAVE_TYPE_VIRNETWORKPTR
static VALUE c_network;

32 33
static void network_free(void *d)
{
34
    ruby_libvirt_free_struct(Network, d);
35 36
}

Chris Lalancette's avatar
Chris Lalancette committed
37
static virNetworkPtr network_get(VALUE n)
38
{
39
    ruby_libvirt_get_struct(Network, n);
40 41
}

42
VALUE ruby_libvirt_network_new(virNetworkPtr n, VALUE conn)
43
{
44
    return ruby_libvirt_new_class(c_network, n, conn, network_free);
45 46 47 48 49 50
}

/*
 * call-seq:
 *   net.undefine -> nil
 *
51
 * Call virNetworkUndefine[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkUndefine]
52
 * to undefine this network.
53
 */
54
static VALUE libvirt_network_undefine(VALUE n)
55
{
56 57 58
    ruby_libvirt_generate_call_nil(virNetworkUndefine,
                                   ruby_libvirt_connect_get(n),
                                   network_get(n));
59 60 61 62 63 64
}

/*
 * call-seq:
 *   net.create -> nil
 *
65
 * Call virNetworkCreate[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreate]
66
 * to start this network.
67
 */
68
static VALUE libvirt_network_create(VALUE n)
69
{
70 71 72
    ruby_libvirt_generate_call_nil(virNetworkCreate,
                                   ruby_libvirt_connect_get(n),
                                   network_get(n));
73 74
}

75
#if HAVE_VIRNETWORKUPDATE
Hiroshi Miura's avatar
Hiroshi Miura committed
76 77 78 79
/*
 * call-seq:
 *   net.update -> nil
 *
80
 * Call virNetworkUpdate[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkUpdate]
Hiroshi Miura's avatar
Hiroshi Miura committed
81 82
 * to update this network.
 */
83 84
static VALUE libvirt_network_update(VALUE n, VALUE command, VALUE section,
                                    VALUE index, VALUE xml, VALUE flags)
85
{
86 87 88 89 90
    ruby_libvirt_generate_call_nil(virNetworkUpdate,
                                   ruby_libvirt_connect_get(n),
                                   network_get(n), NUM2UINT(command),
                                   NUM2UINT(section), NUM2INT(index),
                                   StringValuePtr(xml), NUM2UINT(flags));
Hiroshi Miura's avatar
Hiroshi Miura committed
91
}
92 93
#endif

94 95 96 97
/*
 * call-seq:
 *   net.destroy -> nil
 *
98
 * Call virNetworkDestroy[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkDestroy]
99
 * to shutdown this network.
100
 */
101
static VALUE libvirt_network_destroy(VALUE n)
102
{
103 104 105
    ruby_libvirt_generate_call_nil(virNetworkDestroy,
                                   ruby_libvirt_connect_get(n),
                                   network_get(n));
106 107 108 109
}

/*
 * call-seq:
110
 *   net.name -> String
111
 *
112
 * Call virNetworkGetName[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetName]
113
 * to retrieve the name of this network.
114
 */
115
static VALUE libvirt_network_name(VALUE n)
116
{
117 118 119
    ruby_libvirt_generate_call_string(virNetworkGetName,
                                      ruby_libvirt_connect_get(n), 0,
                                      network_get(n));
120 121 122 123
}

/*
 * call-seq:
124
 *   net.uuid -> String
125
 *
126
 * Call virNetworkGetUUIDString[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetUUIDString]
127
 * to retrieve the UUID of this network.
128
 */
129
static VALUE libvirt_network_uuid(VALUE n)
130
{
131 132
    ruby_libvirt_generate_uuid(virNetworkGetUUIDString,
                               ruby_libvirt_connect_get(n), network_get(n));
133 134 135 136
}

/*
 * call-seq:
137
 *   net.xml_desc(flags=0) -> String
138
 *
139
 * Call virNetworkGetXMLDesc[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetXMLDesc]
140
 * to retrieve the XML for this network.
141
 */
142
static VALUE libvirt_network_xml_desc(int argc, VALUE *argv, VALUE n)
143
{
144 145 146 147
    VALUE flags;

    rb_scan_args(argc, argv, "01", &flags);

148 149
    ruby_libvirt_generate_call_string(virNetworkGetXMLDesc,
                                      ruby_libvirt_connect_get(n), 1,
150
                                      network_get(n),
151
                                      ruby_libvirt_value_to_uint(flags));
152 153 154 155
}

/*
 * call-seq:
156
 *   net.bridge_name -> String
157
 *
158
 * Call virNetworkGetBridgeName[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetBridgeName]
159
 * to retrieve the bridge name for this network.
160
 */
161
static VALUE libvirt_network_bridge_name(VALUE n)
162
{
163 164 165
    ruby_libvirt_generate_call_string(virNetworkGetBridgeName,
                                      ruby_libvirt_connect_get(n),
                                      1, network_get(n));
166 167 168 169 170 171
}

/*
 * call-seq:
 *   net.autostart? -> [true|false]
 *
172
 * Call virNetworkGetAutostart[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetAutostart]
173
 * to determine if this network will be autostarted when libvirtd starts.
174
 */
175
static VALUE libvirt_network_autostart(VALUE n)
176
{
177 178
    int r, autostart;

Chris Lalancette's avatar
Chris Lalancette committed
179
    r = virNetworkGetAutostart(network_get(n), &autostart);
Chris Lalancette's avatar
Chris Lalancette committed
180 181
    ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virNetworkAutostart",
                                ruby_libvirt_connect_get(n));
182 183 184 185 186 187

    return autostart ? Qtrue : Qfalse;
}

/*
 * call-seq:
188
 *   net.autostart = [true|false]
189
 *
190
 * Call virNetworkSetAutostart[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkSetAutostart]
191
 * to set this network to be autostarted when libvirtd starts.
192
 */
193
static VALUE libvirt_network_autostart_equal(VALUE n, VALUE autostart)
194
{
Chris Lalancette's avatar
Chris Lalancette committed
195
    if (autostart != Qtrue && autostart != Qfalse) {
196 197
        rb_raise(rb_eTypeError,
                 "wrong argument type (expected TrueClass or FalseClass)");
Chris Lalancette's avatar
Chris Lalancette committed
198
    }
199

200 201 202
    ruby_libvirt_generate_call_nil(virNetworkSetAutostart,
                                   ruby_libvirt_connect_get(n),
                                   network_get(n), RTEST(autostart) ? 1 : 0);
203 204 205 206 207 208
}

/*
 * call-seq:
 *   net.free -> nil
 *
209
 * Call virNetworkFree[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkFree]
210
 * to free this network.  The object will no longer be valid after this call.
211
 */
212
static VALUE libvirt_network_free(VALUE n)
213
{
214
    ruby_libvirt_generate_call_free(Network, n);
215 216
}

217 218 219 220 221
#if HAVE_VIRNETWORKISACTIVE
/*
 * call-seq:
 *   net.active? -> [true|false]
 *
222
 * Call virNetworkIsActive[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkIsActive]
223
 * to determine if this network is currently active.
224
 */
225
static VALUE libvirt_network_active_p(VALUE n)
226
{
227 228 229
    ruby_libvirt_generate_call_truefalse(virNetworkIsActive,
                                         ruby_libvirt_connect_get(n),
                                         network_get(n));
230 231 232 233 234 235 236 237
}
#endif

#if HAVE_VIRNETWORKISPERSISTENT
/*
 * call-seq:
 *   net.persistent? -> [true|false]
 *
238
 * Call virNetworkIsPersistent[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkIsPersistent]
239
 * to determine if this network is persistent.
240
 */
241
static VALUE libvirt_network_persistent_p(VALUE n)
242
{
243 244 245
    ruby_libvirt_generate_call_truefalse(virNetworkIsPersistent,
                                         ruby_libvirt_connect_get(n),
                                         network_get(n));
246 247 248
}
#endif

249
#if HAVE_VIRNETWORKGETDHCPLEASES
250 251
struct leases_arg {
    virNetworkDHCPLeasePtr *leases;
Chris Lalancette's avatar
Chris Lalancette committed
252
    int nleases;
253 254 255 256 257
};

static VALUE leases_wrap(VALUE arg)
{
    struct leases_arg *e = (struct leases_arg *)arg;
Chris Lalancette's avatar
Chris Lalancette committed
258
    VALUE result, hash;
259
    virNetworkDHCPLeasePtr lease;
Chris Lalancette's avatar
Chris Lalancette committed
260 261 262 263 264 265 266 267 268 269 270 271
    int i;

    result = rb_ary_new2(e->nleases);

    for (i = 0; i < e->nleases; i++) {
        lease = e->leases[i];

        hash = rb_hash_new();
        rb_hash_aset(hash, rb_str_new2("iface"), rb_str_new2(lease->iface));
        rb_hash_aset(hash, rb_str_new2("expirytime"),
                     LL2NUM(lease->expirytime));
        rb_hash_aset(hash, rb_str_new2("type"), INT2NUM(lease->type));
272 273 274 275 276 277
        if (lease->mac) {
            rb_hash_aset(hash, rb_str_new2("mac"), rb_str_new2(lease->mac));
        }
        if (lease->iaid) {
            rb_hash_aset(hash, rb_str_new2("iaid"), rb_str_new2(lease->iaid));
        }
Chris Lalancette's avatar
Chris Lalancette committed
278 279
        rb_hash_aset(hash, rb_str_new2("ipaddr"), rb_str_new2(lease->ipaddr));
        rb_hash_aset(hash, rb_str_new2("prefix"), UINT2NUM(lease->prefix));
280 281 282 283 284 285 286 287
        if (lease->hostname) {
            rb_hash_aset(hash, rb_str_new2("hostname"),
                         rb_str_new2(lease->hostname));
        }
        if (lease->clientid) {
            rb_hash_aset(hash, rb_str_new2("clientid"),
                         rb_str_new2(lease->clientid));
        }
Chris Lalancette's avatar
Chris Lalancette committed
288 289 290

        rb_ary_store(result, i, hash);
    }
291

Chris Lalancette's avatar
Chris Lalancette committed
292
    return result;
293 294
}

295 296 297 298
/*
 * call-seq:
 *   net.dhcp_leases(mac=nil, flags=0) -> Hash
 *
299
 * Call virNetworkGetDHCPLeases[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetDHCPLeases]
300 301 302 303
 * to retrieve the leases for this network.
 */
static VALUE libvirt_network_get_dhcp_leases(int argc, VALUE *argv, VALUE n)
{
304
    VALUE mac, flags, result;
Chris Lalancette's avatar
Chris Lalancette committed
305
    int nleases, i = 0, exception = 0;
306
    virNetworkDHCPLeasePtr *leases = NULL;
307
    struct leases_arg args;
308 309 310 311 312 313 314

    rb_scan_args(argc, argv, "02", &mac, &flags);

    nleases = virNetworkGetDHCPLeases(network_get(n),
                                      ruby_libvirt_get_cstring_or_null(mac),
                                      &leases,
                                      ruby_libvirt_value_to_uint(flags));
315 316
    ruby_libvirt_raise_error_if(nleases < 0, e_Error, "virNetworkGetDHCPLeases",
                                ruby_libvirt_connect_get(n));
317

Chris Lalancette's avatar
Chris Lalancette committed
318 319 320
    args.leases = leases;
    args.nleases = nleases;
    result = rb_protect(leases_wrap, (VALUE)&args, &exception);
321 322 323 324

    for (i = 0; i < nleases; i++) {
        virNetworkDHCPLeaseFree(leases[i]);
    }
325
    free(leases);
326

Chris Lalancette's avatar
Chris Lalancette committed
327 328
    if (exception) {
        rb_jump_tag(exception);
329
    }
330

Chris Lalancette's avatar
Chris Lalancette committed
331
    return result;
332 333 334
}
#endif

335 336 337 338 339
#endif

/*
 * Class Libvirt::Network
 */
340
void ruby_libvirt_network_init(void)
341 342 343 344 345
{
#if HAVE_TYPE_VIRNETWORKPTR
    c_network = rb_define_class_under(m_libvirt, "Network", rb_cObject);
    rb_define_attr(c_network, "connection", 1, 0);

346 347
    rb_define_method(c_network, "undefine", libvirt_network_undefine, 0);
    rb_define_method(c_network, "create", libvirt_network_create, 0);
348
#if HAVE_VIRNETWORKUPDATE
349
    rb_define_method(c_network, "update", libvirt_network_update, 5);
350
#endif
351 352 353 354 355 356 357
    rb_define_method(c_network, "destroy", libvirt_network_destroy, 0);
    rb_define_method(c_network, "name", libvirt_network_name, 0);
    rb_define_method(c_network, "uuid", libvirt_network_uuid, 0);
    rb_define_method(c_network, "xml_desc", libvirt_network_xml_desc, -1);
    rb_define_method(c_network, "bridge_name", libvirt_network_bridge_name, 0);
    rb_define_method(c_network, "autostart", libvirt_network_autostart, 0);
    rb_define_method(c_network, "autostart?", libvirt_network_autostart, 0);
358 359
    rb_define_method(c_network, "autostart=", libvirt_network_autostart_equal,
                     1);
360
    rb_define_method(c_network, "free", libvirt_network_free, 0);
361
#if HAVE_VIRNETWORKISACTIVE
362
    rb_define_method(c_network, "active?", libvirt_network_active_p, 0);
363 364
#endif
#if HAVE_VIRNETWORKISPERSISTENT
365
    rb_define_method(c_network, "persistent?", libvirt_network_persistent_p, 0);
366
#endif
Hiroshi Miura's avatar
Hiroshi Miura committed
367
#if HAVE_CONST_VIR_NETWORK_UPDATE_COMMAND_NONE
Chris Lalancette's avatar
Chris Lalancette committed
368 369 370 371 372 373
    /* Ideally we would just have the "UPDATE_COMMAND_NONE" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_UPDATE_COMMAND_NONE" for backwards compatibility.
     */
    rb_define_const(c_network, "UPDATE_COMMAND_NONE",
                    INT2NUM(VIR_NETWORK_UPDATE_COMMAND_NONE));
374 375
    rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_NONE",
                    INT2NUM(VIR_NETWORK_UPDATE_COMMAND_NONE));
Chris Lalancette's avatar
Chris Lalancette committed
376 377 378 379 380 381
    /* Ideally we would just have the "UPDATE_COMMAND_MODIFY" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_UPDATE_COMMAND_MODIFY" for backwards compatibility.
     */
    rb_define_const(c_network, "UPDATE_COMMAND_MODIFY",
                    INT2NUM(VIR_NETWORK_UPDATE_COMMAND_MODIFY));
382 383
    rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_MODIFY",
                    INT2NUM(VIR_NETWORK_UPDATE_COMMAND_MODIFY));
Chris Lalancette's avatar
Chris Lalancette committed
384 385 386 387 388 389
    /* Ideally we would just have the "UPDATE_COMMAND_ADD_LAST" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_UPDATE_COMMAND_ADD_LAST" for backwards compatibility.
     */
    rb_define_const(c_network, "UPDATE_COMMAND_ADD_LAST",
                    INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_LAST));
390 391
    rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_ADD_LAST",
                    INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_LAST));
Chris Lalancette's avatar
Chris Lalancette committed
392 393 394 395 396 397
    /* Ideally we would just have the "UPDATE_COMMAND_ADD_FIRST" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_UPDATE_COMMAND_ADD_FIRST" for backwards compatibility.
     */
    rb_define_const(c_network, "UPDATE_COMMAND_ADD_FIRST",
                    INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST));
398 399
    rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_ADD_FIRST",
                    INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST));
Chris Lalancette's avatar
Chris Lalancette committed
400 401 402 403 404 405
    /* Ideally we would just have the "SECTION_NONE" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_NONE" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_NONE",
                    INT2NUM(VIR_NETWORK_SECTION_NONE));
406 407
    rb_define_const(c_network, "NETWORK_SECTION_NONE",
                    INT2NUM(VIR_NETWORK_SECTION_NONE));
Chris Lalancette's avatar
Chris Lalancette committed
408 409 410 411 412 413
    /* Ideally we would just have the "SECTION_BRIDGE" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_BRIDGE" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_BRIDGE",
                    INT2NUM(VIR_NETWORK_SECTION_BRIDGE));
414 415
    rb_define_const(c_network, "NETWORK_SECTION_BRIDGE",
                    INT2NUM(VIR_NETWORK_SECTION_BRIDGE));
Chris Lalancette's avatar
Chris Lalancette committed
416 417 418 419 420 421
    /* Ideally we would just have the "SECTION_DOMAIN" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_DOMAIN" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_DOMAIN",
                    INT2NUM(VIR_NETWORK_SECTION_DOMAIN));
422 423
    rb_define_const(c_network, "NETWORK_SECTION_DOMAIN",
                    INT2NUM(VIR_NETWORK_SECTION_DOMAIN));
Chris Lalancette's avatar
Chris Lalancette committed
424 425 426 427 428 429
    /* Ideally we would just have the "SECTION_IP" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_IP" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_IP",
                    INT2NUM(VIR_NETWORK_SECTION_IP));
430 431
    rb_define_const(c_network, "NETWORK_SECTION_IP",
                    INT2NUM(VIR_NETWORK_SECTION_IP));
Chris Lalancette's avatar
Chris Lalancette committed
432 433 434 435 436 437
    /* Ideally we would just have the "SECTION_IP_DHCP_HOST" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_IP_DHCP_HOST" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_IP_DHCP_HOST",
                    INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_HOST));
438 439
    rb_define_const(c_network, "NETWORK_SECTION_IP_DHCP_HOST",
                    INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_HOST));
Chris Lalancette's avatar
Chris Lalancette committed
440 441 442 443 444 445
    /* Ideally we would just have the "SECTION_IP_DHCP_RANGE" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_IP_DHCP_RANGE" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_IP_DHCP_RANGE",
                    INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_RANGE));
446 447
    rb_define_const(c_network, "NETWORK_SECTION_IP_DHCP_RANGE",
                    INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_RANGE));
Chris Lalancette's avatar
Chris Lalancette committed
448 449 450 451 452 453
    /* Ideally we would just have the "SECTION_FORWARD" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_FORWARD" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_FORWARD",
                    INT2NUM(VIR_NETWORK_SECTION_FORWARD));
454 455
    rb_define_const(c_network, "NETWORK_SECTION_FORWARD",
                    INT2NUM(VIR_NETWORK_SECTION_FORWARD));
Chris Lalancette's avatar
Chris Lalancette committed
456 457 458 459 460 461
    /* Ideally we would just have the "SECTION_FORWARD_INTERFACE" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_FORWARD_INTERFACE" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_FORWARD_INTERFACE",
                    INT2NUM(VIR_NETWORK_SECTION_FORWARD_INTERFACE));
462 463
    rb_define_const(c_network, "NETWORK_SECTION_FORWARD_INTERFACE",
                    INT2NUM(VIR_NETWORK_SECTION_FORWARD_INTERFACE));
Chris Lalancette's avatar
Chris Lalancette committed
464 465 466 467 468 469
    /* Ideally we would just have the "SECTION_FORWARD_PF" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_FORWARD_PF" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_FORWARD_PF",
                    INT2NUM(VIR_NETWORK_SECTION_FORWARD_PF));
470 471
    rb_define_const(c_network, "NETWORK_SECTION_FORWARD_PF",
                    INT2NUM(VIR_NETWORK_SECTION_FORWARD_PF));
Chris Lalancette's avatar
Chris Lalancette committed
472 473 474 475 476 477
    /* Ideally we would just have the "SECTION_PORTGROUP" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_PORTGROUP" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_PORTGROUP",
                    INT2NUM(VIR_NETWORK_SECTION_PORTGROUP));
478 479
    rb_define_const(c_network, "NETWORK_SECTION_PORTGROUP",
                    INT2NUM(VIR_NETWORK_SECTION_PORTGROUP));
Chris Lalancette's avatar
Chris Lalancette committed
480 481 482 483 484 485
    /* Ideally we would just have the "SECTION_DNS_HOST" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_DNS_HOST" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_DNS_HOST",
                    INT2NUM(VIR_NETWORK_SECTION_DNS_HOST));
486 487
    rb_define_const(c_network, "NETWORK_SECTION_DNS_HOST",
                    INT2NUM(VIR_NETWORK_SECTION_DNS_HOST));
Chris Lalancette's avatar
Chris Lalancette committed
488 489 490 491 492 493
    /* Ideally we would just have the "SECTION_DNS_TXT" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_DNS_TXT" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_DNS_TXT",
                    INT2NUM(VIR_NETWORK_SECTION_DNS_TXT));
494 495
    rb_define_const(c_network, "NETWORK_SECTION_DNS_TXT",
                    INT2NUM(VIR_NETWORK_SECTION_DNS_TXT));
Chris Lalancette's avatar
Chris Lalancette committed
496 497 498 499 500 501
    /* Ideally we would just have the "SECTION_DNS_SRV" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_SECTION_DNS_SRV" for backwards compatibility.
     */
    rb_define_const(c_network, "SECTION_DNS_SRV",
                    INT2NUM(VIR_NETWORK_SECTION_DNS_SRV));
502 503
    rb_define_const(c_network, "NETWORK_SECTION_DNS_SRV",
                    INT2NUM(VIR_NETWORK_SECTION_DNS_SRV));
Chris Lalancette's avatar
Chris Lalancette committed
504 505 506 507 508 509
    /* Ideally we would just have the "UPDATE_AFFECT_CURRENT" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_UPDATE_AFFECT_CURRENT" for backwards compatibility.
     */
    rb_define_const(c_network, "UPDATE_AFFECT_CURRENT",
                    INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CURRENT));
510 511
    rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_CURRENT",
                    INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CURRENT));
Chris Lalancette's avatar
Chris Lalancette committed
512 513 514 515 516 517
    /* Ideally we would just have the "UPDATE_AFFECT_LIVE" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_UPDATE_AFFECT_LIVE" for backwards compatibility.
     */
    rb_define_const(c_network, "UPDATE_AFFECT_LIVE",
                    INT2NUM(VIR_NETWORK_UPDATE_AFFECT_LIVE));
518 519
    rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_LIVE",
                    INT2NUM(VIR_NETWORK_UPDATE_AFFECT_LIVE));
Chris Lalancette's avatar
Chris Lalancette committed
520 521 522 523 524 525
    /* Ideally we would just have the "UPDATE_AFFECT_CONFIG" constant.
     * Unfortunately we screwed up long ago, and we have to
     * leave "NETWORK_UPDATE_AFFECT_CONFIG" for backwards compatibility.
     */
    rb_define_const(c_network, "UPDATE_AFFECT_CONFIG",
                    INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CONFIG));
526 527
    rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_CONFIG",
                    INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CONFIG));
Hiroshi Miura's avatar
Hiroshi Miura committed
528
#endif
Chris Lalancette's avatar
Chris Lalancette committed
529 530 531 532 533

#if HAVE_CONST_VIR_NETWORK_XML_INACTIVE
    rb_define_const(c_network, "XML_INACTIVE",
                    INT2NUM(VIR_NETWORK_XML_INACTIVE));
#endif
534 535 536 537 538
#if HAVE_CONST_VIR_NETWORK_UPDATE_COMMAND_DELETE
    rb_define_const(c_network, "UPDATE_COMMAND_DELETE",
                    INT2NUM(VIR_NETWORK_UPDATE_COMMAND_DELETE));
#endif

539 540 541 542 543
#if HAVE_VIRNETWORKGETDHCPLEASES
    rb_define_method(c_network, "dhcp_leases",
                     libvirt_network_get_dhcp_leases, -1);
#endif

544 545 546 547 548 549 550 551 552 553
#if HAVE_CONST_VIR_IP_ADDR_TYPE_IPV4
    rb_define_const(c_network, "IP_ADDR_TYPE_IPV4",
                    INT2NUM(VIR_IP_ADDR_TYPE_IPV4));
#endif

#if HAVE_CONST_VIR_IP_ADDR_TYPE_IPV6
    rb_define_const(c_network, "IP_ADDR_TYPE_IPV6",
                    INT2NUM(VIR_IP_ADDR_TYPE_IPV6));
#endif

554 555
#endif
}