incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 1/2] Replaced old RHEV-M with new one to consume RHEV-API instead of executing PowerShell scripts.
Date Tue, 21 Dec 2010 11:58:02 GMT
From: Michal Fojtik <mfojtik@redhat.com>

---
 .../lib/deltacloud/drivers/rhevm/rhevm_client.rb   |  236 ++++++++++++
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |  392 +++++++++++---------
 .../lib/deltacloud/drivers/rhevm/scripts/addVM.ps1 |   32 --
 .../deltacloud/drivers/rhevm/scripts/common.ps1    |   33 --
 .../deltacloud/drivers/rhevm/scripts/deleteVm.ps1  |   30 --
 .../deltacloud/drivers/rhevm/scripts/rebootVm.ps1  |   31 --
 .../deltacloud/drivers/rhevm/scripts/startVm.ps1   |   30 --
 .../deltacloud/drivers/rhevm/scripts/stopVm.ps1    |   30 --
 .../drivers/rhevm/scripts/storageDomains.ps1       |   29 --
 .../drivers/rhevm/scripts/templateById.ps1         |   30 --
 .../deltacloud/drivers/rhevm/scripts/templates.ps1 |   28 --
 .../deltacloud/drivers/rhevm/scripts/vmById.ps1    |   31 --
 .../lib/deltacloud/drivers/rhevm/scripts/vms.ps1   |   29 --
 13 files changed, 459 insertions(+), 502 deletions(-)
 create mode 100644 server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
 delete mode 100644 server/lib/deltacloud/drivers/rhevm/scripts/addVM.ps1
 delete mode 100644 server/lib/deltacloud/drivers/rhevm/scripts/common.ps1
 delete mode 100644 server/lib/deltacloud/drivers/rhevm/scripts/deleteVm.ps1
 delete mode 100644 server/lib/deltacloud/drivers/rhevm/scripts/rebootVm.ps1
 delete mode 100644 server/lib/deltacloud/drivers/rhevm/scripts/startVm.ps1
 delete mode 100644 server/lib/deltacloud/drivers/rhevm/scripts/stopVm.ps1
 delete mode 100644 server/lib/deltacloud/drivers/rhevm/scripts/storageDomains.ps1
 delete mode 100644 server/lib/deltacloud/drivers/rhevm/scripts/templateById.ps1
 delete mode 100644 server/lib/deltacloud/drivers/rhevm/scripts/templates.ps1
 delete mode 100644 server/lib/deltacloud/drivers/rhevm/scripts/vmById.ps1
 delete mode 100644 server/lib/deltacloud/drivers/rhevm/scripts/vms.ps1

diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
new file mode 100644
index 0000000..55f54a4
--- /dev/null
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
@@ -0,0 +1,236 @@
+require 'base64'
+require 'restclient'
+require 'nokogiri'
+
+module RHEVM
+
+  class Client
+    attr_reader :base_uri
+    attr_reader :host
+    attr_reader :entry_points
+    attr_reader :username
+
+    # Define a list of supported collections which will be handled automatically
+    # by method_missing
+    @@COLLECTIONS = [ :templates, :clusters, :storagedomains, :vms, :datacenters ]
+
+    def initialize(username, password, base_uri, opts={})
+      @username, @password = username, password
+      uri = URI.parse(base_uri)
+      @host = "#{uri.scheme}://#{uri.host}:#{uri.port}"
+      @base_uri = base_uri
+      @entry_points = {}
+      discover_entry_points()
+    end
+
+    def method_missing(method_name, *args)
+      opts = args[0] if args[0].class.eql?(Hash)
+      opts ||= {}
+      if @@COLLECTIONS.include?(method_name.to_sym)
+        if opts[:id]
+          object = Nokogiri::XML(get("#{@entry_points[method_name.to_s]}#{opts[:id]}"))
+          element = method_name.to_s
+          element = 'data_centers' if method_name.eql?(:datacenters)
+          inst = ::RHEVM.const_get(element.classify)
+          return inst::new(self, object)
+        else
+          objects = Nokogiri::XML(get(@entry_points[method_name.to_s]))
+          objects_arr = []
+          element = method_name.to_s
+          # FIXME:
+          # This is an exception/or bug in RHEV-M API:
+          # (uri is /datacenters but root element it 'data_centers')
+          element = 'data_centers' if method_name.eql?(:datacenters)
+          element = 'storage_domains' if method_name.eql?(:storagedomains)
+          (objects/"#{element}/#{element.singularize}").each do |item|
+            inst = ::RHEVM.const_get(element.classify)
+            objects_arr << inst.new(self, item)
+          end
+          return objects_arr
+        end
+      end
+    end
+
+    def vm_action(action, vm)
+      response = post("#{@base_uri}/vms/#{vm}/%s" % action)
+      Nokogiri::XML(response)
+    end
+
+    def create_vm(opts="")
+      Nokogiri::XML(post("#{@base_uri}/vms", opts))
+    end
+
+    def delete_vm(id)
+      delete("#{@base_uri}/vms/#{id}")
+    end
+
+    def delete(uri)
+      headers = {
+        :authorization => "Basic " + Base64.encode64("#{@username}:#{@password}"),
+        :accept => 'application/xml',
+      }
+      RestClient.delete(uri, headers).to_s
+    end
+
+    def get(uri)
+      headers = {
+        :authorization => "Basic " + Base64.encode64("#{@username}:#{@password}"),
+        :accept => 'application/xml',
+      }
+      response = RestClient.get(uri, headers).to_s
+      response
+    end
+
+    def post(uri, params="")
+      headers = {
+        :authorization => "Basic " + Base64.encode64("#{@username}:#{@password}"),
+        :accept => 'application/xml',
+        :content_type => 'application/xml'
+      }
+      params = "<action/>" if params.size==0
+      response = RestClient.post(uri, params, headers).to_s
+      response
+    end
+
+    def discover_entry_points()
+      return if @discovered
+      doc = Nokogiri.XML(get(@base_uri))
+      doc.xpath('api/link').each() do |link|
+        @entry_points[link['rel']] = @host + link['href']
+      end
+      @discovered = true
+    end
+
+    private
+    
+    def singularize(str)
+      str.gsub(/s$/, '')
+    end
+
+  end
+
+  class BaseModel
+    attr_accessor(:id, :href, :name)
+
+    def initialize(client, xml)
+      @client = client
+      @id = xml[:id]
+      @href = "#{@client.base_uri}#{xml[:href]}"
+      @name = xml.xpath('name').text
+    end
+  end
+
+  class StorageDomain < BaseModel
+    attr_accessor(:status, :storage_type, :storage_address, :storage_path)
+    attr_accessor(:name, :available, :used, :kind)
+
+    def initialize(client, xml)
+      super(client, xml)
+      @kind = xml.xpath('type').text
+      @name = xml.xpath('name').text
+      @storage_type = xml.xpath('storage/type').text
+      @storage_address = xml.xpath('storage/address').text
+      @storage_path = xml.xpath('storage/path').text
+      @address = xml.xpath('storage/address').text
+      @available = xml.xpath('available').text.to_f
+      @used= xml.xpath('used').text.to_f
+    end
+  end
+
+  class Vm < BaseModel
+    attr_accessor(:status, :memory, :sockets, :cores, :bootdevs, :host, :cluster, :template,
:vmpool, :profile)
+    attr_accessor(:creation_time, :storage)
+
+    def initialize(client, xml)
+      super(client, xml)
+      @status = xml.xpath('status').text
+      @memory = xml.xpath('memory').text.to_f
+      @profile = xml.xpath('type').text
+      @sockets = xml.xpath('cpu/topology').first[:sockets] rescue ''
+      @cores = xml.xpath('cpu/topology').first[:cores] rescue ''
+      @bootdevs = []
+      xml.xpath('os/boot').each do |boot|
+        @bootdevs << boot[:dev]
+      end
+      @host = xml.xpath('host')[:id]
+      @cluster = xml.xpath('cluster').first[:id]
+      @template = xml.xpath('template').first[:id]
+      @vmpool = xml.xpath('vmpool').first[:id] if xml.xpath('vmpool').size >0
+      @creation_time = xml.xpath('creation_time').text
+      storage_link = xml.xpath('link[@rel="disks"]').first[:href]
+      disks_response = Nokogiri::XML(client.get("#{client.host}#{storage_link}"))
+      @storage = disks_response.xpath('disks/disk/size').collect { |s| s.text.to_f }
+      @storage = @storage.inject(nil) { |p, i| p ? p+i : i }
+    end
+  end
+
+  class Template < BaseModel
+    attr_accessor(:status, :memory, :name, :description)
+    
+    def initialize(client, xml)
+      super(client, xml)
+      @status = (xml/'status').text
+      @memory = (xml/'memory').text
+      @description = (xml/'description').text
+    end
+  end
+
+  class DataCenter < BaseModel
+    attr_accessor :name, :storage_type, :description, :status
+
+    def initialize(client, xml)
+      super(client, xml)
+      @name, @storage_type, @description = (xml/'name').text, (xml/'storage_type').text,
(xml/'description').text
+      @status = (xml/'status').text
+    end
+  end
+
+  class Cluster < BaseModel
+    attr_accessor :name, :datacenter_id, :cpu
+
+    def initialize(client, xml)
+      super(client, xml)
+      @name = (xml/'name').text
+      @datacenter_id = (xml/'data_center').first['id']
+      @cpu = (xml/'cpu').first['id']
+      @name = (xml/'name').text
+    end
+  end
+
+end
+
+class String
+
+  unless method_defined?(:classify)
+    # Create a class name from string
+    def classify
+      self.singularize.camelize
+    end
+  end
+
+  unless method_defined?(:camelize)
+    # Camelize converts strings to UpperCamelCase
+    def camelize
+      self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
+    end
+  end
+
+  unless method_defined?(:singularize)
+    # Strip 's' character from end of string
+    def singularize
+      self.gsub(/s$/, '')
+    end
+  end
+
+  # Convert string to float if string value seems like Float
+  def convert
+    return self.to_f if self.strip =~ /^([\d\.]+$)/
+    self
+  end
+
+  # Simply converts whitespaces and - symbols to '_' which is safe for Ruby
+  def sanitize
+    self.strip.gsub(/(\W+)/, '_')
+  end
+
+end
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index c33158e..af0a32e 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -16,8 +16,18 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+# Minihowto: Setting up this driver
+#
+# 1. Setup RHEV-M server
+# 2. Setup RHEV-M API (git://git.fedorahosted.org/rhevm-api.git - follow README)
+# 3. Set URL to API using shell variable (or HTTP header, see comment on provider_url)
+#    export API_PROVIDER="https://x.x.x.x/rhevm-api-powershell"
+# 4. Start Deltacloud using: deltacloudd -i rhevm
+# 5. Use RHEV-M credentials + append Windows Domain
+#    like: admin@rhevm.example.com
+
 require 'deltacloud/base_driver'
