def set_switch_machines(): """Set switches and machines. .. note:: --switch_machines_file is the filename which stores all switches and machines information. each line in fake_switches_files presents one machine. the format of each line machine,<switch_ip>,<switch_port>,<vlan>,<mac> or switch,<switch_ip>,<switch_vendor>,<switch_version>, <switch_community>,<switch_state> """ if not flags.OPTIONS.switch_machines_file: print 'flag --switch_machines_file is missing' return database.init() switches, switch_machines = util.get_switch_machines_from_file( flags.OPTIONS.switch_machines_file) user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL) switch_mapping = {} for switch in switches: added_switch = switch_api.add_switch(False, user=user, **switch) switch_mapping[switch['ip']] = added_switch['id'] for switch_ip, machines in switch_machines.items(): if switch_ip not in switch_mapping: print 'switch ip %s not found' % switch_ip sys.exit(1) switch_id = switch_mapping[switch_ip] for machine in machines: switch_api.add_switch_machine(switch_id, False, user=user, **machine)
def set_switch_machines(): """Set switches and machines. .. note:: --switch_machines_file is the filename which stores all switches and machines information. each line in fake_switches_files presents one machine. the format of each line machine,<switch_ip>,<switch_port>,<vlan>,<mac> or switch,<switch_ip>,<switch_vendor>,<switch_version>, <switch_community>,<switch_state> """ if not flags.OPTIONS.switch_machines_file: print 'flag --switch_machines_file is missing' return database.init() switches, switch_machines = util.get_switch_machines_from_file( flags.OPTIONS.switch_machines_file) user = user_api.get_user_object( setting.COMPASS_ADMIN_EMAIL ) switch_mapping = {} for switch in switches: added_switch = switch_api.add_switch( user, False, **switch ) switch_mapping[switch['ip']] = added_switch['id'] for switch_ip, machines in switch_machines.items(): if switch_ip not in switch_mapping: print 'switch ip %s not found' % switch_ip sys.exit(1) switch_id = switch_mapping[switch_ip] for machine in machines: switch_api.add_switch_machine( user, switch_id, False, **machine )
def set_switch_machines(): """Set switches and machines. .. note:: --switch_machines_file is the filename which stores all switches and machines information. each line in fake_switches_files presents one machine. the format of each line machine,<switch_ip>,<switch_port>,<vlan>,<mac> or switch,<switch_ip>,<switch_vendor>,<switch_version>, <switch_community>,<switch_state> """ if not flags.OPTIONS.switch_machines_file: print 'flag --switch_machines_file is missing' return switches, switch_machines = util.get_switch_machines_from_file( flags.OPTIONS.switch_machines_file) with database.session(): manager = config_manager.ConfigManager() manager.update_switch_and_machines(switches, switch_machines)
def set_switch_machines(): """Set switches and machines. .. note:: --switch_machines_file is the filename which stores all switches and machines information. each line in fake_switches_files presents one machine. the format of each line machine,<switch_ip>,<switch_port>,<vlan>,<mac> or switch,<switch_ip>,<switch_vendor>,<switch_version>, <switch_community>,<switch_state> """ if not flags.OPTIONS.switch_machines_file: print 'flag --switch_machines_file is missing' return switches, switch_machines = util.get_switch_machines_from_file( flags.OPTIONS.switch_machines_file) with database.session(): manager = config_manager.ConfigManager() manager.update_switch_and_machines(switches, switch_machines)