Skip to content

Commit

Permalink
fix update ports in created vips
Browse files Browse the repository at this point in the history
fix create of vip in brocade
  • Loading branch information
edersonbrilhante committed Aug 24, 2016
1 parent dde56b8 commit fcedcb5
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 43 deletions.
7 changes: 2 additions & 5 deletions networkapi/api_pools/facade/v3/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from networkapi.api_pools import models
from networkapi.distributedlock import distributedlock
from networkapi.distributedlock import LOCK_POOL
from networkapi.equipamento.models import Equipamento
from networkapi.healthcheckexpect.models import Healthcheck
from networkapi.infrastructure.datatable import build_query_to_datatable
from networkapi.ip.models import Ip
Expand Down Expand Up @@ -244,13 +243,13 @@ def _create_pool_member(members, pool):
for member in members:
ip = Ip.get_by_pk(member['ip']['id']) if member['ip'] else None
ipv6 = Ipv6.get_by_pk(member['ipv6']['id']) if member['ipv6'] else None
eqpt = Equipamento.get_by_pk(member['equipment']['id'])
identifier = ip.ip_formated if ip else ipv6.ip_formated

pool_member = ServerPoolMember()
pool_member.server_pool = pool
pool_member.ip = ip
pool_member.ipv6 = ipv6
pool_member.identifier = eqpt.nome
pool_member.identifier = identifier
pool_member.weight = member['weight']
pool_member.priority = member['priority']
pool_member.port_real = member['port_real']
Expand Down Expand Up @@ -286,12 +285,10 @@ def _update_pool_member(members):
for member in members:
ip = Ip.get_by_pk(member['ip']['id']) if member['ip'] else None
ipv6 = Ipv6.get_by_pk(member['ipv6']['id']) if member['ipv6'] else None
eqpt = Equipamento.get_by_pk(member['equipment']['id'])

pool_member = ServerPoolMember.objects.get(id=member['id'])
pool_member.ip = ip
pool_member.ipv6 = ipv6
pool_member.identifier = eqpt.nome
pool_member.weight = member['weight']
pool_member.priority = member['priority']
pool_member.port_real = member['port_real']
Expand Down
62 changes: 37 additions & 25 deletions networkapi/api_vip_request/facade/facade_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ def update_real_vip_request(vip_requests, user):
load_balance = dict()
keys = list()
for vip in vip_requests:

vip_request = copy.deepcopy(vip)

vip_old = models.VipRequest.get_by_pk(vip.get('id'))
Expand All @@ -695,33 +696,44 @@ def update_real_vip_request(vip_requests, user):
update_vip_request(vip)

ids_port_old = [port.get('id') for port in serializer_vips_data.get('ports')]
ids_port_new = [port.get('id') for port in vip_request.get('ports') if port.get('id')]
ids_port_all = [port.get('id') for port in vip_request.get('ports')]
ids_port_to_del = list(set(ids_port_old) - set(ids_port_new))
ids_port_to_change = list(set(ids_port_old) & set(ids_port_new))

for id_port_to_change in ids_port_to_change:
idx_pt_old = ids_port_old.index(id_port_to_change)
port_old = serializer_vips_data.get('ports')[idx_pt_old]
idx_pt_new = ids_port_old.index(id_port_to_change)
port_new = vip_request.get('ports')[idx_pt_new]
idx_pt_all = ids_port_all.index(id_port_to_change)

ids_pool_old = [pool.get('id') for pool in port_old.get('pools')]
ids_pool_new = [pool.get('id') for pool in port_new.get('pools') if pool.get('id')]
ids_pool_to_del = list(set(ids_pool_old) - set(ids_pool_new))

# pools to delete in ports dont delete
for id_pool_to_del in ids_pool_to_del:
idx_pl_del = ids_pool_old.index(id_pool_to_del)
pool_del = copy.deepcopy(port_old.get('pools')[idx_pl_del])
pool_del['delete'] = True
vip_request['ports'][idx_pt_all]['pools'].append(pool_del)
ids_port_upt = [port.get('id') for port in vip_request.get('ports') if port.get('id')]
ids_port_to_del = list(set(ids_port_old) - set(ids_port_upt))

# ports to change and insert
for idx_port, port in enumerate(vip_request.get('ports')):
# change port
if port.get('id'):

# idx port old
idx_port_old = ids_port_old.index(port.get('id'))
# port old
port_old = serializer_vips_data.get('ports')[idx_port_old]
# ids pools old
ids_pool_old = [pool.get('id') for pool in port_old.get('pools')]

# ids pools changed
ids_pool_cur = [pool.get('id') for pool in port_old.get('pools') if pool.get('id')]

# ids to delete
ids_pool_to_del = list(set(ids_pool_old) - set(ids_pool_cur))

