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(method_name, *args, &block) ⇒ Object
-
#modify(verbose, hostname, modify_hash) ⇒ Object
-
#pretty_print_running(verbose, hostnames = []) ⇒ Object
-
#query(verbose, hostname) ⇒ Object
-
#respond_to_missing?(method_name) ⇒ Boolean
-
#retrieve(verbose, os_types, use_token = true, ondemand = 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.
11
12
13
14
15
|
# File 'lib/vmfloaty/service.rb', line 11
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(method_name, *args, &block) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/vmfloaty/service.rb', line 17
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
|
Instance Method Details
#delete(verbose, hosts) ⇒ Object
118
119
120
|
# File 'lib/vmfloaty/service.rb', line 118
def delete(verbose, hosts)
@service_object.delete verbose, url, hosts, token, user
end
|
#delete_token(verbose, token_value = ) ⇒ Object
59
60
61
62
63
|
# File 'lib/vmfloaty/service.rb', line 59
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
138
139
140
|
# File 'lib/vmfloaty/service.rb', line 138
def disk(verbose, hostname, disk)
@service_object.disk(verbose, url, hostname, token, disk)
end
|
#get_new_token(verbose) ⇒ Object
53
54
55
56
57
|
# File 'lib/vmfloaty/service.rb', line 53
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
70
71
72
|
# File 'lib/vmfloaty/service.rb', line 70
def list(verbose, os_filter = nil)
@service_object.list verbose, url, os_filter
end
|
#list_active(verbose) ⇒ Object
74
75
76
|
# File 'lib/vmfloaty/service.rb', line 74
def list_active(verbose)
@service_object.list_active verbose, url, token, user
end
|
#modify(verbose, hostname, modify_hash) ⇒ Object
114
115
116
|
# File 'lib/vmfloaty/service.rb', line 114
def modify(verbose, hostname, modify_hash)
@service_object.modify verbose, url, hostname, token, modify_hash
end
|
#pretty_print_running(verbose, hostnames = []) ⇒ Object
101
102
103
104
105
106
107
108
|
# File 'lib/vmfloaty/service.rb', line 101
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
110
111
112
|
# File 'lib/vmfloaty/service.rb', line 110
def query(verbose, hostname)
@service_object.query verbose, url, hostname
end
|
#respond_to_missing?(method_name) ⇒ Boolean
25
26
27
|
# File 'lib/vmfloaty/service.rb', line 25
def respond_to_missing?(method_name, *)
@service_object.respond_to?(method_name) || super
end
|
#retrieve(verbose, os_types, use_token = true, ondemand = nil) ⇒ Object
78
79
80
81
82
|
# File 'lib/vmfloaty/service.rb', line 78
def retrieve(verbose, os_types, use_token = true, ondemand = nil)
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, user, @config, ondemand
end
|
#revert(verbose, hostname, snapshot_sha) ⇒ Object
134
135
136
|
# File 'lib/vmfloaty/service.rb', line 134
def revert(verbose, hostname, snapshot_sha)
@service_object.revert verbose, url, hostname, token, snapshot_sha
end
|
#snapshot(verbose, hostname) ⇒ Object
130
131
132
|
# File 'lib/vmfloaty/service.rb', line 130
def snapshot(verbose, hostname)
@service_object.snapshot verbose, url, hostname, token
end
|
#ssh(verbose, host_os, use_token = true) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/vmfloaty/service.rb', line 88
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, self, host_os, token_value)
end
|
#status(verbose) ⇒ Object
122
123
124
|
# File 'lib/vmfloaty/service.rb', line 122
def status(verbose)
@service_object.status verbose, url
end
|
#summary(verbose) ⇒ Object
126
127
128
|
# File 'lib/vmfloaty/service.rb', line 126
def summary(verbose)
@service_object.summary verbose, url
end
|
#token ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/vmfloaty/service.rb', line 45
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
65
66
67
68
|
# File 'lib/vmfloaty/service.rb', line 65
def token_status(verbose, token_value)
token_value ||= @config['token']
Auth.token_status(verbose, url, token_value)
end
|
#type ⇒ Object
33
34
35
|
# File 'lib/vmfloaty/service.rb', line 33
def type
@service_object.name
end
|
#url ⇒ Object
29
30
31
|
# File 'lib/vmfloaty/service.rb', line 29
def url
@config['url']
end
|
#user ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/vmfloaty/service.rb', line 37
def user
unless @config['user']
puts "Enter your #{@config['url']} service username:"
@config['user'] = STDIN.gets.chomp
end
@config['user']
end
|
#wait_for_request(verbose, requestid) ⇒ Object
84
85
86
|
# File 'lib/vmfloaty/service.rb', line 84
def wait_for_request(verbose, requestid)
@service_object.wait_for_request verbose, requestid, url
end
|