rbovirt 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rbovirt might be problematic. Click here for more details.

data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/lib/ovirt/disk.rb ADDED
@@ -0,0 +1,41 @@
1
+ module OVIRT
2
+
3
+ class Disk < BaseObject
4
+ attr_reader :size, :disk_type, :bootable, :interface, :format, :sparse, :storage_domain, :vm
5
+
6
+ def initialize(client, xml)
7
+ super(client, xml[:id], xml[:href], (xml/'name').first.text)
8
+ parse_xml_attributes!(xml)
9
+ self
10
+ end
11
+
12
+ def self.to_xml(storage_domain_id,opts={})
13
+ builder = Nokogiri::XML::Builder.new do
14
+ disk_{
15
+ storage_domains_{
16
+ storage_domain_(:id => storage_domain_id)
17
+ }
18
+ size_(opts[:size] || 8589934592)
19
+ type_(opts[:type] || 'system')
20
+ bootable_(opts[:bootable] || 'true')
21
+ interface_(opts[:interface] || 'virtio')
22
+ format_(opts[:format] || 'cow')
23
+ sparse_(opts[:sparse] || 'true')
24
+ }
25
+ end
26
+ Nokogiri::XML(builder.to_xml).root.to_s
27
+ end
28
+
29
+ def parse_xml_attributes!(xml)
30
+ @storage_domain = (xml/'storage_domains/storage_domain').first[:id]
31
+ @size = (xml/'size').first.text
32
+ @disk_type = (xml/'type').first.text
33
+ @bootable = (xml/'bootable').first.text
34
+ @interface = (xml/'interface').first.text
35
+ @format = (xml/'format').first.text
36
+ @sparse = (xml/'sparse').first.text
37
+ @vm = Link::new(@client, (xml/'vm').first[:id], (xml/'vm').first[:href])
38
+ end
39
+
40
+ end
41
+ end
data/lib/ovirt/nic.rb ADDED
@@ -0,0 +1,33 @@
1
+ module OVIRT
2
+
3
+ class Nic < BaseObject
4
+ attr_reader :name, :mac, :interface, :network, :vm
5
+
6
+ def initialize(client, xml)
7
+ super(client, xml[:id], xml[:href], (xml/'name').first.text)
8
+ parse_xml_attributes!(xml)
9
+ self
10
+ end
11
+
12
+ def self.to_xml(opts={})
13
+ builder = Nokogiri::XML::Builder.new do
14
+ nic{
15
+ name_(opts[:name] || 'eth0')
16
+ network{
17
+ name_(opts[:network] || 'ovirtmgmt')
18
+ }
19
+ }
20
+ end
21
+ Nokogiri::XML(builder.to_xml).root.to_s
22
+ end
23
+
24
+ def parse_xml_attributes!(xml)
25
+ @name = (xml/'name').first.text
26
+ @mac = (xml/'mac').first[:address]
27
+ @interface = (xml/'interface').first.text
28
+ @network = (xml/'network').first[:id]
29
+ @vm = Link::new(@client, (xml/'vm').first[:id], (xml/'vm').first[:href])
30
+ end
31
+
32
+ end
33
+ end
data/lib/ovirt/vm.rb CHANGED
@@ -4,17 +4,20 @@ module OVIRT
4
4
  FILEINJECT_PATH = "user-data.txt"
5
5
 
6
6
  class VM < BaseObject
7
- attr_reader :description, :status, :memory, :profile, :display, :host, :cluster, :template, :macs
8
- attr_reader :storage, :cores, :username, :creation_time
9
- attr_reader :ip, :vnc
7
+ attr_reader :description, :status, :memory, :profile, :display, :host, :cluster, :template, :nics
8
+ attr_reader :storage, :cores, :creation_time, :os, :ip, :vnc
9
+ attr_accessor :nics, :disks
10
10
 
11
11
  def initialize(client, xml)
12
12
  super(client, xml[:id], xml[:href], (xml/'name').first.text)
13
- @username = client.credentials[:username]
14
13
  parse_xml_attributes!(xml)
15
14
  self
16
15
  end
17
16
 
17
+ def running?
18
+ @status =~ /up/i
19
+ end
20
+
18
21
  def self.to_xml(template_name, cluster_name, opts={})
19
22
  builder = Nokogiri::XML::Builder.new do
20
23
  vm{
@@ -50,39 +53,11 @@ module OVIRT
50
53
  Nokogiri::XML(builder.to_xml).root.to_s
51
54
  end
52
55
 
53
- def self.disk_xml(storage_domain_id,opts={})
54
- builder = Nokogiri::XML::Builder.new do
55
- disk_{
56
- storage_domains_{
57
- storage_domain_(:id => storage_domain_id)
58
- }
59
- size_(opts[:size] || 8589934592)
60
- type_(opts[:type] || 'system')
61
- bootable_(opts[:bootable] || 'true')
62
- interface_(opts[:interface] || 'virtio')
63
- format_(opts[:format] || 'cow')
64
- sparse_(opts[:sparse] || 'true')
65
- }
66
- end
67
- Nokogiri::XML(builder.to_xml).root.to_s
68
- end
69
-
70
- def self.nic_xml(opts={})
71
- builder = Nokogiri::XML::Builder.new do
72
- nic{
73
- name_(opts[:name] || 'eth0')
74
- network{
75
- name_(opts[:network] || 'ovirtmgmt')
76
- }
77
- }
78
- end
79
- Nokogiri::XML(builder.to_xml).root.to_s
80
- end
81
56
  private
82
57
 
83
58
  def parse_xml_attributes!(xml)
84
59
  @description = ((xml/'description').first.text rescue '')
85
- @status = (xml/'status').first.text
60
+ @status = ((xml/'status').first.text rescue 'unknown')
86
61
  @memory = (xml/'memory').first.text
87
62
  @profile = (xml/'type').first.text
88
63
  @template = Link::new(@client, (xml/'template').first[:id], (xml/'template').first[:href])
@@ -96,13 +71,16 @@ module OVIRT
96
71
  }
