1 import groovy.transform.ToString
\r
2 import groovy.transform.EqualsAndHashCode
\r
4 import com.radware.alteon.beans.adc.*;
\r
5 import com.radware.alteon.api.*;
\r
6 import com.radware.alteon.sdk.*
\r
7 import com.radware.alteon.sdk.rpm.*
\r
8 import com.radware.alteon.api.impl.AlteonCliUtils;
\r
9 import com.radware.alteon.cli.CliSession;
\r
12 @ToString(includeNames=true)
\r
13 @EqualsAndHashCode(excludes=["gateway","mask","ips"])
\r
21 @ToString(includeNames=true)
\r
22 @EqualsAndHashCode(excludes=["subnets"])
\r
29 def tokenize_key(map_key) {
\r
30 def ret_arr = map_key.tokenize(".")
\r
31 if (ret_arr.size > 0 && ret_arr[0].startsWith("port")) {
\r
39 def parse(advanced_props) {
\r
41 advanced_props.each {
\r
43 def parsed_key = tokenize_key(key)
\r
45 def port_name = parsed_key[0]
\r
46 def subnet_id = parsed_key[1]
\r
47 def property = parsed_key[2]
\r
48 def port_info = ports.get(port_name)
\r
50 def subnet_info = port_info.subnets.get(subnet_id)
\r
52 subnet_info[property] = value
\r
55 subnet_info = new SubnetInfo(id:subnet_id)
\r
56 subnet_info[property] = value
\r
57 port_info.subnets.put(subnet_id, subnet_info)
\r
61 port_info = new PortInfo(name:port_name)
\r
62 subnet_info = new SubnetInfo(id:subnet_id)
\r
63 subnet_info[property] = value
\r
64 port_info.subnets.put(subnet_id, subnet_info)
\r
65 ports.put(port_name, port_info)
\r
72 def get_property_per_port (ports, port_name, property_name) {
\r
73 port_info = ports[port_name]
\r
75 port_subnet = port_info.subnets
\r
76 if (port_subnet && !port_subnet.isEmpty()) {
\r
77 port_subnet_item = port_subnet.values().iterator().next()
\r
78 port_subnet_property = port_subnet_item[property_name]
\r
79 if (port_subnet_property) {
\r
80 val_array = port_subnet_property.tokenize(",")
\r
81 if (!val_array.isEmpty())
\r
91 def cidr_to_mask(cidr) throws NumberFormatException {
\r
93 String[] st = cidr.split("\\/");
\r
94 if (st.length != 2) {
\r
95 throw new NumberFormatException("Invalid CIDR format '"
\r
96 + cidr + "', should be: xx.xx.xx.xx/xx");
\r
98 String symbolicIP = st[0];
\r
99 String symbolicCIDR = st[1];
\r
101 Integer numericCIDR = new Integer(symbolicCIDR);
\r
102 if (numericCIDR > 32) {
\r
103 throw new NumberFormatException("CIDR can not be greater than 32");
\r
106 st = symbolicIP.split("\\.");
\r
107 if (st.length != 4) {
\r
108 throw new NumberFormatException("Invalid IP address: " + symbolicIP);
\r
112 for (int n = 0; n < st.length; n++) {
\r
113 int value = Integer.parseInt(st[n]);
\r
114 if (value != (value & 0xff)) {
\r
115 throw new NumberFormatException("Invalid IP address: " + symbolicIP);
\r
117 baseIPnumeric += value << i;
\r
121 if (numericCIDR < 1)
\r
122 throw new NumberFormatException("Netmask CIDR can not be less than 1");
\r
123 netmaskNumeric = 0xffffffff;
\r
124 netmaskNumeric = netmaskNumeric << (32 - numericCIDR);
\r
125 return netmaskNumeric
\r
129 def String convert_numeric_ip_to_symbolic(ip) {
\r
130 StringBuffer sb = new StringBuffer(15);
\r
131 for (int shift = 24; shift > 0; shift -= 8) {
\r
132 // process 3 bytes, from high order byte down.
\r
133 def tmp = (ip >>> shift) & 0xff
\r
137 sb.append(ip & 0xff);
\r
138 return sb.toString();
\r
142 primary_adc = sdk.read(service.getPrimaryId())
\r
143 primary_config = primary_adc.adcInfo.advancedConfiguration
\r
144 primary_ports = parse(primary_config)
\r
145 data_ip_address = get_property_per_port(primary_ports, "port1", "ips")
\r
146 data_ip_mask = convert_numeric_ip_to_symbolic(cidr_to_mask(get_property_per_port(primary_ports, "port1", "mask")))
\r
147 gateway = get_property_per_port(primary_ports, "port1", "gateway")
\r
149 if (service.request.ha) {
\r
150 secondary_adc = sdk.read(service.getSecondaryId())
\r
151 secondary_config = secondary_adc.adcInfo.advancedConfiguration
\r
152 secondary_ports = parse(secondary_config)
\r
153 ha_ip_address_1 = get_property_per_port(primary_ports, "port2", "ips")
\r
154 ha_ip_address_2 = get_property_per_port(secondary_ports, "port2", "ips")
\r
155 ha_vrrp_ip_address = ha_ip_address_1
\r
156 ha_ip_mask = convert_numeric_ip_to_symbolic(cidr_to_mask(get_property_per_port(primary_ports, "port2", "mask")))
\r
159 secondary_adc = null
\r
160 secondary_config = null
\r
161 secondary_ports = null
\r
162 ha_ip_address_1 = "1.1.1.1"
\r
163 ha_ip_address_2 = "1.1.1.2"
\r
164 ha_vrrp_ip_address = "1.1.1.3"
\r
165 ha_ip_mask = "255.255.255.255"
\r