-require 'yaml'
+require 'deltacloud/drivers/rhevm/rhevm_client'
 
 module Deltacloud
   module Drivers
@@ -25,218 +35,262 @@ module Deltacloud
 
 class RHEVMDriver < Deltacloud::BaseDriver
 
-  SCRIPT_DIR = File.dirname(__FILE__) + '/scripts'
-  CONFIG = YAML.load_file(File.dirname(__FILE__) + '/../../../../config/rhevm_config.yml')
-  SCRIPT_DIR_ARG = '"' + SCRIPT_DIR + '"'
-  DELIM_BEGIN="<_OUTPUT>"
-  DELIM_END="</_OUTPUT>"
-  POWERSHELL="c:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
-  NO_OWNER=""
-
   feature :instances, :user_name
 
-  def supported_collections
-    DEFAULT_COLLECTIONS.reject { |c| [ :storage_volumes, :storage_snapshots ].include?(c)
}
-  end
-
-  #
-  # Execute a Powershell command, and convert the output
-  # to YAML in order to get back an array of maps.
+  # FIXME: These values are just for ilustration
+  # Also I choosed 'SERVER' and 'DESKTOP' names
+  # because they are referred by VM (API type)
   #
-  def execute(credentials, command, *args)
-    args = args.to_a
-    argString = genArgString(credentials, args)
-    puts argString
-    outputMaps = {}
-    output = `#{POWERSHELL} -command "&{#{File.join(SCRIPT_DIR, command)} #{argString};
exit $LASTEXITCODE}`
-    exitStatus = $?.exitstatus
-    puts(output)
-    puts("EXITSTATUS #{exitStatus}")
-    st = output.index(DELIM_BEGIN)
-    if (st)
-      st += DELIM_BEGIN.length
-      ed = output.index(DELIM_END)
-      output = output.slice(st, (ed-st))
-      # Lets make it yaml
-      output.strip!
-      if (output.length > 0)
-        outputMaps = YAML.load(self.toYAML(output))
-      end
-    end
-    outputMaps
+  # Values like RAM or STORAGE are reported by VM
+  # so they are not static.
+
+  define_hardware_profile 'SERVER' do
+    cpu         ( 1..4 )
+    memory      ( 512 .. 32*1024 )
+    storage     ( 1 .. 100*1024 )
+    architecture 'x86_64'
   end
 
