Class: UnitHosting::Commands
- Inherits:
-
CommandLineUtils::Commands
- Object
- CommandLineUtils::Commands
- UnitHosting::Commands
- Includes:
- Api
- Defined in:
- lib/unit-hosting/commands.rb
Instance Method Summary collapse
- #group ⇒ Object
- #groups ⇒ Object
-
#initialize ⇒ Commands
constructor
CommandLineUtils::COMMANDS +=.
- #login ⇒ Object
- #logout ⇒ Object
- #update ⇒ Object
- #vif_plug ⇒ Object
- #vm_create ⇒ Object
Methods included from Api
Constructor Details
#initialize ⇒ Commands
CommandLineUtils::COMMANDS +=
14 15 16 17 18 19 20 21 |
# File 'lib/unit-hosting/commands.rb', line 14 def initialize super @commands += ["login","logout","update","groups","group"] @agent = Agent.new @cache_file = ENV['HOME']+"/.unit-hosting.cache" @cache = Cache.new(@cache_file) end |
Instance Method Details
#group ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/unit-hosting/commands.rb', line 109 def group opt = OptionParser.new opt.parse!() @summery = "List servers in group." = "" return opt if @help id = .shift group = ask_group(id,@cache.groups) puts group.tablize if group end |
#groups ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/unit-hosting/commands.rb', line 99 def groups opt = OptionParser.new opt.parse!() @summery = "List sever groups." = "" return opt if @help puts @cache.groups.tablize end |
#login ⇒ Object
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 49 50 |
# File 'lib/unit-hosting/commands.rb', line 23 def login opt = OptionParser.new opt.parse!() @summery = "Login to https://cloud.unit-hosting.com ." = "" return opt if @help user = ask('Enter user: ') do |q| q.validate = /\w+/ end ok = false while(!ok) password = ask("Enter your password: ") do |q| q.validate = /\w+/ q.echo = false end @agent.login(user,password) if @agent.login? # => OK ok = true Keystorage.set("unit-hosting",user,password) puts "login OK" else puts "password mismatch" end end end |
#logout ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/unit-hosting/commands.rb', line 52 def logout opt = OptionParser.new opt.parse!() @summery = "Logout from https://cloud.unit-hosting.com ." = "" return opt if @help Keystorage.delete("unit-hosting") end |
#update ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/unit-hosting/commands.rb', line 62 def update all = false opt = OptionParser.new opt.on('-a','--all', 'update all cache') { all = true } opt.parse!() @summery = "Update cache." = "GID [-a|--all]" return opt if @help gid = .shift start gs = @agent.groups.collect { |g| unless g.key.empty? v = @cache.groups.find{ |c| c.instance_id == g.instance_id } v.update if v and v.vms == nil g.vms = v.vms if v g end }.compact @cache.transaction { |ps| if all ps["groups"] = gs.find_all { |g| !g.key.empty? }.extend(Groups).update else group = ask_group(gid,gs) ps["groups"] = gs.collect{ |g| unless g.key.empty? g.update if g.instance_id == group.instance_id g end }.compact.extend(Groups) end } end |
#vif_plug ⇒ Object
121 122 123 |
# File 'lib/unit-hosting/commands.rb', line 121 def vif_plug end |
#vm_create ⇒ Object
125 126 127 |
# File 'lib/unit-hosting/commands.rb', line 125 def vm_create # vm:create tumf-sg-1 end |