archipel-api 3 → 4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 027c7f37fbabd9081fbd5232d9ad976e036b923b
4
- data.tar.gz: 1ed8f3692c9ed43f49214dcfc29708244b2dc1d7
3
+ metadata.gz: 475d4a92a09d54d426ca4a446c4aad744e40df33
4
+ data.tar.gz: 622401326c20d369a4689a5d018db531604c2407
5
5
  SHA512:
6
- metadata.gz: e20c1dc3a83ef3c8c4edba618d4f2b80c7c7d750512d12ed04972903ab4a90afa3e0d9a52d5ecf308db4f0844c485403b4796fa976a90d3f8317e0d9ee2bacc6
7
- data.tar.gz: a2c40450ff293b858dba791d5aa4bc2f6a962e14d1525aae321be6ace6f87de6738dbf5faf941cc1a665d1e82b665bb9f146d9cd7228310fd499ade36f6f6df2
6
+ metadata.gz: 39a0875d3a497ccab74d9a7e37e35d796da10da408ad17b983893018d4a425c1fdec0fdedc2efcc3b8c445828a26e6b6494e093d35c6dd5701ebb789bfd34f92
7
+ data.tar.gz: abe4a90afbc1095f02f3dd7b0756bfe0b00a16a7739ed80b353d98da272045da21c293daa1899a429fa63103d53f07d31e289a40662a560214bc0bb69270438b
@@ -1,7 +1,7 @@
1
1
  module Archipel
2
2
  module Api
3
3
  module Internal
4
- VERSION = '3'
4
+ VERSION = '4'
5
5
  end
6
6
  end
7
7
  end
@@ -50,10 +50,27 @@ class Archipel::Api::Internal::VmXmlMessages
50
50
  enabled_permissions: [], disabled_permissions: disabled
51
51
  end
52
52
 
53
+ def info jid
54
+ render 'info', jid: jid, uuid: uuid_from_jid(jid)
55
+ end
56
+
57
+ def autostart jid, new_state
58
+ render 'autostart', jid: jid, uuid: uuid_from_jid(jid),
59
+ new_state: new_state
60
+ end
61
+
53
62
  def start jid
54
63
  render 'start', jid: jid, uuid: uuid_from_jid(jid)
55
64
  end
56
65
 
66
+ def stop jid
67
+ render 'stop', jid: jid, uuid: uuid_from_jid(jid)
68
+ end
69
+
70
+ def force_stop jid
71
+ render 'force_stop', jid: jid, uuid: uuid_from_jid(jid)
72
+ end
73
+
57
74
  def xml jid
58
75
  render 'xml', jid: jid, uuid: uuid_from_jid(jid)
59
76
  end
@@ -0,0 +1,3 @@
1
+ <query xmlns="archipel:vm:control">
2
+ <%= tag :archipel, action: 'autostart', value: new_state ? 1 : 0 %>
3
+ </query>
@@ -0,0 +1,3 @@
1
+ <query xmlns="archipel:vm:control">
2
+ <archipel action="destroy"/>
3
+ </query>
@@ -0,0 +1,3 @@
1
+ <query xmlns="archipel:vm:control">
2
+ <archipel action="info" />
3
+ </query>
@@ -0,0 +1,3 @@
1
+ <query xmlns="archipel:vm:control">
2
+ <archipel action="shutdown"/>
3
+ </query>
@@ -0,0 +1,56 @@
1
+ require 'ostruct'
2
+ require 'active_support/core_ext/numeric/bytes'
3
+
4
+
5
+ class VmInfo
6
+ class State
7
+ attr_accessor :value, :name
8
+ @@index = {}
9
+
10
+ def initialize value, name
11
+ @value, @name = value, name
12
+ @@index[value] = self
13
+ end
14
+
15
+ STARTED = new 1, 'started'
16
+ STOPPED = new 5, 'stopped'
17
+
18
+ class << self
19
+ private :new
20
+ end
21
+
22
+ def method_missing method, *args
23
+ if method[-1] == '?'
24
+ method[0..-2] == name
25
+ else
26
+ super
27
+ end
28
+ end
29
+
30
+ def to_s
31
+ "VM state: #{name} (#{value})"
32
+ end
33
+
34
+ def self.from_int value
35
+ @@index[value]
36
+ end
37
+ end
38
+
39
+
40
+ attr_reader :state
41
+ attr_reader :autostart
42
+ attr_reader :memory, :memory_max
43
+ attr_reader :cpu_usage, :cpu_number
44
+
45
+ def initialize state, autostart, memory_kib, memory_max_kib, cpu_usage, cpu_number
46
+ pp state
47
+ @state = State.from_int state.to_i
48
+ @autostart = autostart.to_i == 0 ? false : true
49
+
50
+ @memory = memory_kib.to_i * 1024
51
+ @memory_max = memory_max_kib.to_i * 1024
52
+
53
+ @cpu_usage = cpu_usage.to_i
54
+ @cpu_number = cpu_number.to_i
55
+ end
56
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative 'internal/api'
2
2
  require_relative 'internal/vm_xml_messages'