-  def genArgString(credentials, args)
-    commonArgs = [SCRIPT_DIR_ARG, credentials.user, credentials.password, CONFIG["domain"]]
-    commonArgs.concat(args)
-    commonArgs.join(" ")
+  define_hardware_profile 'DESKTOP' do
+    cpu         ( 1..4 )
+    memory      ( 512 .. 32*1024 )
+    storage     ( 1 .. 100*1024 )
+    architecture 'x86_64'
   end
 
-  def toYAML(output)
-    yOutput = "- \n" + output
-    yOutput.gsub!(/^(\w*)[ ]*:[ ]*([A-Z0-9a-z._ -:{}]*)/,' \1: "\2"')
-    yOutput.gsub!(/^[ ]*$/,"- ")
-    puts(yOutput)
-    yOutput
+  # Instead of setting a URL for RHEV provider
+  # do it here in driver, so it can be altered by HTTP headers
+  #
+  def provider_uri=(uri)
+    @RHEVM_URI = uri
   end
 
-  def statify(state)
-    st = state.nil? ? "" : state.upcase()
-    case st
-    when "UP"
-      "RUNNING"
-    when "DOWN"
-      "STOPPED"
-    when "POWERING UP"
-      "PENDING"
-    end
+  # Default Provider URI.
+  #
+  # IMPORTANT:
+  # This URI can be overridden using shell variable API_PROVIDER
+  # or setting provider using HTTP header X-Deltacloud-Provider to URL.
+  #
+  def provider_uri
+    'https://10.34.2.122:8443/rhevm-api-powershell'
   end
 
-  define_hardware_profile 'rhevm'
+  define_instance_states do
+    start.to( :pending )          .automatically
+    pending.to( :running )        .automatically
+    pending.to( :stopped )        .automatically
+    pending.to( :finish )         .on(:destroy)
+    stopped.to( :running )        .on( :start )
+    stopped.to( :finish )         .on( :destroy )
+    running.to( :running )        .on( :reboot )
+    running.to( :stopping )       .on( :stop )
+    shutting_down.to( :stopped )  .automatically
+    stopped.to( :finish )         .automatically
+  end
 
   #
   # Realms
   #
 
   def realms(credentials, opts=nil)
-    domains = execute(credentials, "storageDomains.ps1")
-    if (!opts.nil? && opts[:id])
-        domains = domains.select{|d| opts[:id] == d["StorageId"]}
+    client = new_client(credentials)
+    realm_arr = []
+    safely do
+      clusters = client.clusters
+      clusters.each do |r|
+        d = client.datacenters(:id => r.datacenter_id)
+        realm_arr << convert_realm(r, d)
+      end
     end
+    realm_arr
+  end
 
-    realms = []
-    domains.each do |dom|
-      realms << domain_to_realm(dom)
+  def images(credentials, opts={})
+    client = new_client(credentials)
+    img_arr = []
+    safely do
+      templates = client.templates
+      if (!opts.nil? && opts[:id])
+        templates = templates.select{|t| opts[:id] == t.id}
+      end
+      templates.each do |t|
+        img_arr << convert_image(client, t)
+      end
     end
-    realms
+    img_arr = filter_on( img_arr, :architecture, opts )
+    img_arr.sort_by{|e| [e.owner_id, e.name]}
   end
 
-  def domain_to_realm(dom)
-    Realm.new({
-      :id => dom["StorageId"],
-      :name => dom["Name"],
-      :limit => dom["AvailableDiskSize"]
-    })
+  def instances(credentials, opts={})
+    client = new_client(credentials)
+    inst_arr = []
+    safely do
+      vms = client.vms
+      vms.each do |vm|
+        inst_arr << convert_instance(client, vm)
+      end
+    end
+    inst_arr = filter_on( inst_arr, :id, opts )
+    filter_on( inst_arr, :state, opts )
   end
 
