simple_lb 0.0.6 → 0.0.7
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 +43 -55
- 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: 1b8f191062f29a321e15c15aaa73a6f703ad6953
|
4
|
+
data.tar.gz: 966bbbb5db2c616744e6c453f2813f8737858e7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24857751d831aa06ab1db95a5a8fc11890003c747495ecec90eaa949e38fd70abd485e96f1d55a37aa8df4db231dc99ef8d8f66cc1ee5d1a90a6ce8c82d16f9e
|
7
|
+
data.tar.gz: 74965b083856f47ec412604d5e5a2342ec599dcbe6c1b256a40df5f6da271514a2b816e1d1de958577692ab1c40df4b20e642c6cfd1ef17a7686162d9e4e188f
|
data/lib/simple_lb.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/Users/xjs5/.rvm/rubies/ruby-2.0.0-p353/bin/ruby
|
2
1
|
#
|
3
|
-
|
4
2
|
class VirtualServer
|
5
|
-
require 'savon'
|
3
|
+
require 'savon'
|
6
4
|
|
7
|
-
def initialize
|
5
|
+
def initialize(args)
|
8
6
|
@@vs_attrs = args.to_a
|
9
7
|
if @@vs_attrs.blank?
|
10
|
-
puts
|
11
|
-
puts
|
8
|
+
puts 'Usage:'
|
9
|
+
puts 'simple_lb <vs_server_name> <vs_ipaddress> <member1_ip> <member2_ip>'
|
10
|
+
puts 'Example:'
|
11
|
+
puts 'simple_lb my_vserver 192.168.10.100 192.168.10.102 192.168.10.103'
|
12
12
|
exit
|
13
13
|
end
|
14
14
|
$vs_name = @@vs_attrs.shift
|
@@ -17,21 +17,18 @@ require 'savon'
|
|
17
17
|
VirtualServer.create_config
|
18
18
|
VirtualServer.create_soap_connection('Pool')
|
19
19
|
VirtualServer.create_soap_connection('VirtualServer')
|
20
|
-
puts "array #{@@vs_attrs}"
|
21
20
|
end
|
22
21
|
|
23
22
|
def self.create_config
|
24
|
-
path = File.expand_path
|
23
|
+
path = File.expand_path '~/.bigip.yml'
|
25
24
|
config = YAML.load(File.read(path)) rescue nil
|
26
|
-
unless config
|
25
|
+
unless config
|
27
26
|
config = {
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
}
|
32
|
-
File.open(path, "w") { |f|
|
33
|
-
YAML.dump(config, f)
|
27
|
+
ipaddress: '172.16.222.120',
|
28
|
+
user: 'admin',
|
29
|
+
password: 'admin'
|
34
30
|
}
|
31
|
+
File.open(path, 'w') { |f| YAML.dump(config, f) }
|
35
32
|
abort "Created config file #{path} update with your bigip info"
|
36
33
|
end
|
37
34
|
@ipaddress = config[:ipaddress]
|
@@ -39,7 +36,7 @@ require 'savon'
|
|
39
36
|
@password = config[:password]
|
40
37
|
end
|
41
38
|
|
42
|
-
def self.create_soap_connection
|
39
|
+
def self.create_soap_connection(locallb_prop)
|
43
40
|
@soap =
|
44
41
|
Savon.client do |s|
|
45
42
|
s.wsdl "https://#{@ipaddress}/iControl/iControlPortal.cgi?WSDL=LocalLB.#{locallb_prop}"
|
@@ -51,63 +48,54 @@ require 'savon'
|
|
51
48
|
end
|
52
49
|
case locallb_prop
|
53
50
|
when 'VirtualServer'
|
54
|
-
|
51
|
+
create_virtual_server(@soap, $vs_name, $vs_address)
|
55
52
|
when 'Pool'
|
56
|
-
|
53
|
+
create_pool(@soap, $vs_name, $pool_member1)
|
57
54
|
end
|
58
55
|
end
|
59
56
|
|
60
|
-
def self.create_pool
|
61
|
-
|
62
|
-
soap.call :create do |pool|
|
63
|
-
pool.message 'pool_names' => {:
|
64
|
-
'lb_methods' => {:
|
65
|
-
'members' => {
|
66
|
-
|
67
|
-
|
57
|
+
def self.create_pool(soap, pool_name, pool_member)
|
58
|
+
r =
|
59
|
+
soap.call :create do |pool|
|
60
|
+
pool.message 'pool_names' => { item: ["#{pool_name}"] },
|
61
|
+
'lb_methods' => { item: ['LB_METHOD_ROUND_ROBIN'] },
|
62
|
+
'members' => { item:
|
63
|
+
{ item:
|
64
|
+
[address: pool_member, port: '80'] } }
|
68
65
|
end
|
69
|
-
puts "array #{@@vs_attrs}"
|
70
66
|
unless @@vs_attrs.blank?
|
71
67
|
@@vs_attrs.each do |member|
|
72
|
-
puts "mem #{member}"
|
73
68
|
soap.call :add_member do |pool|
|
74
|
-
pool.message 'pool_names' => {:
|
75
|
-
|
76
|
-
|
77
|
-
|
69
|
+
pool.message 'pool_names' => { item: ["#{pool_name}"] },
|
70
|
+
'members' => { item:
|
71
|
+
{ item:
|
72
|
+
[address: member, port: '80'] } }
|
78
73
|
end
|
79
74
|
r.success?
|
80
75
|
end
|
81
76
|
end
|
82
77
|
end
|
83
|
-
# monitor stuff
|
84
|
-
#soap.call :set_monitor_association do |m|
|
85
|
-
# m.message :monitor_associations => { 'pool_names' => ["#{vs_server_name}"]},
|
86
|
-
# { 'monitor_rule' => ['http']}
|
87
78
|
|
88
|
-
|
89
|
-
#m.success?
|
90
|
-
def self.create_virtual_server (soap,vs_name,vs_address)
|
79
|
+
def self.create_virtual_server(soap, vs_name, vs_address)
|
91
80
|
vsdefinitions = [
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
95
|
-
:
|
96
|
-
vswildmasks =
|
81
|
+
name: vs_name,
|
82
|
+
address: vs_address,
|
83
|
+
port: '80',
|
84
|
+
protocol: 'PROTOCOL_TCP']
|
85
|
+
vswildmasks = '255.255.255.255'
|
97
86
|
vsresources = [
|
98
|
-
:
|
99
|
-
:
|
87
|
+
type: 'RESOURCE_TYPE_POOL',
|
88
|
+
default_pool_name: vs_name]
|
100
89
|
vsprofiles = [
|
101
|
-
:
|
102
|
-
:
|
103
|
-
:
|
104
|
-
r =
|
90
|
+
profile_type: 'PROFILE_TYPE_FAST_L4',
|
91
|
+
profile_context: 'PROFILE_CONTEXT_TYPE_ALL',
|
92
|
+
profile_name: 'tcp']
|
93
|
+
r =
|
105
94
|
soap.call :create do |vs|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
{:item => vsprofiles}}
|
95
|
+
vs.message definitions: { item: vsdefinitions },
|
96
|
+
wildmasks: { item: vswildmasks },
|
97
|
+
resources: { item: vsresources },
|
98
|
+
profiles: { item: { item: vsprofiles } }
|
111
99
|
end
|
112
100
|
r.success?
|
113
101
|
end
|