3
+ require_relative 'vm/vm_info'
3
4
 
4
5
 
5
6
  class Archipel::Api::VmApi < Archipel::Api::Internal::Api
@@ -28,6 +29,24 @@ class Archipel::Api::VmApi < Archipel::Api::Internal::Api
28
29
  out['query'][0]['domain'][0]
29
30
  end
30
31
 
32
+ def info jid
33
+ out = method_missing :info, jid
34
+ resp = out['query'][0]['info'][0]
35
+ pp resp
36
+ VmInfo.new resp['state'], resp['autostart'],
37
+ resp['memory'], resp['maxMem'],
38
+ resp['cpuPrct'], resp['nrVirtCpu']
39
+ end
40
+
41
+ # Set autostart to new_state; read autostart state when new_state is not given
42
+ def autostart jid, new_state = nil
43
+ if new_state.nil?
44
+ info(jid).autostart
45
+ else
46
+ method_missing :autostart, jid, new_state
47
+ end
48
+ end
49
+
31
50
  def method_missing symbol, *args
32
51
  to = args[0]
33
52
  xml = @api.send symbol, *args
data/lib/archipel/api.rb CHANGED
@@ -3,8 +3,9 @@ module Archipel
3
3
  module Internal
4
4
  end
5
5
 
6
- def self.defaults login: nil, password: nil, server: nil, hypervisor: nil, ** kwargs
6
+ def self.defaults login: nil, password: nil, server: nil, hypervisor: nil, **kwargs
7
7
  @config = {login: login, password: password, server: server, hypervisor: hypervisor}
8
+ @config.merge! kwargs
8
9
  end
9
10
 
10
11
  def self.get_defaults
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archipel-api
3
3
  version: !ruby/object:Gem::Version
4
- version: '3'
4
+ version: '4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Nowak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-16 00:00:00.000000000 Z
11
+ date: 2014-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -129,15 +129,20 @@ files:
129
129
  - lib/archipel/api/internal/xml/hypervisor/register_user.xml.erb
130
130
  - lib/archipel/api/internal/xml/hypervisor/unregister_user.xml.erb
131
131
  - lib/archipel/api/internal/xml/todo/clone_vm.xml.erb
132
+ - lib/archipel/api/internal/xml/vm/autostart.xml.erb
132
133
  - lib/archipel/api/internal/xml/vm/create_disk.xml.erb
133
134
  - lib/archipel/api/internal/xml/vm/define_vm.xml.erb
135
+ - lib/archipel/api/internal/xml/vm/force_stop.xml.erb
134
136
  - lib/archipel/api/internal/xml/vm/grant_permissions.xml.erb
137
+ - lib/archipel/api/internal/xml/vm/info.xml.erb
135
138
  - lib/archipel/api/internal/xml/vm/list_disks.xml.erb
136
139
  - lib/archipel/api/internal/xml/vm/remove_disk.xml.erb
137
140
  - lib/archipel/api/internal/xml/vm/start.xml.erb
141
+ - lib/archipel/api/internal/xml/vm/stop.xml.erb
138
142
  - lib/archipel/api/internal/xml/vm/subscribe.xml.erb
139
143
  - lib/archipel/api/internal/xml/vm/xml.xml.erb
140
144
  - lib/archipel/api/internal/xml_messages.rb
145
+ - lib/archipel/api/vm/vm_info.rb
141
146
  - lib/archipel/api/vm_api.rb
142
147
  homepage: https://bitbucket.org/stratushost/ruby-archipel-api
143
148
  licenses: