Class: Service
- Inherits:
-
Object
show all
- Defined in:
- lib/vmfloaty/service.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#delete(verbose, hosts) ⇒ Object
-
#delete_token(verbose, token_value = ) ⇒ Object
-
#disk(verbose, hostname, disk) ⇒ Object
-
#get_new_token(verbose) ⇒ Object
-
#initialize(options, config_hash = {}) ⇒ Service
constructor
A new instance of Service.
-
#list(verbose, os_filter = nil) ⇒ Object
-
#list_active(verbose) ⇒ Object
-
#method_missing(m, *args, &block) ⇒ Object
-
#modify(verbose, hostname, modify_hash) ⇒ Object
-
#pretty_print_running(verbose, hostnames = []) ⇒ Object
-
#query(verbose, hostname) ⇒ Object
-
#retrieve(verbose, os_types, use_token = true) ⇒ Object
-
#revert(verbose, hostname, snapshot_sha) ⇒ Object
-
#snapshot(verbose, hostname) ⇒ Object
-
#ssh(verbose, host_os, use_token = true) ⇒ Object
-
#status(verbose) ⇒ Object
-
#summary(verbose) ⇒ Object
-
#token ⇒ Object
-
#token_status(verbose, token_value) ⇒ Object
-
#type ⇒ Object
-
#url ⇒ Object
-
#user ⇒ Object
Constructor Details
#initialize(options, config_hash = {}) ⇒ Service
Returns a new instance of Service.
10
11
12
13
14
|
# File 'lib/vmfloaty/service.rb', line 10
def initialize(options, config_hash = {})
options ||= Commander::Command::Options.new
@config = Utils.get_service_config config_hash, options
@service_object = Utils.get_service_object @config['type']
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/vmfloaty/service.rb', line 16
def method_missing(m, *args, &block)
if @service_object.respond_to? m
@service_object.send(m, *args, &block)
else
super
end
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
8
9
10
|
# File 'lib/vmfloaty/service.rb', line 8
def config
@config
end
|
Instance Method Details
#delete(verbose, hosts) ⇒ Object
109
110
111
|
# File 'lib/vmfloaty/service.rb', line 109
def delete(verbose, hosts)
@service_object.delete verbose, url, hosts, token
end
|
#delete_token(verbose, token_value = ) ⇒ Object
54
55
56
57
58
|
# File 'lib/vmfloaty/service.rb', line 54
def delete_token(verbose, token_value = @config['token'])
username = user
pass = Commander::UI::password "Enter your pooler service password:", '*'
Auth.delete_token(verbose, url, username, pass, token_value)
end
|
#disk(verbose, hostname, disk) ⇒ Object
129
130
131
|
# File 'lib/vmfloaty/service.rb', line 129
def disk(verbose, hostname, disk)
@service_object.disk(verbose, url, hostname, token, disk)
end
|
#get_new_token(verbose) ⇒ Object
48
49
50
51
52
|
# File 'lib/vmfloaty/service.rb', line 48
def get_new_token(verbose)
username = user
pass = Commander::UI::password "Enter your pooler service password:", '*'
Auth.get_token(verbose, url, username, pass)
end
|
#list(verbose, os_filter = nil) ⇒ Object
65
66
67
|
# File 'lib/vmfloaty/service.rb', line 65
def list(verbose, os_filter = nil)
@service_object.list verbose, url, os_filter
end
|
#list_active(verbose) ⇒ Object
69
70
71
|
# File 'lib/vmfloaty/service.rb', line 69
def list_active(verbose)
@service_object.list_active verbose, url, token
end
|
#modify(verbose, hostname, modify_hash) ⇒ Object
105
106
107
|
# File 'lib/vmfloaty/service.rb', line 105
def modify(verbose, hostname, modify_hash)
@service_object.modify verbose, url, hostname, token, modify_hash
end
|
#pretty_print_running(verbose, hostnames = []) ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/vmfloaty/service.rb', line 92
def pretty_print_running(verbose, hostnames = [])
if hostnames.empty?
puts "You have no running VMs."
else
puts "Running VMs:"
@service_object.pretty_print_hosts(verbose, hostnames, url)
end
end
|
#query(verbose, hostname) ⇒ Object
101
102
103
|
# File 'lib/vmfloaty/service.rb', line 101
def query(verbose, hostname)
@service_object.query verbose, url, hostname
end
|
#retrieve(verbose, os_types, use_token = true) ⇒ Object
73
74
75
76
77
|
# File 'lib/vmfloaty/service.rb', line 73
def retrieve(verbose, os_types, use_token = true)
puts 'Requesting a vm without a token...' unless use_token
token_value = use_token ? token : nil
@service_object.retrieve verbose, os_types, token_value, url
end
|
#revert(verbose, hostname, snapshot_sha) ⇒ Object
125
126
127
|
# File 'lib/vmfloaty/service.rb', line 125
def revert(verbose, hostname, snapshot_sha)
@service_object.revert verbose, url, hostname, token, snapshot_sha
end
|
#snapshot(verbose, hostname) ⇒ Object
121
122
123
|
# File 'lib/vmfloaty/service.rb', line 121
def snapshot(verbose, hostname)
@service_object.snapshot verbose, url, hostname, token
end
|
#ssh(verbose, host_os, use_token = true) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/vmfloaty/service.rb', line 79
def ssh(verbose, host_os, use_token = true)
token_value = nil
if use_token
begin
token_value = token || get_new_token(verbose)
rescue TokenError => e
STDERR.puts e
STDERR.puts 'Could not get token... requesting vm without a token anyway...'
end
end
Ssh.ssh(verbose, host_os, token_value, url)
end
|
#status(verbose) ⇒ Object
113
114
115
|
# File 'lib/vmfloaty/service.rb', line 113
def status(verbose)
@service_object.status verbose, url
end
|
#summary(verbose) ⇒ Object
117
118
119
|
# File 'lib/vmfloaty/service.rb', line 117
def summary(verbose)
@service_object.summary verbose, url
end
|
#token ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/vmfloaty/service.rb', line 40
def token
unless @config['token']
puts "No token found. Retrieving a token..."
@config['token'] = get_new_token(nil)
end
@config['token']
end
|
#token_status(verbose, token_value) ⇒ Object
60
61
62
63
|
# File 'lib/vmfloaty/service.rb', line 60
def token_status(verbose, token_value)
token_value ||= @config['token']
Auth.token_status(verbose, url, token_value)
end
|
#type ⇒ Object
28
29
30
|
# File 'lib/vmfloaty/service.rb', line 28
def type
@service_object.name
end
|
#url ⇒ Object
24
25
26
|
# File 'lib/vmfloaty/service.rb', line 24
def url
@config['url']
end
|
#user ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/vmfloaty/service.rb', line 32
def user
unless @config['user']
puts "Enter your pooler service username:"
@config['user'] = STDIN.gets.chomp
end
@config['user']
end
|