Class: Vcli::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/vcli/cli.rb

Instance Method Summary collapse

Instance Method Details

#loginObject



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
51
52
53
54
55
56
57
58
# File 'lib/vcli/cli.rb', line 26

def ()
  target=options[:target].to_s
  user=options[:user].to_s
  password=options[: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)
    abq.user
    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 "Note Found - HTTP 400 Received"
  rescue AbiquoAPIClient::UnsupportedMediaType
    puts "Unsupported Media Type Specified - HTTP 415 Received"
  end
end

#target(url) ⇒ Object



16
17
18
19
20
# File 'lib/vcli/cli.rb', line 16

def target(url)
  Vcli.set_config("target",url)
  command = "Set target of cli to #{url}"
  puts command
end

#user(username, password) ⇒ Object



61
62
63
64
65
# File 'lib/vcli/cli.rb', line 61

def user(username, password)
  Vcli.set_config("user",username)
  Vcli.set_config("password",password)
  puts "Set user details complete"
end

#versionObject



10
11
12
13
# File 'lib/vcli/cli.rb', line 10

def version()
  command = "Version #{VERSION}"
  puts command
end