Class: UnitHosting::Commands
- Inherits:
-
CommandLineUtils::Commands
- Object
- CommandLineUtils::Commands
- UnitHosting::Commands
show all
- Includes:
- Api
- Defined in:
- lib/unit-hosting/commands.rb
Defined Under Namespace
Classes: ArgumentError, GroupNotFound, LoginError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Api
keypath
Constructor Details
#initialize(endpoint = nil) ⇒ Commands
Returns a new instance of Commands.
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/unit-hosting/commands.rb', line 17
def initialize endpoint =nil
@keyname = "unit-hosting"
@endpoint = endpoint
@command_options = []
super()
@commands += ["login","logout","update","groups","group"]
@agent = Agent.new
@agent.endpoint = @endpoint
@cache = nil
end
|
Instance Attribute Details
#agent ⇒ Object
CommandLineUtils::COMMANDS +=
16
17
18
|
# File 'lib/unit-hosting/commands.rb', line 16
def agent
@agent
end
|
#cache ⇒ Object
CommandLineUtils::COMMANDS +=
16
17
18
|
# File 'lib/unit-hosting/commands.rb', line 16
def cache
@cache
end
|
#keyname ⇒ Object
CommandLineUtils::COMMANDS +=
16
17
18
|
# File 'lib/unit-hosting/commands.rb', line 16
def keyname
@keyname
end
|
Instance Method Details
#group ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/unit-hosting/commands.rb', line 96
def group
opt = OptionParser.new
opt.parse!(@command_options)
@summery = "List servers in group."
@banner = ""
return opt if @help
id = @command_options.shift
group = ask_group(id,cache.groups)
puts group.tablize if group
end
|
#groups ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'lib/unit-hosting/commands.rb', line 87
def groups
opt = OptionParser.new
opt.parse!(@command_options)
@summery = "List sever groups."
@banner = ""
return opt if @help
STDOUT.puts cache.groups.try(:tablize)
end
|
#login ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/unit-hosting/commands.rb', line 32
def login
opt = OptionParser.new
opt.parse!(@command_options)
@summery = "Login to #{@endpoint} ."
@banner = ""
return opt if @help
ok = false
while(!ok)
user = ask('Enter user: ') do |q|
q.validate = /\w+/
end
password = ask("Enter your password: ") do |q|
q.validate = /\w+/
q.echo = false
end
@agent.login(user,password)
if @agent.login?
ok = true
Keystorage.set(@keyname,user,password)
$stderr.puts "login OK"
else
$stderr.puts "password mismatch"
end
end
end
|
#logout ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/unit-hosting/commands.rb', line 59
def logout
opt = OptionParser.new
opt.parse!(@command_options)
@summery = "Logout from #{@endpoint} ."
@banner = ""
return opt if @help
Keystorage.delete(@keyname)
end
|
#update(all = false) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/unit-hosting/commands.rb', line 69
def update all = false
opt = OptionParser.new
opt.on('-a','--all', 'update all cache') { all = true }
opt.parse!(@command_options)
@summery = "Update cache."
@banner = "GID [-a|--all]"
return opt if @help
gid = @command_options.shift
start
if all
cache.update_all_groups!(@agent.groups)
else
group = ask_group(gid,cache.groups)
cache.update_group!(group)
end
end
|
#vif_plug ⇒ Object
108
109
110
|
# File 'lib/unit-hosting/commands.rb', line 108
def vif_plug
end
|
#vm_create ⇒ Object
112
113
114
|
# File 'lib/unit-hosting/commands.rb', line 112
def vm_create
end
|