Class: Pooler

Inherits:
Object
  • Object
show all
Defined in:
lib/vmfloaty/pooler.rb

Class Method Summary collapse

Class Method Details

.delete(verbose, url, hosts, token) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/vmfloaty/pooler.rb', line 81

def self.delete(verbose, url, hosts, token)
  conn = Http.get_conn(verbose, url)

  if token
    conn.headers['X-AUTH-TOKEN'] = token
  end

  hosts.each do |host|
    puts "Scheduling host #{host} for deletion"
    response = conn.delete "vm/#{host}"
    res_body = JSON.parse(response.body)
    if res_body['ok']
      puts "Deletion for vm #{host} successfully scheduled"
    else
      STDERR.puts "There was a problem with your request for vm #{host}."
      STDERR.puts res_body
    end
  end
end

.disk(verbose, url, hostname, token, disk) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/vmfloaty/pooler.rb', line 71

def self.disk(verbose, url, hostname, token, disk)
  conn = Http.get_conn(verbose, url)
  conn.headers['X-AUTH-TOKEN'] = token

  response = conn.post "vm/#{hostname}/disk/#{disk}"

  res_body = JSON.parse(response.body)
  res_body
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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/vmfloaty/pooler.rb', line 50

def self.modify(verbose, url, hostname, token, lifetime, tags)
  modify_body = {}
  if lifetime
    modify_body['lifetime'] = lifetime
  end
  if tags
    modify_body['tags'] = tags
  end

  conn = Http.get_conn(verbose, url)
  conn.headers['X-AUTH-TOKEN'] = token

  response = conn.put do |req|
    req.url "vm/#{hostname}"
    req.body = modify_body.to_json
  end

  res_body = JSON.parse(response.body)
  res_body
end

.query(verbose, url, hostname) ⇒ Object



117
118
119
120
121
122
123
124
# File 'lib/vmfloaty/pooler.rb', line 117

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vmfloaty/pooler.rb', line 21

def self.retrieve(verbose, os_type, token, url)
  conn = Http.get_conn(verbose, url)
  if token
    conn.headers['X-AUTH-TOKEN'] = token
  end

  os_string = ""
  os_type.each do |os,num|
    num.times do |i|
      os_string << os+"+"
    end
  end

  os_string = os_string.chomp("+")

  if os_string.size == 0
    raise "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs."
  end

  response = conn.post "vm/#{os_string}"

  res_body = JSON.parse(response.body)
  if res_body["ok"]
    res_body
  else
    raise "Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. #{res_body}"
  end
end

.revert(verbose, url, hostname, token, snapshot_sha) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/vmfloaty/pooler.rb', line 135

def self.revert(verbose, url, hostname, token, snapshot_sha)
  conn = Http.get_conn(verbose, url)
  conn.headers['X-AUTH-TOKEN'] = token

  response = conn.post "vm/#{hostname}/snapshot/#{snapshot_sha}"
  res_body = JSON.parse(response.body)
  res_body
end

.snapshot(verbose, url, hostname, token) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/vmfloaty/pooler.rb', line 126

def self.snapshot(verbose, url, hostname, token)
  conn = Http.get_conn(verbose, url)
  conn.headers['X-AUTH-TOKEN'] = token

  response = conn.post "vm/#{hostname}/snapshot"
  res_body = JSON.parse(response.body)
  res_body
end

.status(verbose, url) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/vmfloaty/pooler.rb', line 101

def self.status(verbose, url)
  conn = Http.get_conn(verbose, url)

  response = conn.get '/status'
  res_body = JSON.parse(response.body)
  res_body
end

.summary(verbose, url) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/vmfloaty/pooler.rb', line 109

def self.summary(verbose, url)
  conn = Http.get_conn(verbose, url)

  response = conn.get '/summary'
  res_body = JSON.parse(response.body)
  res_body
end