Class: BBGAPI::LB_Applications

Inherits:
Object
  • Object
show all
Defined in:
lib/bbgapi/lb_applications.rb

Class Method Summary collapse

Class Method Details

.createObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bbgapi/lb_applications.rb', line 35

def self.create
  app_name = ask("Specify a name for the new app:  ")
  options = { :body => {
    :name => app_name
    } }
  partial = '/api/lb_applications'
  api_response = BBGAPI::Client.posturl(partial,options)
  puts "App Created!"
  puts "Name:        #{api_response["name"]}"
  puts "ID:          #{api_response["id"]}"
  puts "External IP: #{api_response["ip_v4"]}"
  puts "Internal IP: #{api_response["source_ip"]}"
end

.deleteObject



49
50
51
52
53
54
55
56
57
# File 'lib/bbgapi/lb_applications.rb', line 49

def self.delete
  raw_apps = self.raw
  choose do |menu|
    menu.prompt = "Which App To Delete?"
    raw_apps.each {|app|
      menu.choices(app["name"]) {self.delete_confirm(app["name"],app["id"])}
    }
  end
end

.delete_confirm(name, id) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/bbgapi/lb_applications.rb', line 59

def self.delete_confirm(name,id)
  choose do |menu|
    menu.prompt = "Are you sure you want to delete app #{name}?"

    menu.choices(:yes) {
      partial = "/api/lb_applications/#{id}"
      api_response = BBGAPI::Client.deleteurl(partial)
      pp api_response
    }
    menu.choices(:no)
  end

end

.get_appObject



73
74
75
# File 'lib/bbgapi/lb_applications.rb', line 73

def self.get_app
  return @@current_app
end

.listObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bbgapi/lb_applications.rb', line 18

def self.list
  partial = '/api/lb_applications'
  api_response = BBGAPI::Client.geturl(partial,"")
  apps = []
  api_response.each {|x|
    apps << {"name" => "#{x["name"]}","id" => "#{x["id"]}"}
    puts "\n"
    puts "Name:        #{x["name"]}"
    puts "ID:          #{x["id"]}"
    puts "Description: #{x["description"]}"
    puts "External IP: #{x["ip_v4"]}"
    puts "Internal IP: #{x["source_ip_v4"]}"
    puts "Created:     #{x["created"]}"
  }
  puts "\n"
end


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bbgapi/lb_applications.rb', line 5

def self.menulist
  choose do |menu|
    puts "Load Balancer Applications"
    puts "----------------------------------------"
    menu.prompt = "Which Action?"

    menu.choices(:list) {self.list}
    menu.choices(:create) {self.create}
    menu.choices(:update) {self.tbi}
    menu.choices(:delete) {self.delete}
  end
end

.only_name_idObject



87
88
89
90
91
92
93
94
95
# File 'lib/bbgapi/lb_applications.rb', line 87

def self.only_name_id
  partial = '/api/lb_applications'
  api_response = BBGAPI::Client.geturl(partial,"")
  apps = []
  api_response.each {|x|
    apps << {"name" => "#{x["name"]}","id" => "#{x["id"]}"}
  }
  return apps
end

.rawObject



81
82
83
84
85
# File 'lib/bbgapi/lb_applications.rb', line 81

def self.raw
  partial = '/api/lb_applications'
  api_response = BBGAPI::Client.geturl(partial,"")
  return api_response
end

.set_app(appid = "") ⇒ Object



77
78
79
# File 'lib/bbgapi/lb_applications.rb', line 77

def self.set_app (appid="")
  @@current_app = appid
end

.tbiObject



97
98
99
# File 'lib/bbgapi/lb_applications.rb', line 97

def self.tbi
  puts "This is not yet implemented"
end