# pools to delete in port
for id_pool in ids_pool_to_del:
# idx pool to delete
idx_pool_del = ids_pool_old.index(id_pool)

# pool to delete
pool_del = copy.deepcopy(port_old.get('pools')[idx_pool_del])
pool_del['delete'] = True
vip_request['ports'][idx_port]['pools'].append(pool_del)

# ports to delete
for id_port_to_del in ids_port_to_del:
idx_pt_del = ids_port_old.index(id_port_to_del)
port_del = copy.deepcopy(serializer_vips_data.get('ports')[idx_pt_del])
for id_port in ids_port_to_del:
# idx pool to delete
idx_port_del = ids_port_old.index(id_port)

# port to delete
port_del = copy.deepcopy(serializer_vips_data.get('ports')[idx_port_del])
port_del['delete'] = True
vip_request['ports'].append(port_del)

Expand Down
4 changes: 2 additions & 2 deletions networkapi/api_vip_request/views/views_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def delete(self, request, *args, **kwargs):

@permission_classes_apiview((IsAuthenticated, Write, DeployUpdate))
@permission_obj_apiview([deploy_vip_permission])
@raise_json_validate('vip_put')
@logs_method_apiview
def put(self, request, *args, **kwargs):
"""
Expand Down Expand Up @@ -143,9 +144,8 @@ def put(self, request, *args, **kwargs):
vips = request.DATA
json_validate(SPECS.get('vip_put')).validate(vips)
locks_list = facade.create_lock(vips.get('vips'))
verify_ports_vip(vips)
try:
verify_ports_vip(vips)

response = facade.update_real_vip_request(
vips['vips'], request.user)
except Exception, exception:
Expand Down
8 changes: 7 additions & 1 deletion networkapi/plugins/Brocade/Generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,21 @@ def delete_vip(self, vips):
vps = self.prepare_vips(vip)

for idx, vp in enumerate(vps):
pools_del += self._delete_vip(vp)
if idx != 0:
pools_del += self._delete_vip(vp)

return pools_del

def _delete_vip(self, vp):

pools_del = self._delete_vip_members(vp)

self.baddi.delete_vip(vp)

return pools_del

def _delete_vip_members(self, vp):

pools_del = list()
for member in vp.get('members'):
self.baddi.unbind_member_from_vip(member, vp)
Expand Down Expand Up @@ -377,6 +380,9 @@ def prepare_vips(self, vip):

def _prepare_healthcheck(self, hr):

if not hr:
hr = 'HEAD /'

rg = '^([\" ]?)+(GET|HEAD|POST|PUT|CONNECT|DELETE|OPTIONS|TRACE|PATCH)'
if not valid_regex(hr, rg):
hr = 'GET ' + hr
Expand Down
1 change: 0 additions & 1 deletion networkapi/plugins/Brocade/adx_device_driver_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ def _create_update_port_policy(self, healthmonitor):
.create('HttpPortPolicy'))
url_health_check = (self.slb_factory
.create('URLHealthCheck'))
url_health_check.url = 'HEAD /'
http_port_policy.urlStatusCodeInfo = url_health_check
http_port_policy.healthCheckType = 'SIMPLE'

Expand Down
3 changes: 2 additions & 1 deletion networkapi/plugins/Brocade/lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def __init__(self, hostname, username, password):

self.service_clients = (ClientCache
.get_adx_service_client(device))

except Exception, e:
logging.critical("Unable to connect to BROCADE. Details: %s" % (e))
raise base_exceptions.CommandErrorException(e)

log.info('connected in hostname:%s' % hostname)
16 changes: 8 additions & 8 deletions networkapi/plugins/F5/Generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ def __create_pool(self, pools):
members=pls['pools_members']['members'],
priority=pls['pools_members']['priority'])

plm.set_member_description(
names=pls['pools_names'],
members=pls['pools_members']['members'],
description=pls['pools_members']['description'])
# plm.set_member_description(
# names=pls['pools_names'],
# members=pls['pools_members']['members'],
# description=pls['pools_members']['description'])

plm.set_states(
names=pls['pools_names'],
Expand Down Expand Up @@ -389,10 +389,10 @@ def __update_pool(self, pools):
members=pls['pools_members']['members'],
priority=pls['pools_members']['priority'])

plm.set_member_description(
names=pls['pools_names'],
members=pls['pools_members']['members'],
description=pls['pools_members']['description'])
# plm.set_member_description(
# names=pls['pools_names'],
# members=pls['pools_members']['members'],
# description=pls['pools_members']['description'])

plm.set_states(
names=pls['pools_names'],
Expand Down

0 comments on commit fcedcb5

Please sign in to comment.