+  def reboot_instance(credentials, id)
+    client = new_client(credentials)
+    safely do
+      client.vm_action(:reboot, id)
+    end
+  end
 
+  def start_instance(credentials, id)
+    client = new_client(credentials)
+    safely do
+      client.vm_action(:start, id)
+    end
+  end
 
-  #
-  # Images
-  #
+  def stop_instance(credentials, id)
+    client = new_client(credentials)
+    safely do
+      client.vm_action(:suspend, id)
+    end
+  end
 
-  def images(credentials, opts=nil )
-    templates = []
-    if (opts.nil?)
-      templates = execute(credentials, "templates.ps1")
-    else
-      if (opts[:id])
-        templates = execute(credentials, "templateById.ps1", opts[:id])
-      end
+  def destroy_instance(credentials, id)
+    client = new_client(credentials)
+    safely do
+      client.delete_vm(id)
     end
-    images = []
-    templates.each do |templ|
-      images << template_to_image(templ)
+  end
+
+  def storage_volumes(credentials, opts={})
+    client = new_client(credentials)
+    domains_arr = []
+    safely do
+      client.storagedomains.each do |s|
+        domains_arr << convert_volume(s)
+      end
     end
-    images
+    domains_arr = filter_on( domains_arr, :id, opts )
+    filter_on( domains_arr, :state, opts )
   end
 
-  def template_to_image(templ)
-    Image.new({
-      :id => templ["TemplateId"],
-      :name => templ["Name"],
-      :description => templ["Description"],
-      :architecture => templ["OperatingSystem"],
-      :owner_id => NO_OWNER,
-      :mem_size_md => templ["MemSizeMb"],
-      :instance_count => templ["ChildCount"],
-      :state => templ["Status"],
-      :capacity => templ["SizeGB"]
-    })
+  def create_instance(credentials, image_id, opts={})
+    client = new_client(credentials)
+    safely do
+      # TODO: Add setting CPU topology here
+      vm_name = opts[:name] ? "<name>#{opts[:name]}</name>" : ""
+      vm_template = "<template id='#{image_id}'/>"
+      vm_cluster = opts[:realm_id] ? "<cluster id='#{opts[:realm_id]}'/>" : "<cluster
id='0'/>"
+      vm_type = opts[:hwp_id] ? "<type>#{opts[:hwp_id]}</type>" : "<type>DESKTOP</type>"
+      # FIXME: Setting a memory from RHEV-API leads to Internal Server Error on
+      # RHEV-M API side
+      vm_memory = opts[:hwp_memory] ? "<memory>#{opts[:hwp_memory].to_i*1024}</memory>"
 : ''
+      # TODO: Add storage here (it isn't supported by RHEV-M API so far)
+      convert_instance(client, ::RHEVM::Vm::new(client, client.create_vm(
+        "<vm>"+
+        vm_name +
+        vm_template +
+        vm_cluster +
+        vm_type +
+        # vm_memory +
+        "</vm>"
+      ).xpath('vm')))
+    end
   end
 
-  #
-  # Instances
-  #
+  private
 
-  define_instance_states do
-    start.to(:stopped)            .on( :create )
+  def new_client(credentials)
+    url = (Thread.current[:provider] || ENV['API_PROVIDER'] || provider_uri)
+    ::RHEVM::Client.new(credentials.user, credentials.password, url)
+  end
 
-    pending.to(:shutting_down)    .on( :stop )
-    pending.to(:running)          .automatically
+  def convert_instance(client, inst)
+    state = convert_state(inst.status)
+    profile = InstanceProfile::new(inst.profile, 
+                                   :hwp_memory => inst.memory/1024,
+                                   :hwp_cpu => inst.cores,
+                                   :hwp_storage => "#{(inst.storage/1024/1024)}"
+    )
+    # TODO: Implement public_addresses (nics/ip)
+    # NOTE: This must be enabled on 'guest' side, otherwise this property is not
+    # available through RHEV-M API
+    Instance.new(
+      :id => inst.id,
+      :name => inst.name,
+      :state => state,
+      :image_id => inst.template,
+      :realm_id => inst.cluster,
+      :owner_id => client.username,
+      :launch_time => inst.creation_time,
+      :instance_profile => profile,
+      :hardware_profile_id => profile.id,
+      :actions=>instance_actions_for( state )
+    )
+  end
 
