def show_vlan_internal(self): data = ovsdb.get_map('System', 'other_config') cli_out("Internal VLAN range; %s-%s" % (data.get( 'min_internal_vlan', ''), data.get('max_internal_vlan', ''))) cli_out("Internal VLAN policy: %s" % data.get('internal_vlan_policy', '')) cli_out("Assigned interfaces:")
def run(self, opts, flags): intf_token = context_get().obj condition = ['name', '==', str(intf_token)] intf_other_map = ovsdb.get_map('Interface', 'other_config', conditions=[condition]) # TODO should get 'rxtx' from defaults old_state = intf_other_map.get('lldp_enable_dir', 'rxtx') rx = tx = True if old_state == 'off': rx = tx = False else: if old_state.find('rx') == -1: rx = False if old_state.find('tx') == -1: tx = False while opts: if opts[0] == 'reception': rx = F_NO not in flags opts.pop(0) elif opts[0] == 'transmission': tx = F_NO not in flags opts.pop(0) if not rx and not tx: new_state = 'off' else: new_state = '' if rx: new_state += 'rx' if tx: new_state += 'tx' if old_state != new_state: ovsdb.map_set_key('Interface', 'other_config', 'lldp_enable_dir', new_state, conditions=[condition])
def generate_cli(): lines = [] results = ovsdb.get_map('System', column='aaa') aaa_config = ( ( 'radius', 'AAA_RADIUS', 'aaa authentication login radius' ), ( 'fallback', 'AAA_FALLBACK', 'aaa authentication login fallback error local' ), ( 'ssh_passkeyauthentication', 'SSH_AUTH_PASS', 'no ssh password-authentication' ), ( 'ssh_publickeyauthentication', 'SSH_AUTH_PUBKEY', 'no ssh public-key-authentication' ), ) for key, default, word in aaa_config: val = results.get(key) if val and val != DEFAULTS[default]: lines.append(word) return lines
def __init__(self, ovsdb_server, command_module_paths=None): super(Opscli, self).__init__(UnixConsole()) self.fix_syntax_table() # Initialize the OVSDB helper. ovsdb.Ovsdb(server=ovsdb_server) self.motd = CLI_MSG_MOTD self.prompt_base = 'Openswitch' try: # TODO shell hangs before prompt if this is down results = ovsdb.get_map('System', column='mgmt_intf_status') if 'hostname' in results: self.prompt_base = results['hostname'] except Exception as e: cli_err("Unable to connect to %s: %s." % (ovsdb_server, str(e))) raise Exception # Initialize command tree. for path in command_module_paths: if not os.path.isdir(path): cli_warn("Ignoring invalid module path '%s'." % path) continue self.load_commands(path) self.fixup_contexts() context_push('root') if debug_is_on('cli'): context_get().cmdtree.dump_tree() self.init_ctrl_c() self.init_qhelp() self.init_completion() self.init_history()
def generate_cli(): lines = [] results = ovsdb.get_map('System', column='lacp_config') val = results.get('lacp-system-priority') if val: lines.append("lacp system-priority %s" % val) return lines
def show_vlan_internal(self): data = ovsdb.get_map('System', 'other_config') cli_out("Internal VLAN range; %s-%s" % ( data.get('min_internal_vlan', ''), data.get('max_internal_vlan', ''))) cli_out("Internal VLAN policy: %s" % data.get('internal_vlan_policy', '')) cli_out("Assigned interfaces:")
def run(self, opts, flags): while opts: if opts[0] == 'enable': value = F_NO not in flags ovsdb.map_set_key('System', 'other_config', 'lldp_enable', str(value).lower()) opts.pop(0) elif opts[0] == 'management-address': if F_NO in flags: ovsdb.map_delete_key('System', 'other_config', 'lldp_mgmt_addr') else: ovsdb.map_set_key('System', 'other_config', 'lldp_mgmt_addr', str(opts[1])) opts.pop(0) opts.pop(0) elif opts[0] == 'holdtime': if F_NO in flags: ovsdb.map_delete_key('System', 'other_config', 'lldp_hold') else: ovsdb.map_set_key('System', 'other_config', 'lldp_hold', str(opts[1])) opts.pop(0) opts.pop(0) elif opts[0] == 'timer': if F_NO in flags: ovsdb.map_delete_key('System', 'other_config', 'lldp_tx_interval') else: ovsdb.map_set_key('System', 'other_config', 'lldp_tx_interval', str(opts[1])) opts.pop(0) opts.pop(0) elif opts[0] == 'select-tlv': for word, map_key, descr in tlv_keys: if opts[1] == word: key = map_key break value = str(F_NO not in flags).lower() ovsdb.map_set_key('System', 'other_config', key, value) opts.pop(0) opts.pop(0) elif opts[0] == 'clear': if opts[1] == 'counters': sem = 'lldp_num_clear_counters_requested' elif opts[1] == 'neighbors': sem = 'lldp_num_clear_table_requested' req = ovsdb.get_map('System', 'status') counter = int(req.get(sem, 0)) counter += 1 ovsdb.map_set_key('System', 'status', sem, str(counter)) opts.pop(0) opts.pop(0)
def get_global_config(): data = {} results = ovsdb.get_map('System', column='other_config') data['lldp_enable'] = results.get('lldp_enable', False) == 'true' data['lldp_holdtime'] = int(results.get('lldp_hold', DEFAULTS['LLDP_HOLDTIME'])) data['lldp_tx_interval'] = int(results.get('lldp_tx_interval', DEFAULTS['LLDP_TIMER'])) data['lldp_mgmt_addr'] = results.get('lldp_mgmt_addr', '') return data
def generate_cli(): lines = [] results = ovsdb.get_map('System', column='logrotate_config') logrotate_config = ( ['period', 'LOGROTATE_PERIOD', 'period'], ['maxsize', 'LOGROTATE_MAXSIZE', 'maxsize'], ['target', 'LOGROTATE_TARGET', 'target'], ) for key, default, word in logrotate_config: val = results.get(key) if val and val != DEFAULTS[default]: lines.append("logrotate %s %s" % (word, val)) return lines
def generate_cli(): lines = [] # hostname results = ovsdb.get_map('System', column='mgmt_intf_status') lines.append("hostname %s" % results.get('hostname', '')) # alias results = ovsdb.get('CLI_Alias', columns=['alias_name', 'alias_definition']) for row in results: lines.append("alias %s %s" % (row['alias_name'], row['alias_definition'])) return lines
def get_tlv_keys(enabled=None, key='config'): if key not in ('config', 'cli', 'descr'): raise Exception('invalid key') data = OrderedDict() results = ovsdb.get_map('System', column='other_config') for config_key, default, cli_word, descr in lldp_tlv_keys: value = results.get(config_key, DEFAULTS[default]) == 'true' if enabled is None or enabled == value: if key == 'config': od_key = config_key elif key == 'cli': od_key = cli_word else: od_key = descr data[od_key] = value return data
def generate_cli(): lines = [] results = ovsdb.get_map('System', column='other_config') if results.get('lldp_enable', '') == 'true': lines.append('lldp enable') val = results.get('lldp_hold') if val and val != DEFAULTS['LLDP_HOLDTIME']: lines.append("lldp holdtime %s" % val) val = results.get('lldp_tx_interval') if val and val != DEFAULTS['LLDP_TIMER']: lines.append("lldp timer %s" % val) val = results.get('lldp_mgmt_addr') if val: lines.append("lldp management-address %s" % val) lldp_tlv_config = ( ('lldp_tlv_mgmt_addr_enable', 'LLDP_TLV_MGMT_ADDR', 'management-address'), ('lldp_tlv_port_proto_vlan_id_enable', 'LLDP_TLV_PROTO_VLAN_ID', 'port-protocol-vlan-id'), ('lldp_tlv_port_proto_id_enable', 'LLDP_TLV_PORT_PROTO_ID', 'port-protocol-id'), ('lldp_tlv_port_vlan_name_enable', 'LLDP_TLV_PORT_VLAN_NAME', 'port-vlan-name'), ('lldp_tlv_port_desc_enable', 'LLDP_TLV_PORT_DESC', 'port-description'), ('lldp_tlv_port_vlan_id_enable', 'LLDP_TLV_PORT_VLAN_ID', 'port-vlan-id'), ('lldp_tlv_sys_cap_enable', 'LLDP_TLV_SYS_CAP', 'system-capabilities'), ('lldp_tlv_sys_desc_enable', 'LLDP_TLV_SYS_DESC', 'system-description'), ('lldp_tlv_sys_name_enable', 'LLDP_TLV_SYS_NAME', 'system-name'), ) for key, default, word in lldp_tlv_config: val = results.get(key) if val and val != DEFAULTS[default]: lines.append("no lldp select-tlv %s" % word) return lines
def run(self, opts, flags): data = ovsdb.get_map('Subsystem', 'other_config') out_kv('system-fan', data)
def run(self, opts, flags): data = ovsdb.get_map('Subsystem', 'other_info') out_kv('system', data)
def show_tlv(): results = ovsdb.get_map('System', 'other_config') cli_out('TLVs advertised:') data = ops.lldp.get_tlv_keys(enabled=True, key='config') out_keys('lldp_tlv', data)
def generate_cli(): lines = [] results = ovsdb.get_map('System', column='other_config') if results.get('lldp_enable', '') == 'true': lines.append('lldp enable') val = results.get('lldp_hold') if val and val != DEFAULTS['LLDP_HOLDTIME']: lines.append("lldp holdtime %s" % val) val = results.get('lldp_tx_interval') if val and val != DEFAULTS['LLDP_TIMER']: lines.append("lldp timer %s" % val) val = results.get('lldp_mgmt_addr') if val: lines.append("lldp management-address %s" % val) lldp_tlv_config = ( ( 'lldp_tlv_mgmt_addr_enable', 'LLDP_TLV_MGMT_ADDR', 'management-address' ), ( 'lldp_tlv_port_proto_vlan_id_enable', 'LLDP_TLV_PROTO_VLAN_ID', 'port-protocol-vlan-id' ), ( 'lldp_tlv_port_proto_id_enable', 'LLDP_TLV_PORT_PROTO_ID', 'port-protocol-id' ), ( 'lldp_tlv_port_vlan_name_enable', 'LLDP_TLV_PORT_VLAN_NAME', 'port-vlan-name' ), ( 'lldp_tlv_port_desc_enable', 'LLDP_TLV_PORT_DESC', 'port-description' ), ( 'lldp_tlv_port_vlan_id_enable', 'LLDP_TLV_PORT_VLAN_ID', 'port-vlan-id' ), ( 'lldp_tlv_sys_cap_enable', 'LLDP_TLV_SYS_CAP', 'system-capabilities' ), ( 'lldp_tlv_sys_desc_enable', 'LLDP_TLV_SYS_DESC', 'system-description' ), ( 'lldp_tlv_sys_name_enable', 'LLDP_TLV_SYS_NAME', 'system-name' ), ) for key, default, word in lldp_tlv_config: val = results.get(key) if val and val != DEFAULTS[default]: lines.append("no lldp select-tlv %s" % word) return lines