Ejemplo n.º 1
0
 def show_online_devices(self):
     print_normal('Show the ' +
                  UseStyle('ONLINE', fore='green', mode='underline') +
                  ' devices.')
     devices_config_obj = DeviceConfigs.initialize(
         mars_config=self.mars_config)
     for device_config in devices_config_obj.get_data():
         print_normal(device_to_line_string(device_config))
Ejemplo n.º 2
0
 def init_online_data(self):
     print('Start to trace the ' +
           UseStyle('ONLINE', fore='green', mode='underline') + ' data')
     self.device_config_obj = DeviceConfigs.initialize(self.mars_config)
     self.hosts_obj = Hosts.initialize(self.mars_config)
     self.group_obj = Groups.initialize(self.mars_config)
     self.flow_obj = Flows.initialize(self.mars_config)
     self.link_obj = Links.initialize(self.mars_config)
Ejemplo n.º 3
0
    def _load_device_config(self, after_time):
        path_dir = self.mars_config.get_base_path()
        device_path = path_dir + after_time + '/devices_config'

        f = open(device_path, 'r')
        lines = f.readlines()
        device_config_str = ''.join(lines)
        f.close()
        self.device_config_object = DeviceConfigs.initialize_with(
            self.mars_config, json.loads(device_config_str))
Ejemplo n.º 4
0
    def show_snap_devices(self, snap_time):
        snap_time_str = format_time_string_2_number(snap_time)
        print_normal('Show the ' +
                     UseStyle(snap_time, fore='green', mode='underline') +
                     ' devices.')
        devices_config_obj = DeviceConfigs.initialize_with(
            self.mars_config,
            get_devices_configs(self.mars_config, snap_time_str))

        for device_config in devices_config_obj.get_data():
            print_normal(device_to_line_string(device_config))
Ejemplo n.º 5
0
 def show_online_links(self):
     print_normal('Show the ' +
                  UseStyle('ONLINE', fore='green', mode='underline') +
                  ' links.')
     link_obj = Links.initialize(mars_config=self.mars_config)
     devices_config_obj = DeviceConfigs.initialize(
         mars_config=self.mars_config)
     for device_config in devices_config_obj.get_data():
         print_normal_start('Device Name : ' + device_config['name'],
                            color='yellow')
         for link in link_obj.get_data():
             if link['src']['device'] == device_config['id']:
                 print_normal_center(
                     link_to_line_string(link, devices_config_obj))
         print_normal_end('')
         print_normal('')
Ejemplo n.º 6
0
 def init_snap_data(self, snap_time_str):
     print('Start to trace the ' +
           UseStyle(snap_time_str, fore='green', mode='underline') +
           ' snap data\n')
     snap_time = format_time_string_2_number(snap_time_str)
     self.snap_time = snap_time
     self.device_config_obj = DeviceConfigs.initialize_with(
         self.mars_config, get_devices_configs(self.mars_config, snap_time))
     self.hosts_obj = Hosts.initialize_with(
         self.mars_config, get_host(self.mars_config, snap_time))
     self.group_obj = Groups.initialize_with(
         self.mars_config, get_group(self.mars_config, snap_time))
     self.flow_obj = Flows.initialize_with(
         self.mars_config, get_flow(self.mars_config, snap_time))
     self.link_obj = Links.initialize_with(
         self.mars_config, get_link(self.mars_config, snap_time))
Ejemplo n.º 7
0
    def show_online_hosts(self):
        print_normal('Show the ' +
                     UseStyle('ONLINE', fore='green', mode='underline') +
                     ' hosts.')
        host_obj = Hosts.initialize(mars_config=self.mars_config)
        devices_config_obj = DeviceConfigs.initialize(
            mars_config=self.mars_config)

        for device_config in devices_config_obj.get_data():
            print_normal_start('Device Name : ' + device_config['name'],
                               color='yellow')
            for host in host_obj.get_data():
                for location in host['locations']:
                    if location['elementId'] == device_config['id']:
                        print_normal_center(
                            host_to_line_string(host, devices_config_obj))

            print_normal_end('')
            print_normal('')
Ejemplo n.º 8
0
    def show_snap_links(self, snap_time_str):
        snap_time = format_time_string_2_number(snap_time_str)
        print_normal('Show the ' +
                     UseStyle(snap_time_str, fore='green', mode='underline') +
                     ' links.')

        link_obj = Links.initialize_with(self.mars_config,
                                         get_link(self.mars_config, snap_time))
        devices_config_obj = DeviceConfigs.initialize_with(
            self.mars_config, get_devices_configs(self.mars_config, snap_time))

        for device_config in devices_config_obj.get_data():
            print_normal_start('Device Name : ' + device_config['name'],
                               color='yellow')
            for link in link_obj.get_data():
                if link['src']['device'] == device_config['id']:
                    print_normal_center(
                        link_to_line_string(link, devices_config_obj))
            print_normal_end('')
            print_normal('')
Ejemplo n.º 9
0
    def show_snap_hosts(self, snap_time_str):
        print_normal('Show the ' +
                     UseStyle(snap_time_str, fore='green', mode='underline') +
                     ' hosts.')

        snap_time = format_time_string_2_number(snap_time_str)
        host_obj = Hosts.initialize_with(self.mars_config,
                                         get_host(self.mars_config, snap_time))
        devices_config_obj = DeviceConfigs.initialize_with(
            self.mars_config, get_devices_configs(self.mars_config, snap_time))

        for device_config in devices_config_obj.get_data():
            print_normal_start('Device Name : ' + device_config['name'],
                               color='yellow')
            for host in host_obj.get_data():
                for location in host['locations']:
                    if location['elementId'] == device_config['id']:
                        print_normal_center(
                            host_to_line_string(host, devices_config_obj))

            print_normal_end('')
            print_normal('')
Ejemplo n.º 10
0
    def snap_all_data(self):
        print_normal('Going to snap all the data from ' +
                     self.mars_config.get_url())
        device_object = Devices.initialize(self.mars_config)
        device_config_object = DeviceConfigs.initialize(self.mars_config)
        host_object = Hosts.initialize(self.mars_config)
        flow_object = Flows.initialize(self.mars_config)
        group_object = Groups.initialize(self.mars_config)
        link_object = Links.initialize(self.mars_config)

        t = int(time.time())

        data_path = self.mars_config.get_base_path() + '/' + str(t)

        os.mkdir(data_path)
        device_object.save(data_path)
        device_config_object.save(data_path)
        host_object.save(data_path)
        flow_object.save(data_path)
        group_object.save(data_path)
        link_object.save(data_path)

        print_normal('Success to snap the data')