-    running.to(:pending)          .on( :reboot )
-    running.to(:shutting_down)    .on( :stop )
+  # STATES: 
+  #
+  # UNASSIGNED, DOWN, UP, POWERING_UP, POWERED_DOWN, PAUSED, MIGRATING_FROM, MIGRATING_TO,

+  # UNKNOWN, NOT_RESPONDING, WAIT_FOR_LAUNCH, REBOOT_IN_PROGRESS, SAVING_STATE, RESTORING_STATE,

+  # SUSPENDED, IMAGE_ILLEGAL, IMAGE_LOCKED or POWERING_DOWN 
+  #
+  def convert_state(state)
+    case state
+    when 'WAIT_FOR_LAUNCH', 'REBOOT_IN_PROGRESS', 'SAVING_STATE',
+      'RESTORING_STATE', 'POWERING_DOWN' then
+      'PENDING'
+    when 'UNASSIGNED', 'DOWN', 'POWERING_DOWN', 'PAUSED', 'NOT_RESPONDING', 'SAVING_STATE',

+      'SUSPENDED', 'IMAGE_ILLEGAL', 'IMAGE_LOCKED', 'UNKNOWN' then
+      'STOPPED'
+    when 'POWERING_UP', 'UP', 'MIGRATING_TO', 'MIGRATING_FROM'
+      'RUNNING'
+    end
+  end
 
-    shutting_down.to(:stopped)    .automatically
-    stopped.to(:pending)          .on( :start )
-    stopped.to(:finish)           .on( :destroy )
+  def convert_volume(volume)
+    StorageVolume.new(
+      :id => volume.id,
+      :state => 'AVAILABLE',
+      :capacity => ((volume.available-volume.used)/1024/1024).abs,
+      :instance_id => nil,
+      :kind => volume.kind,
+      :name => volume.name,
+      :device => "#{volume.storage_address}:#{volume.storage_path}"
+    )
   end
 
-  def instances(credentials, opts=nil)
-    vms = []
-    if (opts.nil?)
-      vms = execute(credentials, "vms.ps1")
-    else
-      if (opts[:id])
-        vms = execute(credentials, "vmById.ps1", opts[:id])
-      end
-    end
-    instances = []
-    vms.each do |vm|
-      instances << vm_to_instance(vm)
-    end
-    instances = filter_on( instances, :id, opts )
-    instances = filter_on( instances, :state, opts )
-    instances
-  end
-
-  def vm_to_instance(vm)
-    Instance.new({
-      :id => vm["VmId"],
-      :description => vm["Description"],
-      :name => vm["Name"],
-      :architecture => vm["OperatingSystem"],
-      :owner_id => NO_OWNER,
-      :image_id => vm["TemplateId"],
-      :state => statify(vm["Status"]),
-      :instance_profile => InstanceProfile.new("rhevm"),
-      :actions => instance_actions_for(statify(vm["Status"])),
-    })
-  end
-
-  def start_instance(credentials, image_id)
-    vm = execute(credentials, "startVm.ps1", image_id)
-    vm_to_instance(vm[0])
-  end
-
-  def stop_instance(credentials, image_id)
-    vm = execute(credentials, "stopVm.ps1", image_id)
-    vm_to_instance(vm[0])
-  end
-
-  def create_instance(credentials, image_id, opts)
-    name = opts[:name]
-    name = "Inst-#{rand(10000)}" if (name.nil? or name.empty?)
-    realm_id = opts[:realm_id]
-    if (realm_id.nil?)
-        realms = filter_on(realms(credentials, opts), :name, :name => "data")
-        puts realms[0]
-        realm_id = realms[0].id
-    end
-    vm = execute(credentials, "addVm.ps1", image_id, name, realm_id)
-    vm_to_instance(vm[0])
+  def convert_image(client, img)
+    Image.new(
+      :id => img.id,
+      :name => img.name,
+      :description => img.description,
+      :owner_id => client.username,
+      :architecture => 'x86_64', # All RHEV-M VMs are x86_64
+      :status => img.status
+    )
   end
 
-  def reboot_instance(credentials, image_id)
-    vm = execute(credentials, "rebootVm.ps1", image_id)
-    vm_to_instance(vm[0])
+  def convert_realm(r, dc)
+    Realm.new(
+      :id => r.id,
+      :name => dc.name,
+      :state => dc.status == 'UP' ? 'AVAILABLE' : 'DOWN',
+      :limit => :unlimited
+    )
   end
 