97
72
  @cores = ((xml/'cpu/topology').first[:cores] rescue nil)
98
73
  @storage = ((xml/'disks/disk/size').first.text rescue nil)
99
- @macs = (xml/'nics/nic/mac').collect { |mac| mac[:address] }
100
74
  @creation_time = (xml/'creation_time').text
101
75
  @ip = ((xml/'guest_info/ip').first[:address] rescue nil)
102
76
  @vnc = {
103
77
  :address => ((xml/'display/address').first.text rescue "127.0.0.1"),
104
78
  :port => ((xml/'display/port').first.text rescue "5890")
105
79
  } unless @ip
80
+ @os = {
81
+ :type => (xml/'os').first[:type],
82
+ :boot => (xml/'os/boot').collect {|boot| boot[:dev] }
83
+ }
106
84
  end
107
85
 
108
86
  end
data/lib/rbovirt.rb CHANGED
@@ -5,6 +5,8 @@ require "ovirt/host"
5
5
  require "ovirt/storage_domain"
6
6
  require "ovirt/template"
7
7
  require "ovirt/vm"
8
+ require "ovirt/disk"
9
+ require "ovirt/nic"
8
10
 
9
11
  require "nokogiri"
10
12
  require "rest_client"
@@ -33,16 +35,22 @@ module OVIRT
33
35
  @api_entrypoint = api_entrypoint
34
36
  end
35
37
 
36
- def vm(vm_id)
38
+ def vm(vm_id, opts={})
37
39
  headers = {:accept => "application/xml; detail=disks; detail=nics; detail=hosts"}
38
- vm = http_get("/vms/%s" % vm_id, headers).root
39
- OVIRT::VM::new(self, vm)
40
+ vm = OVIRT::VM::new(self, http_get("/vms/%s" % vm_id, headers).root)
41
+ vm.nics = http_get("/vms/%s/nics" % vm_id, headers).xpath('/nics/nic').collect do |nic|
42
+ OVIRT::Nic::new(self, nic)
43
+ end if opts[:nics]
44
+ vm.disks = http_get("/vms/%s/disks" % vm_id, headers).xpath('/disks/disk').collect do |disk|
45
+ OVIRT::Disk::new(self, disk)
46
+ end if opts[:disks]
47
+ vm
40
48
  end
41
49
 
42
50
  def vms(opts={})
43
51
  headers = {:accept => "application/xml; detail=disks; detail=nics; detail=hosts"}
44
- search= opts[:search] || ("datacenter=$s" % current_datacenter.name)
45
- http_get("/vms?search=%s" % search, headers).xpath('/vms/vm').collect do |vm|
52
+ search= opts[:search] || ("datacenter=%s" % current_datacenter.name)
53
+ http_get("/vms?search=%s" % CGI.escape(search), headers).xpath('/vms/vm').collect do |vm|
46
54
  OVIRT::VM::new(self, vm)
47
55
  end
48
56
  end
@@ -78,12 +86,12 @@ module OVIRT
78
86
 
79
87
  def add_disk(vm_id, opts={})
80
88
  storage_domain_id = opts[:storage_domain] || storagedomains.first.id
81
- result_xml = http_post("/vms/%s/disks" % vm_id, VM.disk_xml(storage_domain_id, opts))
89
+ result_xml = http_post("/vms/%s/disks" % vm_id, OVIRT::Disk.to_xml(storage_domain_id, opts))
82
90
  end
83
91
 
84
92
 
85
93
  def add_nic(vm_id, opts={})
86
- http_post("/vms/%s/nics" % vm_id, VM.nic_xml( opts))
94
+ http_post("/vms/%s/nics" % vm_id, OVIRT::Nic.to_xml( opts))
87
95
  end
88
96
 
89
97
  def create_template(vm_id, opts)
data/rbovirt.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rbovirt}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Amos Benari"]
12
- s.date = %q{2012-01-16}
12
+ s.date = %q{2012-01-18}
13
13
  s.description = %q{A Ruby client for oVirt REST API}
14
14
  s.email = %q{abenari@redhat.com}
15
15
  s.extra_rdoc_files = [
@@ -26,7 +26,9 @@ Gem::Specification.new do |s|
26
26
  "lib/ovirt/base_object.rb",
27
27
  "lib/ovirt/cluster.rb",
28
28
  "lib/ovirt/datacenter.rb",
29
+ "lib/ovirt/disk.rb",
29
30
  "lib/ovirt/host.rb",
31
+ "lib/ovirt/nic.rb",
30
32
  "lib/ovirt/storage_domain.rb",
31
33
  "lib/ovirt/template.rb",
32
34
  "lib/ovirt/vm.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbovirt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Amos Benari
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-16 00:00:00 +02:00
18
+ date: 2012-01-18 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -125,7 +125,9 @@ files:
125
125
  - lib/ovirt/base_object.rb
126
126
  - lib/ovirt/cluster.rb
127
127
  - lib/ovirt/datacenter.rb
128
+ - lib/ovirt/disk.rb
128
129
  - lib/ovirt/host.rb
130
+ - lib/ovirt/nic.rb
129
131
  - lib/ovirt/storage_domain.rb
130
132
  - lib/ovirt/template.rb
131
133
  - lib/ovirt/vm.rb