Class: Pooler
- Inherits:
-
Object
- Object
- Pooler
- Defined in:
- lib/vmfloaty/pooler.rb
Class Method Summary collapse
- .delete(verbose, url, hostnames) ⇒ Object
- .list(verbose, url, os_filter = nil) ⇒ Object
- .modify(verbose, url, hostname, token, lifetime, tags) ⇒ Object
- .query(verbose, url, hostname) ⇒ Object
- .retrieve(verbose, os_type, token, url) ⇒ Object
- .revert(verbose, url, hostname, token, snapshot_sha) ⇒ Object
- .snapshot(verbose, url, hostname, token) ⇒ Object
- .status(verbose, url) ⇒ Object
- .summary(verbose, url) ⇒ Object
Class Method Details
.delete(verbose, url, hostnames) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vmfloaty/pooler.rb', line 49 def self.delete(verbose, url, hostnames) if hostnames.nil? STDERR.puts "You did not provide any hosts to delete" exit 1 end hosts = hostnames.split(',') conn = Http.get_conn(verbose, url) hosts.each do |host| puts "Scheduling host #{host} for deletion" response = conn.delete "/vm/#{host}" res_body = JSON.parse(response.body) puts res_body end end |
.list(verbose, url, os_filter = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/vmfloaty/pooler.rb', line 6 def self.list(verbose, url, os_filter=nil) conn = Http.get_conn(verbose, url) response = conn.get '/vm' response_body = JSON.parse(response.body) if os_filter hosts = response_body.select { |i| i[/#{os_filter}/] } else hosts = response_body end hosts end |
.modify(verbose, url, hostname, token, lifetime, tags) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vmfloaty/pooler.rb', line 36 def self.modify(verbose, url, hostname, token, lifetime, ) modify_body = {'lifetime'=>lifetime, 'tags'=>} conn = Http.get_conn_with_token(verbose, url, token) conn.headers['X-AUTH-TOKEN'] response = conn.put do |req| req.url "/vm/#{hostname}" end res_body = JSON.parse(response.body) res_body end |
.query(verbose, url, hostname) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/vmfloaty/pooler.rb', line 82 def self.query(verbose, url, hostname) conn = Http.get_conn(verbose, url) response = conn.get "/vm/#{hostname}" res_body = JSON.parse(response.body) res_body end |
.retrieve(verbose, os_type, token, url) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vmfloaty/pooler.rb', line 21 def self.retrieve(verbose, os_type, token, url) os = os_type.gsub(',','+') if token.nil? conn = Http.get_conn(verbose, url) else conn = Http.get_conn_with_token(verbose, url, token) conn.headers['X-AUTH-TOKEN'] end response = conn.post "/vm/#{os}" res_body = JSON.parse(response.body) res_body end |
.revert(verbose, url, hostname, token, snapshot_sha) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/vmfloaty/pooler.rb', line 100 def self.revert(verbose, url, hostname, token, snapshot_sha) conn = Http.get_conn_with_token(verbose, url, token) conn.headers['X-AUTH-TOKEN'] response = conn.post "/vm/#{hostname}/snapshot/#{snapshot}" res_body = JSON.parse(response.body) res_body end |
.snapshot(verbose, url, hostname, token) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/vmfloaty/pooler.rb', line 91 def self.snapshot(verbose, url, hostname, token) conn = Http.get_conn_with_token(verbose, url, token) conn.headers['X-AUTH-TOKEN'] response = conn.post "/vm/#{hostname}/snapshot" res_body = JSON.parse(response.body) res_body end |