-  def destroy_instance(credentials, image_id)
-    vm = execute(credentials, "deleteVm.ps1", image_id)
-    vm_to_instance(vm[0])
+  # Disabling this error catching will lead to more verbose messages
+  # on console (eg. response from RHEV-M API (so far I didn't figure our
+  # how to pass those message to our exception handling tool)
+  def catched_exceptions_list
+    {
+      :auth => RestClient::Unauthorized,
+      :error => RestClient::InternalServerError,
+      :glob => [ /RestClient::(\w+)/ ]
+    }
   end
+
 end
 
     end
diff --git a/server/lib/deltacloud/drivers/rhevm/scripts/addVM.ps1 b/server/lib/deltacloud/drivers/rhevm/scripts/addVM.ps1
deleted file mode 100644
index 55dab0c..0000000
--- a/server/lib/deltacloud/drivers/rhevm/scripts/addVM.ps1
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Copyright (C) 2009  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-param([string]$scriptsDir,
-        [string]$username,
-        [string]$password,
-        [string]$domain,
-        [string]$templateId,
-        [string]$name,
-        [string]$storageId)
-# Get the common functions
-. "$scriptsDir\common.ps1"
-verifyLogin $username $password $domain
-$templ = get-template $templateId
-beginOutput
-add-vm -TemplateObject $templ -Name $name -StorageDomainId $storageId
-endOutput
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/rhevm/scripts/common.ps1 b/server/lib/deltacloud/drivers/rhevm/scripts/common.ps1
deleted file mode 100644
index 91d57d9..0000000
--- a/server/lib/deltacloud/drivers/rhevm/scripts/common.ps1
+++ /dev/null
@@ -1,33 +0,0 @@
-#
-# Copyright (C) 2009  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-$DELIM_BEGIN="<_OUTPUT>"
-$DELIM_END="</_OUTPUT>"
-$VM_PROPERTY_LIST="VmId", "Name", "Description", "TemplateId", "Domain", "Status", "OperatingSystem"
-function beginOutput {
-    echo $DELIM_BEGIN
-}
-
-function endOutput {
-    echo $DELIM_END
-}
-
-function verifyLogin {
-    param($username, $password, $domain)
-    Login-User $username $password $domain
-}
diff --git a/server/lib/deltacloud/drivers/rhevm/scripts/deleteVm.ps1 b/server/lib/deltacloud/drivers/rhevm/scripts/deleteVm.ps1
deleted file mode 100644
index fae745e..0000000
--- a/server/lib/deltacloud/drivers/rhevm/scripts/deleteVm.ps1
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# Copyright (C) 2009  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-param([string]$scriptsDir,
-        [string]$username,
-        [string]$password,
-        [string]$domain,
-        [string]$id)
-# Get the common functions
-. "$scriptsDir\common.ps1"
-verifyLogin $username $password $domain
-beginOutput
-# The AppliacationList causes the YAML pain, so Omit it
-remove-vm $id | format-list -Property $VM_PROPERTY_LIST
-endOutput
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/rhevm/scripts/rebootVm.ps1 b/server/lib/deltacloud/drivers/rhevm/scripts/rebootVm.ps1
deleted file mode 100644
index 49d00c5..0000000
--- a/server/lib/deltacloud/drivers/rhevm/scripts/rebootVm.ps1
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# Copyright (C) 2009  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-param([string]$scriptsDir,
-        [string]$username,
-        [string]$password,
-        [string]$domain,
-        [string]$id)
-# Get the common functions
-. "$scriptsDir\common.ps1"
-verifyLogin $username $password $domain
-# The AppliacationList causes the YAML pain, so Omit it
-stop-vm $id | format-list -Property $VM_PROPERTY_LIST
-beginOutput
-start-vm $id | format-list -Property $VM_PROPERTY_LIST
-endOutput
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/rhevm/scripts/startVm.ps1 b/server/lib/deltacloud/drivers/rhevm/scripts/startVm.ps1
deleted file mode 100644
index 79a137f..0000000
--- a/server/lib/deltacloud/drivers/rhevm/scripts/startVm.ps1
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# Copyright (C) 2009  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-param([string]$scriptsDir,
-        [string]$username,
-        [string]$password,
-        [string]$domain,
-        [string]$id)
-# Get the common functions
-. "$scriptsDir\common.ps1"
-verifyLogin $username $password $domain
-beginOutput
-# The AppliacationList causes the YAML pain, so Omit it
-start-vm $id | format-list -Property $VM_PROPERTY_LIST
-endOutput
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/rhevm/scripts/stopVm.ps1 b/server/lib/deltacloud/drivers/rhevm/scripts/stopVm.ps1
deleted file mode 100644
index 9943a78..0000000
--- a/server/lib/deltacloud/drivers/rhevm/scripts/stopVm.ps1
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# Copyright (C) 2009  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-param([string]$scriptsDir,
-        [string]$username,
-        [string]$password,
-        [string]$domain,
-        [string]$id)
-# Get the common functions
-. "$scriptsDir\common.ps1"
-verifyLogin $username $password $domain
-beginOutput
-# The AppliacationList causes the YAML pain, so Omit it
-stop-vm $id | format-list -Property $VM_PROPERTY_LIST
-endOutput
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/rhevm/scripts/storageDomains.ps1 b/server/lib/deltacloud/drivers/rhevm/scripts/storageDomains.ps1
deleted file mode 100644
index 63b5147..0000000
--- a/server/lib/deltacloud/drivers/rhevm/scripts/storageDomains.ps1
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# Copyright (C) 2009  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-param([string]$scriptsDir,
-        [string]$username,
-        [string]$password,
-        [string]$domain)
-# Get the common functions
-. "$scriptsDir\common.ps1"
-verifyLogin $username $password $domain
-beginOutput
-# The AppliacationList causes the YAML pain, so Omit it
-select-storagedomain *
-endOutput
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/rhevm/scripts/templateById.ps1 b/server/lib/deltacloud/drivers/rhevm/scripts/templateById.ps1
deleted file mode 100644
index a393d93..0000000
--- a/server/lib/deltacloud/drivers/rhevm/scripts/templateById.ps1
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# Copyright (C) 2009  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-param([string]$scriptsDir,
-        [string]$username,
-        [string]$password,
-        [string]$domain,
-        [string]$id)
-
-# Get the common functions
-. "$scriptsDir\common.ps1"
-verifyLogin $username $password $domain
-beginOutput
-get-template $id
-endOutput
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/rhevm/scripts/templates.ps1 b/server/lib/deltacloud/drivers/rhevm/scripts/templates.ps1
deleted file mode 100644
index caeb48c..0000000
--- a/server/lib/deltacloud/drivers/rhevm/scripts/templates.ps1
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Copyright (C) 2009  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-param([string]$scriptsDir,
-        [string]$username,
-        [string]$password,
-        [string]$domain)
-# Get the common functions
-. "$scriptsDir\common.ps1"
-verifyLogin $username $password $domain
-beginOutput
-select-template *
-endOutput
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/rhevm/scripts/vmById.ps1 b/server/lib/deltacloud/drivers/rhevm/scripts/vmById.ps1
deleted file mode 100644
index 4408adf..0000000
--- a/server/lib/deltacloud/drivers/rhevm/scripts/vmById.ps1
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# Copyright (C) 2009  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-param([string]$scriptsDir,
-        [string]$username,
-        [string]$password,
-        [string]$domain,
-        [string]$id)
-# Get the common functions
-. "$scriptsDir\common.ps1"
-verifyLogin $username $password $domain
-$vm = get-vm $id
-beginOutput
-# The AppliacationList causes the YAML pain, so Omit it
-$vm | format-list -Property $VM_PROPERTY_LIST
-endOutput
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/rhevm/scripts/vms.ps1 b/server/lib/deltacloud/drivers/rhevm/scripts/vms.ps1
deleted file mode 100644
index a083936..0000000
--- a/server/lib/deltacloud/drivers/rhevm/scripts/vms.ps1
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# Copyright (C) 2009  Red Hat, Inc.
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.  The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License.  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-param([string]$scriptsDir,
-        [string]$username,
-        [string]$password,
-        [string]$domain)
-# Get the common functions
-. "$scriptsDir\common.ps1"
-verifyLogin $username $password $domain
-beginOutput
-# The AppliacationList causes the YAML pain, so Omit it
-select-vm * | format-list -Property $VM_PROPERTY_LIST
-endOutput
\ No newline at end of file
-- 
1.7.3.3


Mime
View raw message