[Ovirt-devel] Another Pass at Ovirt Node Qpid API

Ian Main imain at redhat.com
Wed Nov 5 21:32:38 UTC 2008



Here is another pass at the ovirt qpid API.  I've cleaned a few things up, incorporated some suggestions, done away with camel case (just because I can), and fleshed out the network configuration.

I've sent it as an attachment because it's getting pretty big.

I'm really wishing QMF had inheritance implemented but that's not in yet (future versions will have it I'm told).

Here is an example of how you might use it to configure networking:

s = Qpid::Qmf::Session.new()
b = s.add_broker("amqp://localhost:5672")

node = s.objects(:class => 'OvirtNode', 'hostname' => 'node3.priv.ovirt.org')

# Grab all the real interfaces.
interfaces = s.objects(:class => 'NetworkInterface', 'ovirt_node' => node.object_id)

# Print their name/mac and then print all IPv4 addresses bound to them.
interfaces.each do |interface|
    puts "interface name: #{interface.name}, mac: #{interface.mac}"
    ips = s.objects(:class => 'IpAddress', 'interface' => interface.object_id)
    puts "IP Addresses:"
    ips.each do |ip|
        puts "IP address: #{ip.ipaddr}"
    end
end

# Add a new bond to the current network.  This is kind of shortcutting because in
# a real application we'd have to find the real names of the interfaces, but as you
# can see above that's not hard.

iface1 = s.objects(:class => 'NetworkInterface', 'name' => 'eth1', 'ovirt_node' => node.object_id)
iface2 = s.objects(:class => 'NetworkInterface', 'name' => 'eth2', 'ovirt_node' => node.object_id)

bond = node.create_bonding_interface("bond0")

# Setup the two interfaces to be bonded.
iface1.master = bond.object_id
iface2.master = bond.object_id

# We'll pretend there was a previous config and we'll remove everything to do with it.
# Remove dhcp config.
iface1.dhcp = false
iface2.dhcp = false

# Remove all IPs.  Should do the same with v6, but we'll assume its disabled.
ips = s.objects(:class => 'IpAddress', 'interface' => iface1.object_id)
ips |= s.objects(:class => 'IpAddress', 'interface' => iface2.object_id)
ips.each do |ip|
    ip.delete
end

bond.bonding_mode = 'balance-alb'
bond.dhcp = true

# Restart network service.. I'm sure we could just restart the individual interfaces
# and it would work too.
node.restart_network()

# Make bond0 use a static IP instead

bond.dhcp = false
ipaddr = bond.add_ip_address()
ipaddr.ipaddr = "172.31.0.53"
ipaddr.prefix = 24
ipaddr.broadcast = "172.31.0.255"

# Just restart the interface..
bond.restart()

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ovirt-node-2008-11-05.xml
Type: application/xml
Size: 8814 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20081105/9d753f17/attachment.wsdl>


More information about the ovirt-devel mailing list