[Ovirt-devel] [PATCH server 2/8] Remove client/ directory, it will live in its own repo
David Lutterkort
lutter at redhat.com
Mon Feb 2 20:35:31 UTC 2009
---
client/README | 17 -------
client/examples/script.rb | 101 --------------------------------------------
client/lib/ovirt.rb | 102 ---------------------------------------------
3 files changed, 0 insertions(+), 220 deletions(-)
delete mode 100644 client/README
delete mode 100755 client/examples/script.rb
delete mode 100644 client/lib/ovirt.rb
diff --git a/client/README b/client/README
deleted file mode 100644
index ee1db15..0000000
--- a/client/README
+++ /dev/null
@@ -1,17 +0,0 @@
-This is a very simple client library for accessing the OVirt API from Ruby.
-
-The file examples/script.rb contains a script that shows how this is done
-in some detail.
-
-You must have ActiveResource installed, e.g. with 'yum install
-rubygem-activeresource'
-
-The server is specified with a URL of the form
- http://USER:PASSWORD@HOST/ovirt
-
-This requires that the server is configured to allow HTTP authentication,
-since there are no mechanisms in the API to forward krb5 tickets.
-
-Before calling any other method on the API, you need to call
- OVirt::Base::site = "http://USER:PASSWORD@HOST/ovirt"
- OVirt::Base::login
diff --git a/client/examples/script.rb b/client/examples/script.rb
deleted file mode 100755
index 1485535..0000000
--- a/client/examples/script.rb
+++ /dev/null
@@ -1,101 +0,0 @@
-#! /usr/bin/ruby
-
-# Sample script that shows how to use the OVirt API
-
-require 'pp'
-require 'rubygems'
-require 'activeresource'
-require 'optparse'
-
-require 'ovirt'
-
-def move_random_host(hosts, pool)
- host = hosts[rand(hosts.size)]
- puts "Move #{host.hostname} to #{pool.name}"
- pool.hosts << host
- pool.save
-end
-
-def element_path(obj)
- "[#{obj.class.element_path(obj.id)}]"
-end
-
-def print_pool(pool)
- puts "\n\nPool #{pool.name}: #{pool.hosts.size} hosts, #{pool.storage_pools.size} storage pools #{element_path(pool)} "
- puts "=" * 75
- pool.hosts.each do |h|
- printf "%-36s %s\n", h.hostname, element_path(h)
- end
- pool.storage_pools.each do |sp|
- type = sp.nfs? ? "NFS" : "iSCSI"
- printf "%-5s %-30s %s\n", type, sp.label, element_path(sp)
- end
- puts "-" * 75
-end
-
-# Plumbing so we can find the OVirt server
-# "http://ovirt.watzmann.net:3000/ovirt/rest"
-PROGNAME=File::basename($0)
-OVirt::Base.site = ENV["OVIRT_SERVER"]
-opts = OptionParser.new("#{PROGNAME} GLOBAL_OPTS")
-opts.separator(" Run some things against an OVirt server. The server is specified with")
-opts.separator(" the -s option as a URL of the form http://USER:PASSWORD@SERVER/ovirt")
-opts.separator("")
-opts.separator "Global options:"
-opts.on("-s", "--server=URL", "The OVirt server. Since there is no auth\n" +
- "#{" "*37}yet, must be the mongrel server port.\n" +
- "#{" "*37}Overrides env var OVIRT_SERVER") do |val|
- OVirt::Base.site = val
-end
-
-opts.order(ARGV)
-
-unless OVirt::Base.site
- $stderr.puts <<EOF
-You must specify the OVirt server to connect to, either with the
---server option or through the OVIRT_SERVER environment variable
-EOF
- exit 1
-end
-
-OVirt::Base.login
-
-# Get a single host by name
-host = OVirt::Host.find_by_hostname("node3.priv.ovirt.org")
-puts "#{host.uuid} has id #{host.id}"
-
-# What's in the default pool
-defpool = OVirt::HardwarePool.default_pool
-print_pool(defpool)
-
-# Create a new hardware pool
-mypool = OVirt::HardwarePool.find_by_path("/default/mypool")
-unless mypool
- puts "Create mypool"
- mypool = OVirt::HardwarePool.create( { :parent_id => defpool.id,
- :name => "mypool" } )
-end
-
-# Move some hosts around
-puts
-if defpool.hosts.size > 1
- move_random_host(defpool.hosts, mypool)
-elsif mypool.hosts.size > 0
- move_random_host(mypool.hosts, defpool)
-end
-
-# Delete all storage pools for mypool and add a new one
-mypool.storage_pools.each do |sp|
- puts "Delete storage pool #{sp.id}"
- sp.destroy
-end
-
-storage_pool = OVirt::StoragePool.create( { :storage_type => "NFS",
- :hardware_pool_id => mypool.id,
- :ip_addr => "192.168.122.50",
- :export_path => "/exports/pool1" } )
-puts "Created storage pool #{storage_pool.id}"
-
-# For some reason, mypool.reload doesn't work here
-mypool = OVirt::HardwarePool.find_by_path("/default/mypool")
-print_pool(mypool)
diff --git a/client/lib/ovirt.rb b/client/lib/ovirt.rb
deleted file mode 100644
index 15dc467..0000000
--- a/client/lib/ovirt.rb
+++ /dev/null
@@ -1,102 +0,0 @@
-require 'pp'
-require 'rubygems'
-require 'activeresource'
-
-class ActiveResource::Connection
- attr_accessor :session
-
- alias_method :old_default_header, :default_header
-
- def default_header
- old_default_header
- @default_header ||= {}
- if session
- @default_header["Cookie"] = session
- end
- @default_header
- end
-end
-
-module OVirt
- class Base < ActiveResource::Base
- LOGIN_PATH = "login/login"
-
- def self.login
- response = nil
- begin
- response = connection.get(prefix + LOGIN_PATH)
- rescue ActiveResource::Redirection => e
- response = e.response
- end
- unless connection.session = session_cookie(response)
- raise "Authentication failed"
- end
- end
-
- private
- def self.session_cookie(response)
- if cookies = response.get_fields("Set-Cookie")
- cookies.find { |cookie|
- cookie.split(";")[0].split("=")[0] == "_ovirt_session_id"
- }
- end
- end
-
- end
-
- class HardwarePool < Base
- def self.find_by_path(path)
- find(:first, :params => { :path => path })
- end
-
- def self.default_pool
- find(:first, :params => { :path => "/default" })
- end
- end
-
- class StoragePool < Base
- def iscsi?
- attributes["type"] == "IscsiStoragePool"
- end
-
- def nfs?
- attributes["type"] == "NfsStoragePool"
- end
-
- def label
- if iscsi?
- "#{ip_addr}:#{port}:#{target}"
- elsif nfs?
- "#{ip_addr}:#{export_path}"
- else
- raise "Unknown type #{attributes["type"]}"
- end
- end
- end
-
- class IscsiStoragePool < StoragePool
- def initialize(attributes = {})
- super(attributes.update( "type" => "IscsiStoragePool" ))
- end
- end
-
- class NfsStoragePool < StoragePool
- def initialize(attributes = {})
- super(attributes.update( "type" => "NfsStoragePool" ))
- end
- end
-
- class Host < Base
- def self.find_by_uuid(uuid)
- find(:first, :params => { :uuid => uuid })
- end
-
- def self.find_by_hostname(hostname)
- find(:first, :params => { :hostname => hostname })
- end
-
- def hardware_pool
- HardwarePool.find(hardware_pool_id)
- end
- end
-end
--
1.6.0.6
More information about the ovirt-devel
mailing list