def delete_health_monitor(self, argu): cmd_apv_detach_hm = ADCDevice.detach_hm_to_group( argu['pool_id'], argu['hm_id']) cmd_apv_no_hm = ADCDevice.no_health_monitor(argu['hm_id']) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_apv_detach_hm) self.run_cli_extend(base_rest_url, cmd_apv_no_hm)
def _delete_vip(self, va_name, pool_id, vip_id, vlan_tag, updated): interface_name = self.in_interface if vlan_tag != 'None': interface_name = "vlan." + vlan_tag # configure vip cmd_apv_no_ip = ADCDevice.no_ip(interface_name) cmd_apv_no_route = ADCDevice.clear_route() cmd_avx_no_ip = "va run %s \"%s\"" % (va_name, cmd_apv_no_ip) cmd_avx_no_route = "va run %s \"%s\"" % (va_name, cmd_apv_no_route) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_no_ip) self.run_cli_extend(base_rest_url, cmd_avx_no_route) if updated: self.cache.remove_vip(pool_id, vip_id) self.cache.dump() if vlan_tag != 'None': cmd_apv_no_vlan_device = ADCDevice.no_vlan_device(interface_name) cmd_avx_no_vlan_device = "va run %s \"%s\"" % ( va_name, cmd_apv_no_vlan_device) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_no_vlan_device)
def no_ha(self, va_name, vlan_tag): """ clear the HA configuration when delete_vip """ if len(self.hostnames) == 1: LOG.debug("Only one machine, doesn't need to configure HA") return True interface_name = self.in_interface if vlan_tag != 'None': interface_name = "vlan." + vlan_tag cmd_apv_disable_cluster = ADCDevice.cluster_disable(interface_name) cmd_avx_disable_cluster = "va run %s \"%s\"" % ( va_name, cmd_apv_disable_cluster) cmd_apv_clear_cluster_config = ADCDevice.cluster_clear_virtual_interface( interface_name) cmd_avx_clear_cluster_config = "va run %s \"%s\"" % ( va_name, cmd_apv_clear_cluster_config) for base_rest_url in self.base_rest_urls: # disable the virtual cluster self.run_cli_extend(base_rest_url, cmd_avx_disable_cluster) # clear the configuration of this virtual ifname self.run_cli_extend(base_rest_url, cmd_avx_clear_cluster_config)
def delete_group(self, argu, updated=True): """Delete SLB group in lb-pool-delete""" va_name = self.get_va_name(argu) cmd_apv_no_group = ADCDevice.no_group(argu['pool_id']) cmd_avx_no_group = "va run %s \"%s\"" % (va_name, cmd_apv_no_group) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_no_group) member_dict = argu['members'] for member in member_dict.keys(): cmd_apv_no_member = ADCDevice.no_real_server( member_dict[member], member) cmd_avx_no_member = "va run %s \"%s\"" % (va_name, cmd_apv_no_member) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_no_member) for health_monitor in argu['health_monitors']: cmd_apv_no_hm = ADCDevice.no_health_monitor(health_monitor) cmd_avx_no_hm = "va run %s \"%s\"" % (va_name, cmd_apv_no_hm) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_no_hm) if updated: self.write_memory(argu) self.cache.remove_group(argu['pool_id'])
def delete_health_monitor(self, argu): va_name = self.get_va_name(argu) cmd_apv_detach_hm = ADCDevice.detach_hm_to_group( argu['pool_id'], argu['hm_id']) cmd_apv_no_hm = ADCDevice.no_health_monitor(argu['hm_id']) cmd_avx_detach_hm = "va run %s \"%s\"" % (va_name, cmd_apv_detach_hm) cmd_avx_no_hm = "va run %s \"%s\"" % (va_name, cmd_apv_no_hm) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_detach_hm) self.run_cli_extend(base_rest_url, cmd_avx_no_hm)
def create_health_monitor(self, argu): if not argu: LOG.error("In delete_member, it should not pass the None.") cmd_apv_create_hm = ADCDevice.create_health_monitor( argu['hm_id'], argu['hm_type'], argu['hm_delay'], argu['hm_max_retries'], argu['hm_timeout'], argu['hm_http_method'], argu['hm_url'], argu['hm_expected_codes']) cmd_apv_attach_hm = ADCDevice.attach_hm_to_group( argu['pool_id'], argu['hm_id']) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_apv_create_hm) self.run_cli_extend(base_rest_url, cmd_apv_attach_hm)
def _delete_group(self, va_name, pool_id): cmd_apv_delete_group = ADCDevice.no_group(pool_id) cmd_avx_delete_group = "va run %s \"%s\"" % (va_name, cmd_apv_delete_group) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_delete_group)
def _create_group(self, pool_id, lb_algorithm, pk_type): """ Create SLB group in lb-pool-create""" cmd_apv_create_group = ADCDevice.create_group(pool_id, lb_algorithm, pk_type) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_apv_create_group)
def _delete_policy(self, vip_id, session_persistence_type, lb_algorithm): """ Delete SLB policy """ cmd_apv_no_policy = ADCDevice.no_policy(vip_id, lb_algorithm, session_persistence_type) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_apv_no_policy)
def _create_vs(self, vip_id, vip_address, protocol, protocol_port, connection_limit): cmd_apv_create_vs = ADCDevice.create_virtual_service( vip_id, vip_address, protocol_port, protocol, connection_limit) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_apv_create_vs)
def _create_group(self, va_name, pool_id, lb_algorithm, sp_type): cmd_apv_create_group = ADCDevice.create_group(pool_id, lb_algorithm, sp_type) cmd_avx_create_group = "va run %s \"%s\"" % (va_name, cmd_apv_create_group) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_create_group)
def create_health_monitor(self, argu): va_name = self.get_va_name(argu) cmd_apv_create_hm = ADCDevice.create_health_monitor( argu['hm_id'], argu['hm_type'], argu['hm_delay'], argu['hm_max_retries'], argu['hm_timeout'], argu['hm_http_method'], argu['hm_url'], argu['hm_expected_codes']) cmd_apv_attach_hm = ADCDevice.attach_hm_to_group( argu['pool_id'], argu['hm_id']) cmd_avx_create_hm = "va run %s \"%s\"" % (va_name, cmd_apv_create_hm) cmd_avx_attach_hm = "va run %s \"%s\"" % (va_name, cmd_apv_attach_hm) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_create_hm) self.run_cli_extend(base_rest_url, cmd_avx_attach_hm)
def write_memory(self, argu): va_name = self.get_va_name(argu) cmd_apv_write_memory = ADCDevice.write_memory() cmd_avx_write_memory = "va run %s \"%s\"" % (va_name, cmd_apv_write_memory) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_write_memory)
def _create_policy(self, pool_id, vip_id, session_persistence_type, lb_algorithm, cookie_name): """ Create SLB policy """ cmd_apv_create_policy = ADCDevice.create_policy( vip_id, pool_id, lb_algorithm, session_persistence_type, cookie_name) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_apv_create_policy)
def create_member(self, argu): """ create a member""" va_name = self.get_va_name(argu) cmd_apv_create_real_server = ADCDevice.create_real_server( argu['member_id'], argu['member_address'], argu['member_port'], argu['protocol']) cmd_apv_add_rs_into_group = ADCDevice.add_rs_into_group( argu['pool_id'], argu['member_id'], argu['member_weight']) cmd_avx_create_rs = "va run %s \"%s\"" % (va_name, cmd_apv_create_real_server) cmd_avx_add_rs_into_group = "va run %s \"%s\"" % ( va_name, cmd_apv_add_rs_into_group) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_create_rs) self.run_cli_extend(base_rest_url, cmd_avx_add_rs_into_group)
def delete_group(self, argu, updated): """Delete SLB group in lb-pool-delete""" cmd_apv_no_group = ADCDevice.no_group(argu['pool_id']) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_apv_no_group) member_dict = argu['members'] for member in member_dict.keys(): cmd_apv_no_member = ADCDevice.no_real_server( member_dict[member], member) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_apv_no_member) for health_monitor in argu['health_monitors']: cmd_apv_no_hm = ADCDevice.no_health_monitor(health_monitor) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_apv_no_hm) self.write_memory(argu)
def delete_member(self, argu): """ Delete a member""" va_name = self.get_va_name(argu) cmd_apv_no_rs = ADCDevice.no_real_server(argu['protocol'], argu['member_id']) cmd_avx_no_rs = "va run %s \"%s\"" % (va_name, cmd_apv_no_rs) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_no_rs)
def update_member(self, argu): """ Update a member""" va_name = self.get_va_name(argu) cmd_apv_add_rs_into_group = ADCDevice.add_rs_into_group( argu['pool_id'], argu['member_id'], argu['member_weight']) cmd_avx_add_rs_into_group = "va run %s \"%s\"" % ( va_name, cmd_apv_add_rs_into_group) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_add_rs_into_group)
def config_ha(self, va_name, vlan_tag, vip_address): """ set the HA configuration when create_vip """ if len(self.hostnames) == 1: LOG.debug("Only one machine, doesn't need to configure HA") return True interface_name = self.in_interface if vlan_tag != 'None': interface_name = "vlan." + vlan_tag cmd_apv_config_virtual_iface = ADCDevice.cluster_config_virtual_interface( interface_name) cmd_apv_config_virtual_vip = ADCDevice.cluster_config_vip( interface_name) cmd_apv_cluster_enable = ADCDevice.cluster_enable(interface_name) cmd_avx_config_virtual_iface = "va run %s \"%s\"" % ( va_name, cmd_apv_config_virtual_iface) cmd_avx_config_virtual_vip = "va run %s \"%s\"" % ( va_name, cmd_apv_config_virtual_vip) cmd_avx_cluster_enable = "va run %s \"%s\"" % (va_name, cmd_apv_cluster_enable) priority = 1 for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_config_virtual_iface) self.run_cli_extend(base_rest_url, cmd_avx_config_virtual_vip) priority += 10 cmd_apv_config_virtual_prior = ADCDevice.cluster_config_priority( interface_name, priority) cmd_avx_config_cluster_prior = "va run %s \"%s\"" % ( va_name, cmd_apv_config_virtual_prior) self.run_cli_extend(base_rest_url, cmd_avx_config_cluster_prior) self.run_cli_extend(base_rest_url, cmd_avx_cluster_enable)
def _delete_vs(self, va_name, vip_id, protocol): cmd_apv_no_vs = ADCDevice.no_virtual_service(vip_id, protocol) cmd_avx_no_vs = "va run %s \"%s\"" % (va_name, cmd_apv_no_vs) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_no_vs)
def _create_vip(self, va_name, pool_id, vip_id, vlan_tag, vip_address, netmask, interface_mapping, vip_port_mac, gateway_ip): """ create vip""" interface_name = self.in_interface # mock to set the mac if vip_port_mac: mock_mac = "0c:c4:7a:7c:af:f6" cmd_apv_config_mac = "interface mac %s %s" % (interface_name, mock_mac) cmd_avx_config_mac = "va run %s \"%s\"" % (va_name, cmd_apv_config_mac) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_config_mac) time.sleep(1) # update the mac if vip_port_mac: cmd_apv_config_mac = "interface mac %s %s" % (interface_name, vip_port_mac) cmd_avx_config_mac = "va run %s \"%s\"" % (va_name, cmd_apv_config_mac) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_config_mac) # create vlan if vlan_tag != 'None': interface_name = "vlan." + vlan_tag cmd_apv_config_vlan = ADCDevice.vlan_device( self.in_interface, interface_name, vlan_tag) cmd_avx_config_vlan = "va run %s \"%s\"" % (va_name, cmd_apv_config_vlan) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_config_vlan) # configure vip if len(self.hostnames) == 1: LOG.debug("Configure the vip address into interface") cmd_apv_config_ip = ADCDevice.configure_ip(interface_name, vip_address, netmask) cmd_apv_config_route = ADCDevice.configure_route(gateway_ip) cmd_avx_config_ip = "va run %s \"%s\"" % (va_name, cmd_apv_config_ip) cmd_avx_config_route = "va run %s \"%s\"" % (va_name, cmd_apv_config_route) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_avx_config_ip) self.run_cli_extend(base_rest_url, cmd_avx_config_route) else: for host in self.hostnames: iface = interface_mapping[host] ip = iface['address'] cmd_apv_config_ip = ADCDevice.configure_ip( interface_name, ip, netmask) cmd_apv_config_route = ADCDevice.configure_route(gateway_ip) cmd_avx_config_ip = "va run %s \"%s\"" % (va_name, cmd_apv_config_ip) cmd_avx_config_route = "va run %s \"%s\"" % ( va_name, cmd_apv_config_route) base_rest_url = "https://" + host + ":9997/rest/avx" self.run_cli_extend(base_rest_url, cmd_avx_config_ip) self.run_cli_extend(base_rest_url, cmd_avx_config_route) self.cache.put(pool_id, vip_id, host, iface['port_id']) self.cache.dump()
def write_memory(self, argu): cmd_apv_write_memory = ADCDevice.write_memory() for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_apv_write_memory)
def _delete_vs(self, vip_id, protocol): cmd_apv_no_vs = ADCDevice.no_virtual_service(vip_id, protocol) for base_rest_url in self.base_rest_urls: self.run_cli_extend(base_rest_url, cmd_apv_no_vs)