def wrapper(self, *args, **kwargs): vthunder = kwargs.get('vthunder') if vthunder: api_ver = acos_client.AXAPI_21 if vthunder.axapi_version == 21 else acos_client.AXAPI_30 self.axapi_client = acos_client.Client(vthunder.ip_address, api_ver, vthunder.username, vthunder.password, timeout=30) if vthunder.partition_name != a10constants.SHARED_PARTITION: activate_partition(self.axapi_client, vthunder.partition_name) else: self.axapi_client = None result = func(self, *args, **kwargs) try: self.axapi_client.session.close() except ConnectionError as e: LOG.debug("Failed to close the vThunder session: %s", str(e)) except AttributeError: pass return result
def _get_ve_ip(self, vlan_id, vthunder, device_id=None): master_device_id = vthunder.device_network_map[0].vcs_device_id if master_device_id != device_id: api_ver = acos_client.AXAPI_21 if vthunder.axapi_version == 21 else acos_client.AXAPI_30 device_obj = vthunder.device_network_map[1] client = acos_client.Client(device_obj.mgmt_ip_address, api_ver, vthunder.username, vthunder.password, timeout=30) if vthunder.partition_name != "shared": activate_partition(client, vthunder.partition_name) close_axapi_client = True else: client = self.axapi_client close_axapi_client = False try: resp = client.interface.ve.get_oper(vlan_id) if close_axapi_client: client.session.close() ve = resp.get('ve') if ve and ve.get('oper') and ve['oper'].get('ipv4_list'): ipv4_list = ve['oper']['ipv4_list'] if ipv4_list: return ipv4_list[0]['addr'] except (acos_errors.ACOSException, req_exceptions.ConnectionError) as e: LOG.warning("Failed to get ve ip from device id %s: %s", str(device_id), str(e))
def wrapper(self, *args, **kwargs): vthunder = kwargs.get('vthunder') use_shared_partition = kwargs.get('write_mem_shared_part', False) if vthunder: api_ver = acos_client.AXAPI_21 if vthunder.axapi_version == 21 else acos_client.AXAPI_30 self.axapi_client = acos_client.Client(vthunder.ip_address, api_ver, vthunder.username, vthunder.password, timeout=30) if use_shared_partition or vthunder.partition_name == 'shared': activate_partition(self.axapi_client, "shared") else: if vthunder.partition_name != "shared": activate_partition(self.axapi_client, vthunder.partition_name) else: self.axapi_client = None result = func(self, *args, **kwargs) try: self.axapi_client.session.close() except ConnectionError as e: LOG.debug("Failed to close the vThunder session: %s", str(e)) except AttributeError: pass return result
def get_a10_client(self, device_info, **kwargs): return acos_client.Client(device_info['host'], device_info['api_version'], device_info['username'], device_info['password'], port=device_info['port'], protocol=device_info['protocol'])
def client_factory(self, vthunder): c = acos_client.Client(vthunder.ip_address, str(vthunder.axapi_version), vthunder.username, vthunder.password, timeout=CONF.vthunder.default_axapi_timeout) return c
def _get_a10_client(self, device_info, **kwargs): if hasattr(self.hooks, 'get_a10_client'): return self.hooks.get_a10_client(device_info, **kwargs) else: return acos_client.Client( device_info['host'], device_info['api_version'], device_info['username'], device_info['password'], port=device_info['port'], protocol=device_info['protocol'])
def get_axapi_client(vthunder): api_ver = acos_client.AXAPI_21 if vthunder.axapi_version == 21 else acos_client.AXAPI_30 axapi_client = acos_client.Client(vthunder.ip_address, api_ver, vthunder.username, vthunder.password, timeout=30) return axapi_client
def get_client(h, password=None): p = password or h['password'] c = acos_client.Client(h['host'], h['axapi'], h['user'], p, port=h['port'], protocol=h['protocol']) return c
def __enter__(self): c = acos_client.Client('localhost', acos_client.AXAPI_21, self.parent.username, self.parent.password) c.http._http = self.parent.mock() c.session.http._http = c.http._http if self.session_id is not None: c.session.session_id = self.session_id return c
def get_a10_client(self, device_info, **kwargs): if kwargs.get('action', None) == 'create': retry = [errno.EHOSTUNREACH, errno.ECONNRESET, errno.ECONNREFUSED, errno.ETIMEDOUT] return acos_client.Client( device_info['host'], device_info['api_version'], device_info['username'], device_info['password'], port=device_info['port'], protocol=device_info['protocol'], retry_errno_list=retry) else: return super(VThunderPerTenantPlumbingHooks, self).get_a10_client(device_info, **kwargs)
def login(self, str_api_version): try: return acos.Client(self.config['appliance']['target'], self._get_axapi_version(str_api_version), self.config['appliance']['userid'], self.config['appliance']['passwd']) except acos.errors.ACOSUnsupportedVersion as e: self.logger.error(e) except KeyError as e: self.logger.error(e)
def get_acos_lient(admin, password): config = configparser.ConfigParser() module_path = os.path.dirname(__file__) filename = os.path.join(module_path, 'load_balancer.conf') config.read(filename) host_name = config.get('test', 'a10_domain') version = config.get('test', 'acos_version') admin_name = admin admin_pass = password try: if version == '3.0': return acos.Client(host_name, acos.AXAPI_30, admin_name, admin_pass) else: return acos.Client(host_name, acos.AXAPI_21, admin_name, admin_pass) except Exception as e: print('Http request error: ' + str(e))
def login(self, appliance): try: config = next(x for x in self.config['appliance'] if x['target'] == appliance) return acos.Client(config['target'], config['api_version'], config['userid'], config['passwd']) except acos.errors.ACOSUnsupportedVersion as e: self.logger.error(e) except KeyError as e: self.logger.error(e) except StopIteration: self.logger.error( "Specified appliance(%s) doesn't exist in the configuration file " % appliance)
def main(): config = configparser.ConfigParser() module_path = os.path.dirname(__file__) filename = os.path.join(module_path, 'load_balancer.conf') config.read(filename) host_name = config.get('test', 'a10_domain') admin_name = config.get('test', 'a10_admin_name') admin_pass = config.get('test', 'a10_admin_passport') try: c = acos.Client(host_name, acos.AXAPI_30, admin_name, admin_pass) except Exception as e: print('Http request error: ' + str(e.message)) return parser = argparse.ArgumentParser() parser.add_argument("-lg", '--groupName', help="List all service group or one group") parser.add_argument("-ls", '--status', help="List servers according to state") parser.add_argument("-ss", '--serverName', help="Show a server's information") parser.add_argument("-es", "--disabledServerName", "--disabledServerIP", help="Enable a server") parser.add_argument("-ds", "--enabledServerName", "--enabledServerIP", help="Disable a server") parser.add_argument("-ip", "--ipAddress", help="Ip address of server") args = parser.parse_args() if args.groupName: list_service_group(c, args.groupName) if args.status: list_servers(c, args.status) if args.serverName: show_server_info(c, args.serverName) if args.disabledServerName and args.ipAddress: enable_server(c, args.disabledServerName, args.ipAddress) if args.enabledServerName and args.ipAddress: disable_server(c, args.enabledServerName, args.ipAddress) if args.disabledServerName == 'all': enable_all_servers(c)
def _create_new_acos_client(self, d, sleep_time_on_error=0.5): client = acos_client.Client(d['host'], d.get('api_version', acos_client.AXAPI_30), d['username'], d['password'], port=d['port'], protocol=d['protocol']) final_client = None for i in range(1, 10): if (client.session.id is not None): final_client = client break else: time.sleep(sleep_time_on_error) return final_client
def __init__(self, host, username, password, partition='shared', session_id=None, timeout=None): self.host = host self.username = username self.password = password self.partition = partition self.client = acos_client.Client(self.host, acos_client.AXAPI_21, self.username, self.password, timeout=timeout) if session_id is not None: self.client.session.session_id = session_id self.client.session_retries = 0 try: self.client.system.partition.active(args.partition) except acos_errors.InvalidSessionID, ex: raise Exception('Session has expired. Please re-login')
a10mgmtPort = os.environ["a10mgmtPort"] a10proto = os.environ["a10mgmtProto"] # Create list of dependent service tiers dependencies = os.environ["CliqrDependencies"].split(",") # NOTE: THIS SCRIPT ONLY SUPPORTS THE FIRST DEPENDENT TIER!!! # Set the new server list from the CliQr environment serverIps = os.environ["CliqrTier_" + dependencies[0] + "_IP"].split(",") pool = 'pool' + os.environ['parentJobId'] vip = 'vip' + os.environ['parentJobId'] # healthMonitor = 'hm'+os.environ['parentJobId'] c = acos.Client(a10IP, acos.AXAPI_21, 'admin', 'welcome2cliqr', port=a10mgmtPort, protocol=a10proto) if cmd == "start": # Make a list out of the IP addresses of the web server tier. print serverIps # Create pool and add to VIP. c.slb.service_group.create(pool, c.slb.service_group.TCP, c.slb.service_group.ROUND_ROBIN) # Create and apply a health check for the pool # c.slb.hm.create(healthMonitor, c.slb.hm.HTTP, 5, 5, 5, 'GET', '/', '200', 80) # Apply a ping health-check to pool # c.slb.service_group.update(pool, health_monitor=ping) # Add each web server IP as a real server, then add it to the pool.
# -*- coding: utf-8 -*- __author__ = 'wenjiexu' # @Time : 18-1-17 下午8:34 # @File : tmp.py.py # @Description : import acos_client as acos c = acos.Client('10.5.36.4', acos.AXAPI_30, 'opsadmin', 'md7jrH7eH<Qkzoi2i4uv', port=80, protocol='http') c.partition.active("L3V-GW02") c.devicecontext.switch_context(2) print c.network.vlan.get_all()
def _get_a10_client(self, device_info): d = device_info return acos_client.Client(d['host'], d.get('api_version', acos_client.AXAPI_21), d['username'], d['password'], port=d['port'], protocol=d['protocol'])
def __init__(self): self.c = acos_client.Client('138.197.107.20', acos_client.AXAPI_21, 'admin', 'a10') self._lb_repo = repo.LoadBalancerRepository() self._octavia_driver_db = driver_lib.DriverLibrary()
def client_factory(self, vthunder): axapi_version = acos_client.AXAPI_21 if vthunder.axapi_version == 21 else acos_client.AXAPI_30 c = acos_client.Client(vthunder.ip_address, axapi_version, vthunder.username, vthunder.password) return c