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
-
#maybe_use_vmpooler ⇒ Object
some methods do not exist for ABS, and if possible should target the Pooler service.
-
#method_missing(method_name, *args, &block) ⇒ Object
-
#modify(verbose, hostname, modify_hash) ⇒ Object
-
#query(verbose, hostname) ⇒ Object
-
#respond_to_missing?(method_name) ⇒ Boolean
-
#retrieve(verbose, os_types, use_token = true, ondemand = nil, continue = nil) ⇒ 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
-
#wait_for_request(verbose, requestid) ⇒ Object
Constructor Details
#initialize(options, config_hash = {}) ⇒ Service
Returns a new instance of Service.
12
13
14
15
16
17
|
# File 'lib/vmfloaty/service.rb', line 12
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']
@silent = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/vmfloaty/service.rb', line 19
def method_missing(method_name, *args, &block)
if @service_object.respond_to?(method_name)
@service_object.send(method_name, *args, &block)
else
super
end
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9
10
11
|
# File 'lib/vmfloaty/service.rb', line 9
def config
@config
end
|
#silent ⇒ Object
Returns the value of attribute silent.
10
11
12
|
# File 'lib/vmfloaty/service.rb', line 10
def silent
@silent
end
|
Instance Method Details
#delete(verbose, hosts) ⇒ Object
112
113
114
|
# File 'lib/vmfloaty/service.rb', line 112
def delete(verbose, hosts)
@service_object.delete verbose, url, hosts, token, user
end
|
#delete_token(verbose, token_value = ) ⇒ Object
61
62
63
64
65
|
# File 'lib/vmfloaty/service.rb', line 61
def delete_token(verbose, token_value = @config['token'])
username = user
pass = Commander::UI.password "Enter your #{@config['url']} service password:", '*'
Auth.delete_token(verbose, url, username, pass, token_value)
end
|
#disk(verbose, hostname, disk) ⇒ Object
135
136
137
138
|
# File 'lib/vmfloaty/service.rb', line 135
def disk(verbose, hostname, disk)
maybe_use_vmpooler
@service_object.disk(verbose, url, hostname, token, disk)
end
|
#get_new_token(verbose) ⇒ Object
55
56
57
58
59
|
# File 'lib/vmfloaty/service.rb', line 55
def get_new_token(verbose)
username = user
pass = Commander::UI.password "Enter your #{@config['url']} service password:", '*'
Auth.get_token(verbose, url, username, pass)
end
|
#list(verbose, os_filter = nil) ⇒ Object
72
73
74
|
# File 'lib/vmfloaty/service.rb', line 72
def list(verbose, os_filter = nil)
@service_object.list verbose, url, os_filter
end
|
#list_active(verbose) ⇒ Object
76
77
78
|
# File 'lib/vmfloaty/service.rb', line 76
def list_active(verbose)
@service_object.list_active verbose, url, token, user
end
|
#maybe_use_vmpooler ⇒ Object
some methods do not exist for ABS, and if possible should target the Pooler service
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/vmfloaty/service.rb', line 141
def maybe_use_vmpooler
if @service_object == ABS if !self.silent
FloatyLogger.info "The service in use is ABS, but the requested method should run against vmpooler directly, using fallback_vmpooler config from ~/.vmfloaty.yml"
self.silent = true
end
@config = Utils.get_vmpooler_service_config(@config['vmpooler_fallback'])
@service_object = Pooler
end
end
|
#modify(verbose, hostname, modify_hash) ⇒ Object
107
108
109
110
|
# File 'lib/vmfloaty/service.rb', line 107
def modify(verbose, hostname, modify_hash)
maybe_use_vmpooler
@service_object.modify verbose, url, hostname, token, modify_hash
end
|
#query(verbose, hostname) ⇒ Object
103
104
105
|
# File 'lib/vmfloaty/service.rb', line 103
def query(verbose, hostname)
@service_object.query verbose, url, hostname
end
|
#respond_to_missing?(method_name) ⇒ Boolean
27
28
29
|
# File 'lib/vmfloaty/service.rb', line 27
def respond_to_missing?(method_name, *)
@service_object.respond_to?(method_name) || super
end
|
#retrieve(verbose, os_types, use_token = true, ondemand = nil, continue = nil) ⇒ Object
80
81
82
83
84
|
# File 'lib/vmfloaty/service.rb', line 80
def retrieve(verbose, os_types, use_token = true, ondemand = nil, continue = nil)
FloatyLogger.info 'Requesting a vm without a token...' unless use_token
token_value = use_token ? token : nil
@service_object.retrieve verbose, os_types, token_value, url, user, @config, ondemand, continue
end
|
#revert(verbose, hostname, snapshot_sha) ⇒ Object
130
131
132
133
|
# File 'lib/vmfloaty/service.rb', line 130
def revert(verbose, hostname, snapshot_sha)
maybe_use_vmpooler
@service_object.revert verbose, url, hostname, token, snapshot_sha
end
|
#snapshot(verbose, hostname) ⇒ Object
125
126
127
128
|
# File 'lib/vmfloaty/service.rb', line 125
def snapshot(verbose, hostname)
maybe_use_vmpooler
@service_object.snapshot verbose, url, hostname, token
end
|
#ssh(verbose, host_os, use_token = true) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/vmfloaty/service.rb', line 90
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
FloatyLogger.error e
FloatyLogger.info 'Could not get token... requesting vm without a token anyway...'
end
end
Ssh.ssh(verbose, self, host_os, token_value)
end
|
#status(verbose) ⇒ Object
116
117
118
|
# File 'lib/vmfloaty/service.rb', line 116
def status(verbose)
@service_object.status verbose, url
end
|
#summary(verbose) ⇒ Object
120
121
122
123
|
# File 'lib/vmfloaty/service.rb', line 120
def summary(verbose)
maybe_use_vmpooler
@service_object.summary verbose, url
end
|
#token ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/vmfloaty/service.rb', line 47
def token
unless @config['token']
FloatyLogger.info 'No token found. Retrieving a token...'
@config['token'] = get_new_token(nil)
end
@config['token']
end
|
#token_status(verbose, token_value) ⇒ Object
67
68
69
70
|
# File 'lib/vmfloaty/service.rb', line 67
def token_status(verbose, token_value)
token_value ||= @config['token']
Auth.token_status(verbose, url, token_value)
end
|
#type ⇒ Object
35
36
37
|
# File 'lib/vmfloaty/service.rb', line 35
def type
@service_object.name
end
|
#url ⇒ Object
31
32
33
|
# File 'lib/vmfloaty/service.rb', line 31
def url
@config['url']
end
|
#user ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/vmfloaty/service.rb', line 39
def user
unless @config['user']
FloatyLogger.info "Enter your #{@config['url']} service username:"
@config['user'] = STDIN.gets.chomp
end
@config['user']
end
|
#wait_for_request(verbose, requestid) ⇒ Object
86
87
88
|
# File 'lib/vmfloaty/service.rb', line 86
def wait_for_request(verbose, requestid)
@service_object.wait_for_request verbose, requestid, url
end
|