simple_lb 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_lb.rb +50 -41
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2e80f6ac1aed262ee892a0aa9586b73b7b83834
|
4
|
+
data.tar.gz: 580865efca073b58f00848fad7b902ecfdb97d86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b971085e27dcd564c4430242daad1b290c820e0b269f8ee6db429744da49e4b6453a5a766100f7d6aaf3ba8b21cd0b8f6439ef7ada9963d4993d9ca183bac3d
|
7
|
+
data.tar.gz: 733aae3a416b3817d321c6d0954d154b44c73a921c4fbaf7046d0dee26a9b5ebf0ff761115e7430fc1da3ce0d6d50436c60922acaff68869efe1d6f462d94573
|
data/lib/simple_lb.rb
CHANGED
@@ -1,60 +1,69 @@
|
|
1
|
+
require 'savon'
|
1
2
|
#
|
2
3
|
class VirtualServer
|
3
|
-
|
4
|
+
def usage
|
5
|
+
puts 'Usage:'
|
6
|
+
puts 'simple_lb <vs_server_name> <vs_ipaddress> <member1_ip> <member2_ip>'
|
7
|
+
puts 'Example:'
|
8
|
+
puts 'simple_lb my_vserver 192.168.10.100 192.168.10.102 192.168.10.103'
|
9
|
+
exit
|
10
|
+
end
|
4
11
|
|
5
12
|
def initialize(args)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
exit
|
13
|
+
config_path = File.expand_path '~/.bigip.yml'
|
14
|
+
create_config(config_path) unless File.exist?(config_path)
|
15
|
+
if args.blank?
|
16
|
+
usage
|
17
|
+
else
|
18
|
+
@vs_attrs = args.to_a
|
13
19
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
load_config(config_path)
|
21
|
+
vs_name = @vs_attrs.shift
|
22
|
+
vs_address = @vs_attrs.shift
|
23
|
+
pool_member1 = @vs_attrs.shift
|
24
|
+
create_soap_connection('Pool', vs_name, vs_address, pool_member1, @vs_attrs)
|
25
|
+
create_soap_connection('VirtualServer', vs_name, vs_address, pool_member1, @vs_attrs)
|
20
26
|
end
|
21
27
|
|
22
|
-
def
|
23
|
-
|
24
|
-
config = YAML.load(File.read(path)) rescue nil
|
25
|
-
unless config
|
26
|
-
config = {
|
27
|
-
ipaddress: '172.16.222.120',
|
28
|
-
user: 'admin',
|
29
|
-
password: 'admin'
|
30
|
-
}
|
31
|
-
File.open(path, 'w') { |f| YAML.dump(config, f) }
|
32
|
-
abort "Created config file #{path} update with your bigip info"
|
33
|
-
end
|
28
|
+
def load_config(config_path)
|
29
|
+
config = YAML.load_file(config_path)
|
34
30
|
@ipaddress = config[:ipaddress]
|
35
31
|
@user = config[:user]
|
36
32
|
@password = config[:password]
|
37
33
|
end
|
38
34
|
|
39
|
-
def
|
35
|
+
def create_config(config_path)
|
36
|
+
config = {
|
37
|
+
ipaddress: '172.16.222.120',
|
38
|
+
user: 'admin',
|
39
|
+
password: 'admin'
|
40
|
+
}
|
41
|
+
File.open(config_path, 'w') do |f|
|
42
|
+
YAML.dump(config, f)
|
43
|
+
end
|
44
|
+
puts "Created config file #{config_path} update with your bigip info"
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_soap_connection(locallb_prop, vs_name, vs_address, pool_member1, vs_attrs)
|
40
49
|
@soap =
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
50
|
+
Savon.client do |s|
|
51
|
+
s.wsdl "https://#{@ipaddress}/iControl/iControlPortal.cgi?WSDL=LocalLB.#{locallb_prop}"
|
52
|
+
s.basic_auth [@user, @password]
|
53
|
+
s.ssl_verify_mode :none
|
54
|
+
s.endpoint "https://#{@ipaddress}/iControl/iControlPortal.cgi"
|
55
|
+
s.namespace "urn:iControl:LocalLB/#{locallb_prop}"
|
56
|
+
s.convert_request_keys_to :none
|
57
|
+
end
|
49
58
|
case locallb_prop
|
50
59
|
when 'VirtualServer'
|
51
|
-
create_virtual_server(@soap,
|
60
|
+
create_virtual_server(@soap, vs_name, vs_address)
|
52
61
|
when 'Pool'
|
53
|
-
create_pool(@soap,
|
62
|
+
create_pool(@soap, vs_name, pool_member1, vs_attrs)
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
57
|
-
def
|
66
|
+
def create_pool(soap, pool_name, pool_member, vs_attrs)
|
58
67
|
r =
|
59
68
|
soap.call :create do |pool|
|
60
69
|
pool.message 'pool_names' => { item: ["#{pool_name}"] },
|
@@ -63,8 +72,8 @@ class VirtualServer
|
|
63
72
|
{ item:
|
64
73
|
[address: pool_member, port: '80'] } }
|
65
74
|
end
|
66
|
-
unless
|
67
|
-
|
75
|
+
unless vs_attrs.blank?
|
76
|
+
vs_attrs.each do |member|
|
68
77
|
soap.call :add_member do |pool|
|
69
78
|
pool.message 'pool_names' => { item: ["#{pool_name}"] },
|
70
79
|
'members' => { item:
|
@@ -76,7 +85,7 @@ class VirtualServer
|
|
76
85
|
end
|
77
86
|
end
|
78
87
|
|
79
|
-
def
|
88
|
+
def create_virtual_server(soap, vs_name, vs_address)
|
80
89
|
vsdefinitions = [
|
81
90
|
name: vs_name,
|
82
91
|
address: vs_address,
|