Class: BBGAPI::LB_Services

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

Class Method Summary collapse

Class Method Details

.createObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bbgapi/lb_services.rb', line 62

def self.create
  begin
    cur_app = BBGAPI::LB_Applications.get_app
  rescue
    cur_app = self.recurse
  end

  choose do |menu|
    menu.prompt = "HTTP or HTTPS?"
    menu.choices(:http) {service_type="http"}
    menu.choices(:https) {service_type="https"}
  end

  options = { :body => {
    :service_type => service_type
    } }

  partial = "/api/lb_applications/#{cur_app}/lb_services"
  api_response = BBGAPI::Client.posturl(partial,options)
  pp api_response
  #puts "Name:         #{api_response["name"]}"

  puts "\n"
end

.deleteObject



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

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

.delete_confirm(name, id) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/bbgapi/lb_services.rb', line 97

def self.delete_confirm(name,id)
  begin
    cur_app = BBGAPI::LB_Applications.get_app
  rescue
    cur_app = self.recurse
  end

  choose do |menu|
    menu.prompt = "Are you sure you want to delete service #{name}?"
    menu.choices(:yes) {
      partial = "/api/lb_applications/#{cur_app}/lb_services/#{id}"
      api_response = BBGAPI::Client.deleteurl(partial)
      pp api_response
    }
    menu.choices(:no)
  end
end

.get_serviceObject



16
17
18
# File 'lib/bbgapi/lb_services.rb', line 16

def self.get_service
  return @@current_service
end

.haproxyinfoObject



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/bbgapi/lb_services.rb', line 144

def self.haproxyinfo
  begin
    cur_app = BBGAPI::LB_Applications.get_app
  rescue
    cur_app = self.recurse
  end

  partial = "/api/lb_applications/#{cur_app}/lb_services"
  api_response = BBGAPI::Client.geturl(partial,"")
  haproxy = []
  api_response.each {|x|
    haproxy << {"name" => "#{x["name"]}","status_url" => "#{x["status_url"]}","status_username" => "#{x["status_username"]}","status_password" => "#{x["status_password"]}"}
  }
  return haproxy
end

.listObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bbgapi/lb_services.rb', line 38

def self.list
  begin
    cur_app = BBGAPI::LB_Applications.get_app
  rescue
    cur_app = self.recurse
  end

  partial = "/api/lb_applications/#{cur_app}/lb_services"
  api_response = BBGAPI::Client.geturl(partial,"")
  api_response.each {|x|
    puts "\n"
    puts "Name:         #{x["name"]}"
    puts "ID:           #{x["id"]}"
    puts "Description:  #{x["description"]}"
    puts "Port:         #{x["port"]}"
    puts "Service Type: #{x["service_type"]}"
    puts "Status URL:   #{x["status_url"]}"
    puts "Status User:  #{x["status_username"]}"
    puts "Status Pass:  #{x["status_password"]}"
    puts "Created:      #{x["created"]}"
  }
  puts "\n"
end


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

def self.menulist
  choose do |menu|
    puts "Load Balancer Services"
    puts "----------------------------------------"
    menu.prompt = "Which Action?"
    menu.choices(:list) {self.list}
    menu.choices(:create) {self.tbi}
    menu.choices(:update) {self.tbi}
    menu.choices(:delete) {self.tbi}
  end
end

.only_name_idObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/bbgapi/lb_services.rb', line 115

def self.only_name_id
  begin
    cur_app = BBGAPI::LB_Applications.get_app
  rescue
    cur_app = self.recurse
  end

  partial = "/api/lb_applications/#{cur_app}/lb_services"
  api_response = BBGAPI::Client.geturl(partial,"")
  services = []
  api_response.each {|x|
    services << {"name" => "#{x["name"]}","id" => "#{x["id"]}"}
  }
  return services
end

.rawObject



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/bbgapi/lb_services.rb', line 131

def self.raw
  begin
    cur_app = BBGAPI::LB_Applications.get_app
  rescue
    cur_app = self.recurse
  end

  partial = "/api/lb_applications/#{cur_app}/lb_services"
  api_response = BBGAPI::Client.geturl(partial,"")
  return api_response
end

.recurseObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bbgapi/lb_services.rb', line 24

def self.recurse
  apps = BBGAPI::LB_Applications.only_name_id
  choose do |menu|
    menu.prompt = "Which Application?"
    apps.each {|k|
      menu.choices(k["name"]) {
        BBGAPI::LB_Applications.set_app(k["id"])
        cur_app = k["id"]
      }
    }
  end
  return BBGAPI::LB_Applications.get_app
end

.set_service(serviceid = "") ⇒ Object



20
21
22
# File 'lib/bbgapi/lb_services.rb', line 20

def self.set_service (serviceid="")
  @@current_service = serviceid
end

.tbiObject



160
161
162
# File 'lib/bbgapi/lb_services.rb', line 160

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