def test_get_vip_secuirty_group_name(self): FAKE_LB_ID = uuidutils.generate_uuid() self.assertIsNone(utils.get_vip_security_group_name(None)) expected_sg_name = constants.VIP_SECURITY_GROUP_PREFIX + FAKE_LB_ID self.assertEqual(expected_sg_name, utils.get_vip_security_group_name(FAKE_LB_ID))
def _get_lb_security_group(self, load_balancer_id): sec_grp_name = common_utils.get_vip_security_group_name( load_balancer_id) sec_grps = self.neutron_client.list_security_groups(name=sec_grp_name) if sec_grps and sec_grps.get(constants.SECURITY_GROUPS): return sec_grps.get(constants.SECURITY_GROUPS)[0] return None
def update_vip_sg(self, load_balancer, vip): if self.sec_grp_enabled: sec_grp = self._get_lb_security_group(load_balancer.id) if not sec_grp: sec_grp_name = common_utils.get_vip_security_group_name( load_balancer.id) sec_grp = self._create_security_group(sec_grp_name) self._update_security_group_rules(load_balancer, sec_grp.get(constants.ID)) self._add_vip_security_group_to_port(load_balancer.id, vip.port_id, sec_grp.get(constants.ID)) return sec_grp.get(constants.ID) return None
def execute(self, loadbalancer_id): sg_name = utils.get_vip_security_group_name(loadbalancer_id) try: security_group = self.network_driver.get_security_group(sg_name) if security_group: return security_group.id except base.SecurityGroupNotFound: with excutils.save_and_reraise_exception() as ctxt: if self.network_driver.sec_grp_enabled: LOG.error('VIP security group %s was not found.', sg_name) else: ctxt.reraise = False return None