Class: Vcli::Cli
- Inherits:
-
Thor
- Object
- Thor
- Vcli::Cli
- Defined in:
- lib/vcli/cli.rb
Instance Method Summary collapse
- #deploy ⇒ Object
- #login ⇒ Object
- #poweroff ⇒ Object
- #poweron ⇒ Object
- #reset ⇒ Object
- #target(url) ⇒ Object
- #undeploy ⇒ Object
- #user(username, password) ⇒ Object
- #version ⇒ Object
Instance Method Details
#deploy ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/vcli/cli.rb', line 87 def deploy() begin abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password) # If --vm parameter passed vdc=[:vdc].to_s va=[:va].to_s vm=[:vm].to_s if vm.length != 0 # if Virtual Machine Specified link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/virtualappliances/' + va + '/virtualmachines/' + vm + '/action/deploy', :type => 'application/vnd.abiquo.acceptedrequest+json') reqdata=Hash.new response=abq.post(link,reqdata) puts "Deploying Virtual Machine" puts "Waiting for VM to be deployed" status=response.link(:status).get while status.state == "STARTED" && status.state != "LOCKED" do status=response.link(:status).get print "." sleep 10 end else # If no Virtual Machine specified its a Virtual Appliance link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/virtualappliances/' + va + '/action/deploy') reqdata=Hash.new response=abq.post(link,reqdata) puts "Deploying Virtual Appliance" puts "Waiting for VA to be Deployed" end rescue AbiquoAPIClient::Forbidden puts "Forbidden HTTP 403 Received" rescue AbiquoAPIClient::InvalidCredentials puts "Invalid Credentials - HTTP 401 Received" rescue AbiquoAPIClient::BadRequest => e puts "Bad Request - HTTP 400 or 406 Received" puts e.inspect rescue AbiquoAPIClient::NotFound puts "Not Found - HTTP 400 Received" rescue AbiquoAPIClient::UnsupportedMediaType puts "Unsupported Media Type Specified - HTTP 415 Received" end end |
#login ⇒ Object
31 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 58 59 60 61 62 |
# File 'lib/vcli/cli.rb', line 31 def login() target=[:target].to_s user=[:user].to_s password=[:password].to_s if target.length >0 Vcli.set_config("target",target) end if user.length >0 Vcli.set_config("user",user) end if password.length >0 Vcli.set_config("password",password) end begin abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password) enterprise=abq.user.link(:enterprise).get puts "Logged into Abiquo Portal as User - #{abq.user.id} - #{abq.user.name} #{abq.user.surname}" puts " in Enterprise - #{enterprise.id} - #{abq.enterprise.title}" rescue AbiquoAPIClient::Forbidden puts "Forbidden HTTP 403 Received" rescue AbiquoAPIClient::InvalidCredentials puts "Invalid Credentials - HTTP 401 Received" rescue AbiquoAPIClient::BadRequest puts "Bad Request - HTTP 400 or 406 Received" rescue AbiquoAPIClient::NotFound puts "Not Found - HTTP 400 Received" rescue AbiquoAPIClient::UnsupportedMediaType puts "Unsupported Media Type Specified - HTTP 415 Received" end end |
#poweroff ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/vcli/cli.rb', line 139 def poweroff() begin abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password) vdc=[:vdc].to_s va=[:va].to_s vm=[:vm].to_s link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/virtualappliances/' + va + '/virtualmachines/' + vm + '/state', :type => 'application/vnd.abiquo.virtualmachinestate+json') reqdata=Hash.new reqdata[:state]= "OFF" =Hash.new [:accept] = 'application/vnd.abiquo.acceptedrequest+json' print "Powering Off VM." tries ||= 3 begin response=abq.put(link,reqdata,) status=response.link(:status).get while status.state == "STARTED" && status.state != "LOCKED" do status=response.link(:status).get print "." sleep 10 end rescue Exception=> e retry unless (tries -= 1).zero? end puts puts "VM Powered Off" rescue AbiquoAPIClient::Forbidden puts "Forbidden HTTP 403 Received" rescue AbiquoAPIClient::InvalidCredentials puts "Invalid Credentials - HTTP 401 Received" rescue AbiquoAPIClient::BadRequest => e puts "Bad Request - HTTP 400 or 406 Received" puts e.inspect rescue AbiquoAPIClient::NotFound puts "Not Found - HTTP 400 Received" rescue AbiquoAPIClient::UnsupportedMediaType puts "Unsupported Media Type Specified - HTTP 415 Received" end end |
#poweron ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/vcli/cli.rb', line 187 def poweron() begin abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password) vdc=[:vdc].to_s va=[:va].to_s vm=[:vm].to_s link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/virtualappliances/' + va + '/virtualmachines/' + vm + '/state', :type => 'application/vnd.abiquo.virtualmachinestate+json') reqdata=Hash.new reqdata[:state]= "ON" =Hash.new [:accept] = 'application/vnd.abiquo.acceptedrequest+json' abq.put(link,reqdata,) puts "VM Powered On" rescue AbiquoAPIClient::Forbidden puts "Forbidden HTTP 403 Received" rescue AbiquoAPIClient::InvalidCredentials puts "Invalid Credentials - HTTP 401 Received" rescue AbiquoAPIClient::BadRequest => e puts "Bad Request - HTTP 400 or 406 Received" puts e.inspect rescue AbiquoAPIClient::NotFound puts "Not Found - HTTP 400 Received" rescue AbiquoAPIClient::UnsupportedMediaType puts "Unsupported Media Type Specified - HTTP 415 Received" end end |
#reset ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/vcli/cli.rb', line 222 def reset() begin abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password) # If --vm parameter passed vdc=[:vdc].to_s va=[:va].to_s vm=[:vm].to_s link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/virtualappliances/' + va + '/virtualmachines/' + vm + '/action/reset', :type => 'application/vnd.abiquo.acceptedrequest+json') reqdata=Hash.new abq.post(link,reqdata) puts "VM Reset" rescue AbiquoAPIClient::Forbidden puts "Forbidden HTTP 403 Received" rescue AbiquoAPIClient::InvalidCredentials puts "Invalid Credentials - HTTP 401 Received" rescue AbiquoAPIClient::BadRequest => e puts "Bad Request - HTTP 400 or 406 Received" puts e.inspect rescue AbiquoAPIClient::NotFound puts "Not Found - HTTP 400 Received" rescue AbiquoAPIClient::UnsupportedMediaType puts "Unsupported Media Type Specified - HTTP 415 Received" end end |
#target(url) ⇒ Object
18 19 20 21 22 |
# File 'lib/vcli/cli.rb', line 18 def target(url) Vcli.set_config("target",url) command = "Set target of cli to #{url}" puts command end |
#undeploy ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/vcli/cli.rb', line 256 def undeploy() begin abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password) # If --vm parameter passed vdc=[:vdc].to_s va=[:va].to_s vm=[:vm].to_s force=[:force] request=Hash.new forcerequest=Hash.new if force forcerequest[:forceUndeploy]=true else forcerequest[:forceUndeploy]=false end request[:virtualmachinetask]=forcerequest if vm.length != 0 # if Virtual Machine Specified link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/virtualappliances/' + va + '/virtualmachines/' + vm + '/action/undeploy', :type => 'application/vnd.abiquo.virtualmachinetask+json') else # If no Virtual Machine specified its a Virtual Appliance link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/virtualappliances/' + va + '/action/undeploy', :type => 'application/vnd.abiquo.virtualmachinetask+json') end =Hash.new [:accept] = 'application/vnd.abiquo.acceptedrequest+json' abq.post(link,request,) rescue AbiquoAPIClient::Forbidden puts "Forbidden HTTP 403 Received" rescue AbiquoAPIClient::InvalidCredentials puts "Invalid Credentials - HTTP 401 Received" rescue AbiquoAPIClient::BadRequest => e puts "Bad Request - HTTP 400 or 406 Received" puts e.inspect rescue AbiquoAPIClient::NotFound puts "Not Found - HTTP 400 Received" rescue AbiquoAPIClient::UnsupportedMediaType puts "Unsupported Media Type Specified - HTTP 415 Received" end end |
#user(username, password) ⇒ Object
65 66 67 68 69 |
# File 'lib/vcli/cli.rb', line 65 def user(username, password) Vcli.set_config("user",username) Vcli.set_config("password",password) puts "Set user details complete" end |
#version ⇒ Object
12 13 14 15 |
# File 'lib/vcli/cli.rb', line 12 def version() command = "Version #{VERSION}" puts command end |