From: Scott Seago <sseago at redhat.com>
This adds some of the network API stuff to ovirt-agent. It's still not
complete but what is there is functional.
Signed-off-by: Ian Main <imain at redhat.com>
---
src/ovirt-agent/lib/ovirt.rb | 3 +
.../ovirt/controllers/hardwarepool_controller.rb | 2 +-
.../lib/ovirt/controllers/network_controller.rb | 30 +++++++++++++++
.../lib/ovirt/controllers/ovirt_controller.rb | 25 ++++++++++++
.../physical_network_impl_controller.rb | 13 ++++++
.../lib/ovirt/controllers/vlan_impl_controller.rb | 13 ++++++
.../lib/ovirt/controllers/vmdef_controller.rb | 5 ++
src/ovirt-agent/ovirt-agent.rb | 4 +-
src/ovirt-agent/ovirt-test.rb | 40 +++++++++++++++++---
src/ovirt-agent/ovirt_api.xml | 27 +++++++++++++
10 files changed, 153 insertions(+), 9 deletions(-)
create mode 100644 src/ovirt-agent/lib/ovirt/controllers/network_controller.rb
create mode 100644
src/ovirt-agent/lib/ovirt/controllers/physical_network_impl_controller.rb
create mode 100644
src/ovirt-agent/lib/ovirt/controllers/vlan_impl_controller.rb
diff --git a/src/ovirt-agent/lib/ovirt.rb b/src/ovirt-agent/lib/ovirt.rb
index e215d3b..0177748 100644
--- a/src/ovirt-agent/lib/ovirt.rb
+++ b/src/ovirt-agent/lib/ovirt.rb
@@ -7,4 +7,7 @@ require 'ovirt/controllers/ovirt_controller'
require 'ovirt/controllers/hardwarepool_controller'
require 'ovirt/controllers/vmpool_controller'
require 'ovirt/controllers/vmdef_controller'
+require 'ovirt/controllers/network_controller'
+require 'ovirt/controllers/vlan_impl_controller'
+require 'ovirt/controllers/physical_network_impl_controller'
diff --git a/src/ovirt-agent/lib/ovirt/controllers/hardwarepool_controller.rb
b/src/ovirt-agent/lib/ovirt/controllers/hardwarepool_controller.rb
index b7ea3f2..fc5c198 100644
--- a/src/ovirt-agent/lib/ovirt/controllers/hardwarepool_controller.rb
+++ b/src/ovirt-agent/lib/ovirt/controllers/hardwarepool_controller.rb
@@ -35,7 +35,7 @@ module Ovirt
puts "pool_hash: #{pool_hash.inspect}"
svc_create(pool_hash, id, {})
- args['vm_pool'] = encode_id(@pool.id)
+ args['vm_pool'] =
@agent.encode_id(VmResourcePoolService.schema_class.id, @pool.id)
end
end
end
diff --git a/src/ovirt-agent/lib/ovirt/controllers/network_controller.rb
b/src/ovirt-agent/lib/ovirt/controllers/network_controller.rb
new file mode 100644
index 0000000..1a8ffd1
--- /dev/null
+++ b/src/ovirt-agent/lib/ovirt/controllers/network_controller.rb
@@ -0,0 +1,30 @@
+module Ovirt
+
+ class NetworkController < AgentController
+
+ include NetworkService
+
+ def find(id)
+ svc_show(id)
+ render(@network)
+ end
+
+ def list
+ puts "query for Network class!"
+ svc_list
+ @networks.collect { |network| render(network) }
+ end
+
+ def render(network)
+ obj = to_qmf(network, :propmap => { :proto => nil})
+ obj['proto'] = network.boot_type.proto
+ puts "network.type is #{@network.type}"
+ if @network.type == 'PhysicalNetwork'
+ obj['impl'] =
@agent.encode_id(PhysicalNetworkImplController.schema_class.id, @network.id)
+ elsif @network.type == 'Vlan'
+ obj['impl'] =
@agent.encode_id(VlanImplController.schema_class.id, @network.id)
+ end
+ return obj
+ end
+ end
+end
diff --git a/src/ovirt-agent/lib/ovirt/controllers/ovirt_controller.rb
b/src/ovirt-agent/lib/ovirt/controllers/ovirt_controller.rb
index 4f58113..c831869 100644
--- a/src/ovirt-agent/lib/ovirt/controllers/ovirt_controller.rb
+++ b/src/ovirt-agent/lib/ovirt/controllers/ovirt_controller.rb
@@ -27,6 +27,31 @@ module Ovirt
[ @@instance ]
end
+ def create_vlan_network
+ extend NetworkService
+
+ boot_type = BootType.find(:first, :conditions => ["proto =
?", args['proto']])
+ raise "Unknown boot protocol #{args['proto']}." if not
boot_type
+ puts "in create_vlan_network, boot_type id is #{boot_type.id}"
+ hash = { :name => args['name'], :number =>
args['number'], :type => 'Vlan', :boot_type_id =>
boot_type.id }
+
+ svc_create(hash)
+
+ args['network'] =
@agent.encode_id(NetworkController.schema_class.id, @network.id)
+ end
+
+ def create_physical_network
+ extend NetworkService
+
+ boot_type = BootType.find(:first, :conditions => ["proto =
?", args['proto']])
+ raise "Unknown boot protocol #{args['proto']}." if not
boot_type
+ puts "in create_physical_network, boot_type id is
#{boot_type.id}"
+ hash = { :name => args['name'], :type =>
'PhysicalNetwork', :boot_type_id => boot_type.id }
+
+ svc_create(hash)
+
+ args['network'] =
@agent.encode_id(NetworkController.schema_class.id, @network.id)
+ end
end
end
diff --git
a/src/ovirt-agent/lib/ovirt/controllers/physical_network_impl_controller.rb
b/src/ovirt-agent/lib/ovirt/controllers/physical_network_impl_controller.rb
new file mode 100644
index 0000000..f5cb8da
--- /dev/null
+++ b/src/ovirt-agent/lib/ovirt/controllers/physical_network_impl_controller.rb
@@ -0,0 +1,13 @@
+module Ovirt
+
+ class PhysicalNetworkImplController < NetworkController
+
+ def render(network)
+ obj = Qmf::QmfObject.new(schema_class)
+ obj['network'] =
@agent.encode_id(NetworkController.schema_class.id, @network.id)
+ obj.set_object_id(encode_id(network.id))
+ return obj
+ end
+
+ end
+end
diff --git a/src/ovirt-agent/lib/ovirt/controllers/vlan_impl_controller.rb
b/src/ovirt-agent/lib/ovirt/controllers/vlan_impl_controller.rb
new file mode 100644
index 0000000..59766ca
--- /dev/null
+++ b/src/ovirt-agent/lib/ovirt/controllers/vlan_impl_controller.rb
@@ -0,0 +1,13 @@
+module Ovirt
+
+ class VlanImplController < NetworkController
+
+ def render(network)
+ obj = Qmf::QmfObject.new(schema_class)
+ obj['number'] = @network.number
+ obj['network'] =
@agent.encode_id(NetworkController.schema_class.id, @network.id)
+ obj.set_object_id(encode_id(network.id))
+ return obj
+ end
+ end
+end
diff --git a/src/ovirt-agent/lib/ovirt/controllers/vmdef_controller.rb
b/src/ovirt-agent/lib/ovirt/controllers/vmdef_controller.rb
index 1ee69a4..38e3694 100644
--- a/src/ovirt-agent/lib/ovirt/controllers/vmdef_controller.rb
+++ b/src/ovirt-agent/lib/ovirt/controllers/vmdef_controller.rb
@@ -3,6 +3,11 @@ module Ovirt
include VmService
+ def description(desc)
+ puts "description property set for vmdef."
+ svc_update(id, { :description => desc }, false, false)
+ end
+
def find(id)
svc_show(id)
render(@vm)
diff --git a/src/ovirt-agent/ovirt-agent.rb b/src/ovirt-agent/ovirt-agent.rb
index 62834b0..425699b 100755
--- a/src/ovirt-agent/ovirt-agent.rb
+++ b/src/ovirt-agent/ovirt-agent.rb
@@ -139,7 +139,7 @@ class OvirtAgent < Qmf::AgentHandler
@settings.host = server
# FIXME: Bug in swig!
#@settings.port = port
- @settings.mechanism = 'GSSAPI'
+ #@settings.mechanism = 'GSSAPI'
@logger.info "Connecting to broker on #{@settings.host}.."
@@ -165,7 +165,7 @@ class OvirtAgent < Qmf::AgentHandler
end
@controller_classes.values.each do |controller_class|
- @logger.info "Register #{controller_class.schema_class.name} =>
#{controller_class.name}"
+ @logger.info "Register #{controller_class.schema_class.name} =>
#{controller_class.name}, id #{controller_class.schema_class.id}"
@agent.register_class(controller_class.schema_class)
end
end
diff --git a/src/ovirt-agent/ovirt-test.rb b/src/ovirt-agent/ovirt-test.rb
index 412a8ee..ab67d10 100755
--- a/src/ovirt-agent/ovirt-test.rb
+++ b/src/ovirt-agent/ovirt-test.rb
@@ -18,6 +18,12 @@ b = s.add_broker(srv, :mechanism => 'GSSAPI')
# This segfaults in F10 (ruby-1.8.6.287-2.fc10.x86_64)
# p s.objects(:class => "Ovirt")
+def print_properties(obj)
+ for (key, val) in obj.properties
+ puts " property: #{key}, #{val}"
+ end
+end
+
ovirt = s.object(:class => "Ovirt")
puts "id is #{ovirt.object_id}"
raise "ACK! NO ovirt class!" unless ovirt
@@ -25,6 +31,32 @@ puts "ovirt.version is #{ovirt.version}"
ovirt_by_id = s.object(:object_id => ovirt.object_id)
puts "ovirt_by_id.version is #{ovirt_by_id.version}"
+puts "Networks"
+network = nil
+result = ovirt.create_physical_network('ovirt-test', 'static')
+puts "Error: #{result.text}" if result.status != 0
+if result.status == 0
+ puts "new network created:"
+ network = s.object(:object_id => result.network)
+ puts "network is #{network} - id #{result.network}"
+ print_properties(network)
+ impl = s.object(:object_id => network.impl)
+ puts "impl is #{impl}:"
+ print_properties(impl)
+end
+
+result = ovirt.create_vlan_network('ovirt-test', 'static', 1)
+puts "Error: #{result.text}" if result.status != 0
+if result.status == 0
+ puts "new network created:"
+ network = s.object(:object_id => result.network)
+ puts "network is #{network} - id #{result.network}"
+ print_properties(network)
+ impl = s.object(:object_id => network.impl)
+ puts "impl is #{impl}:"
+ print_properties(impl)
+end
+
puts "Hardware Pools:"
hwps = s.objects(:class => "HardwarePool")
hwps.each do |hwp|
@@ -33,9 +65,7 @@ hwps.each do |hwp|
vmps = s.objects(:class => "VmPool", 'hardware_pool'
=> hwp.object_id)
vmps.each do |vmp|
puts "VM pool: #{vmp.name}"
- for (key, val) in vmp.properties
- puts " property: #{key}, #{val}"
- end
+ print_properties(vmp)
end
end
@@ -98,9 +128,7 @@ puts "VM deleted" if !vm
vms = s.objects(:class => 'VmDef')
vms.each do |vm|
puts "VM: #{vm.description}"
- for (key, val) in vm.properties
- puts " property: #{key}, #{val}"
- end
+ print_properties(vm)
end
diff --git a/src/ovirt-agent/ovirt_api.xml b/src/ovirt-agent/ovirt_api.xml
index a5aa383..6efa58b 100644
--- a/src/ovirt-agent/ovirt_api.xml
+++ b/src/ovirt-agent/ovirt_api.xml
@@ -20,6 +20,20 @@
</doc:desc>
<property name="version" type="sstr"
access="RC" desc="Ovirt version string"/>
+ <method name="create_physical_network">
+ <arg name="name" dir="I" type="sstr"
desc="Name of the new network"/>
+ <arg name="proto" dir="I" type="sstr"
desc="The boot protocol on this network, 'static', 'dhcp',
or 'bootp'."/>
+ <arg name="network" dir="O" type="objId"
desc="The newly created network definition object."/>
+ </method>
+
+ <method name="create_vlan_network">
+ <arg name="name" dir="I" type="sstr"
desc="Name of the new network"/>
+ <arg name="proto" dir="I" type="sstr"
desc="The boot protocol on this network, 'static', 'dhcp',
or 'bootp'."/>
+ <arg name="number" dir="I" type="uint32"
desc="VLAN network number."/>
+ <arg name="network" dir="O" type="objId"
desc="The newly created network definition object."/>
+ </method>
+
+
</class>
<class name="HardwarePool">
@@ -73,12 +87,25 @@
</doc:desc>
<property name="name" type="sstr" desc="The
name of the network"/>
<property name="proto" type="sstr" desc="The
boot protocol on this network, one of 'static', 'dhcp' or
'bootp'"/>
+ <property name="impl" type="objId"
access="RC" desc="References a VlanImpl or
PhysicalNetworkImpl."/>
+ <!-- FIXME: What about IP addresses, usages, and VMs references -->
<method name="create_vm_nic_def" desc="Create a new NIC
for a VM">
<arg name="mac" type="sstr" dir="I"
desc="The MAC address for the new NIC"/>
<arg name="nic" dir="O" type="objId"
references="VmNicDef" desc="Newly created VM NIC"/>
</method>
</class>
+ <!-- FIXME: This needs to use inheritance when QMF infrastructure is
available -->
+ <class name="VlanImpl">
+ <property name="network" type="objId"
references="Network" access="RC" desc="Reference to the
network this implementation is for."/>
+ <property name="number" type="uint32"
access="RW" desc="VLAN Number"/>
+ <!-- FIXME: Bondings ref needed once Bondings are added to the API
-->
+ </class>
+ <class name="PhysicalNetworkImpl">
+ <property name="network" type="objId"
references="Network" access="RC" desc="Reference to the
network this implementation is for."/>
+ <!-- FIXME: NICs ref needed once the VM/Host NIC model is finalized
-->
+ </class>
+
<class name="VmNicDef">
<doc:desc>
The virtual NIC of a VM; ties a MAC address to a logical network
--
1.6.2.5