def run_test(parsed_args): chassis = connect(parsed_args.log, parsed_args.chassis) for port in parsed_args.ports: XenaPort(chassis, port).reserve(force=True) for port in chassis.ports.values(): port.clear_stats() for stream in port.streams.values(): stream.set_state(XenaStreamState.enabled) chassis.start_traffic() time.sleep(parsed_args.time) chassis.stop_traffic() time.sleep(2) counters = parsed_args.counters if hasattr(parsed_args, 'counters') else None with open(parsed_args.results, 'w+') as f: ports_stats = XenaPortsStats(chassis.parent) ports_stats.read_stats() if counters: f.write('port,{}\n'.format(','.join(counters))) for port in chassis.ports: line = port for counter in counters: line += ',' line += str(ports_stats.get_flat_stats()[port][counter]) f.write('{}\n'.format(line)) else: f.write(json.dumps(ports_stats.get_flat_stats(), indent=2)) for port in chassis.ports.values(): port.release()
def inventory(self): """ Get module inventory. """ self.m_info = self.get_attributes() if 'NOTCFP' in self.m_info['m_cfptype']: a = self.get_attribute('m_portcount') m_portcount = int(a) else: m_portcount = int(self.get_attribute('m_cfpconfig').split()[0]) for p_index in range(m_portcount): XenaPort(parent=self, index='{}/{}'.format(self.index, p_index)).inventory()
def measure(): global ports # Pet ports XenaPort(parent=chassis, index=port0) XenaPort(parent=chassis, index=port1) port_stats = XenaPortsStats(xm.session) streams_stats = XenaStreamsStats(xm.session) # Loop for 10 seconds or any condition you want for _ in range(10): # Get statistics. port_stats.read_stats() streams_stats.read_stats() print(port_stats.statistics.dumps()) print(streams_stats.statistics.dumps()) time.sleep(1)
def load_config(self, context, xena_configs_folder): reservation_id = context.reservation.reservation_id my_api = CloudShellSessionContext(context).get_api() reservation_ports = get_reservation_resources( my_api, reservation_id, 'Xena Chassis Shell 2G.GenericTrafficGeneratorPort') for reserved_port in reservation_ports: config = get_family_attribute(my_api, reserved_port, 'Logical Name').Value.strip() address = get_address(reserved_port) self.logger.debug( 'Configuration {} will be loaded on Physical location {}'. format(config, address)) chassis = my_api.GetResourceDetails( reserved_port.Name.split('/')[0]) encripted_password = my_api.GetAttributeValue( chassis.Name, 'Xena Chassis Shell 2G.Password').Value password = CloudShellSessionContext( context).get_api().DecryptPassword(encripted_password).Value tcp_port = my_api.GetAttributeValue( chassis.Name, 'Xena Chassis Shell 2G.Controller TCP Port').Value if not tcp_port: tcp_port = '22611' ip, module, port = address.split('/') self.xm.session.add_chassis(ip, int(tcp_port), password) xena_port = XenaPort(self.xm.session.chassis_list[ip], '{}/{}'.format(module, port)) xena_port.reserve(force=True) xena_port.load_config( path.join(xena_configs_folder, config) + '.xpc')
def load_config(parsed_args): chassis = connect(parsed_args.log, parsed_args.chassis) with open(parsed_args.input) as f: commands = f.read().splitlines() for command in commands: if command.startswith(';'): port = XenaPort(chassis, command.split(':')[1].strip()) port.reserve(force=True) elif command.startswith('P_LPTXMODE'): pass else: if not command.startswith('P_LPTXMODE'): port.send_command(command) for port in chassis.ports.values(): port.release()
def reserve_ports(self, locations, force=False, reset=True): """ Reserve ports and reset factory defaults. XenaManager-2G -> Reserve/Relinquish Port. XenaManager-2G -> Reset port. :param locations: list of ports locations in the form <module/port> to reserve :param force: True - take forcefully, False - fail if port is reserved by other user :param reset: True - reset port, False - leave port configuration :return: ports dictionary (index: object) """ for location in locations: if self.modules[int(location.split('/')[0])].capabilities.values['ischimera']: port = XenaChimeraPort(parent=self, index=location) else: port = XenaPort(parent=self, index=location) port.reserve(force) if reset: port.reset() return self.ports