deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [02/14] git commit: Network API rev 3 - RHEV-M Driver implementation
Date Fri, 26 Apr 2013 15:46:59 GMT
Network API rev 3 - RHEV-M Driver implementation


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/c1c84bcb
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/c1c84bcb
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/c1c84bcb

Branch: refs/heads/master
Commit: c1c84bcb7bda87b137f990adc5db250c029d46d6
Parents: 3163f81
Author: marios <marios@redhat.com>
Authored: Fri Apr 12 12:22:49 2013 +0300
Committer: marios <marios@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300

----------------------------------------------------------------------
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |   88 ++++++++++++++-
 1 files changed, 86 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c1c84bcb/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index ce34457..6b90b2d 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -208,6 +208,71 @@ class RhevmDriver < Deltacloud::BaseDriver
     end
   end
 
+  def networks(credentials, opts={})
+    client = new_client(credentials)
+    networks = []
+    safely do
+      client.networks(opts).each do |n|
+        next unless n.status == "operational" # making network operational is admin task
+        networks << convert_network(n)
+      end
+    end
+    filter_on(networks, :id, opts)
+  end
+
+  #def create_network(credentials, opts={})
+  #  RHEV API supports creation of networks, but network creation is
+  #  admin task, it's not expected to create networks on demand.
+  #  If we want to have this action, it must also be implemented in
+  #  rbovirt at first
+  #end
+
+  #def destroy_network(credentials, opts={})
+  #  RHEV API supports deletion of networks, but network creation is
+  #  admin task, it's not expected to delete networks on demand.
+  #  If we want to have this action, it must also be implemented in
+  #  rbovirt at first
+  #end
+
+  #def subnets(credentials, opts={})
+  #  there is not any suitable entity in RHEV networking model
+  #end
+  def network_interfaces(credentials, opts={})
+    client = new_client(credentials)
+    nics = []
+    safely do
+      client.vms.each do |vm|
+        vm.interfaces.each do |vm_nic|
+          if opts[:id] && (vm_nic.id == opts[:id])
+            return [convert_nic(vm_nic)]
+          else
+            nics << convert_nic(vm_nic)
+          end
+        end
+      end
+    end
+    filter_on(nics, :id, opts)
+  end
+
+  #:network, :instance, :name
+  def create_network_interface(credentials, opts={})
+    client = new_client(credentials)
+    name = opts[:name] || "nic_#{Time.now.to_i}"
+    safely do
+      iface = client.add_interface(opts[:instance], {:name => name, :network => opts[:network]})
+      convert_nic(iface)
+    end
+  end
+
+  def destroy_network_interface(credentials, nic_id)
+    client = new_client(credentials)
+    safely do
+      #need to discover the instance for this nic first
+      nic = network_interface(credentials, {:id => nic_id})
+      client.destroy_interface(nic.instance, nic_id)
+    end
+  end
+
   private
 
   def new_client(credentials)
@@ -270,7 +335,8 @@ class RhevmDriver < Deltacloud::BaseDriver
     else
       actions = instance_actions_for(state)
     end
-
+    #get network_interfaces:
+    nics = inst.interfaces.inject([]){|res, cur| res << cur.id  ; res}
     Instance.new(
       :actions=>actions,
       :id => inst.id,
@@ -284,7 +350,8 @@ class RhevmDriver < Deltacloud::BaseDriver
       :hardware_profile_id => profile.id,
       :public_addresses => public_addresses,
       :private_addresses => [],
-      :create_image => can_create_image
+      :create_image => can_create_image,
+      :network_interfaces => nics
     )
   end
 
@@ -344,6 +411,23 @@ class RhevmDriver < Deltacloud::BaseDriver
     )
   end
 
+  def convert_network(n)
+    Network.new(
+      :id     => n.id,
+      :name   => n.name,
+      :state  => "UP" # only here if status is "operational"
+    )
+  end
+
+  def convert_nic(nic)
+    NetworkInterface.new({
+      :id => nic.id,
+      :name => nic.name,
+      :instance => nic.vm.id,
+      :network => nic.network || "n/a"
+    })
+  end
+
   exceptions do
 
     on /Unauthorized/ do


Mime
View raw message