Example #1
0
 def gather_info(self, retry=1):
     try:
         logger.info("host: {}  gather host info ".format(self.name))
         facts = gather_host_info(self.ip, self.port, self.username,
                                  self.password, retry)
     except Exception as e:
         self.status = Host.HOST_STATUS_UNKNOWN
         logger.error("host: {}  gather host info".format(self.name),
                      exc_info=True)
         raise e
     self.memory = facts["ansible_memtotal_mb"]
     cpu_cores = facts["ansible_processor_cores"]
     cpu_count = facts["ansible_processor_count"]
     self.cpu_core = int(cpu_cores) * int(cpu_count)
     self.os = facts["ansible_distribution"]
     self.os_version = facts["ansible_distribution_version"]
     self.save()
     devices = facts["ansible_devices"]
     volumes = []
     for name in devices:
         if not name.startswith(('dm', 'loop', 'sr')):
             volume = Volume(name='/dev/' + name)
             volume.size = devices[name]['size']
             volume.save()
             volumes.append(volume)
     self.volumes.set(volumes)
     self.status = Host.HOST_STATUS_RUNNING
     self.save()
Example #2
0
 def gather_info(self, retry=1):
     self.host.status = Host.HOST_STATUS_UPDATING
     try:
         logger.info("host: {}  gather host info ".format(self.name))
         facts = gather_host_info(ip=self.ip,
                                  port=self.port,
                                  username=self.username,
                                  retry=retry,
                                  password=self.password,
                                  private_key_path=self.private_key_path)
         self.memory = facts["ansible_memtotal_mb"]
         cpu_cores = facts["ansible_processor_cores"]
         cpu_count = facts["ansible_processor_count"]
         vcpus = facts.get("ansible_processor_vcpus", None)
         if vcpus:
             self.cpu_core = int(vcpus)
         else:
             self.cpu_core = int(cpu_cores) * int(cpu_count)
         self.os = facts["ansible_distribution"]
         self.os_version = facts["ansible_distribution_version"]
         devices = facts["ansible_devices"]
         volumes = []
         for name in devices:
             if not name.startswith(('dm', 'loop', 'sr')):
                 volume = Volume(name='/dev/' + name)
                 volume.size = devices[name]['size']
                 volume.save()
                 volumes.append(volume)
         self.volumes.set(volumes)
         msg = get_gpu_device(self.to_ssh_config())
         gpus = []
         if msg:
             host_gpus = str(msg).split('\n')
             for hg in host_gpus:
                 if hg.find("[") > -1:
                     g = GPU()
                     g.name = hg[hg.index("[") + 1:hg.index("]")]
                     g.save()
                     gpus.append(g)
                 else:
                     continue
         self.gpus.set(gpus)
         self.status = Host.HOST_STATUS_RUNNING
         self.save()
     except Exception as e:
         self.status = Host.HOST_STATUS_UNKNOWN
         self.cpu_core = 0
         self.memory = 0
         self.os = "未知"
         self.volumes.set([])
         self.os_version = ""
         self.save()
         logger.error("host: {}  gather host info".format(self.name),
                      exc_info=True)
Example #3
0
 def gather_info(self):
     facts = gather_host_info(self.ip, self.username, self.password)
     self.memory = facts["ansible_memtotal_mb"]
     cpu_cores = facts["ansible_processor_cores"]
     cpu_count = facts["ansible_processor_count"]
     self.cpu_core = int(cpu_cores) * int(cpu_count)
     self.os = facts["ansible_distribution"]
     self.os_version = facts["ansible_distribution_version"]
     self.save()
     devices = facts["ansible_devices"]
     volumes = []
     for name in devices:
         if not name.startswith(('dm', 'loop', 'sr')):
             volume = Volume(name='/dev/' + name)
             volume.size = devices[name]['size']
             volume.save()
             volumes.append(volume)
     self.volumes.set(volumes)
Example #4
0
    def gather_info(self, retry=1):
        try:

            logger.info("host: {}  gather host info ".format(self.name))
            facts = gather_host_info(ip=self.ip,
                                     port=self.port,
                                     username=self.username,
                                     retry=retry,
                                     password=self.password,
                                     private_key_path=self.private_key_path)
            self.memory = facts["ansible_memtotal_mb"]
            cpu_cores = facts["ansible_processor_cores"]
            cpu_count = facts["ansible_processor_count"]
            vcpus = facts.get("ansible_processor_vcpus", None)
            if vcpus:
                self.cpu_core = int(vcpus)
            else:
                self.cpu_core = int(cpu_cores) * int(cpu_count)
            self.os = facts["ansible_distribution"]
            self.os_version = facts["ansible_distribution_version"]
            self.save()
            devices = facts["ansible_devices"]
            volumes = []
            for name in devices:
                if not name.startswith(('dm', 'loop', 'sr')):
                    volume = Volume(name='/dev/' + name)
                    volume.size = devices[name]['size']
                    volume.save()
                    volumes.append(volume)
            self.volumes.set(volumes)
            self.status = Host.HOST_STATUS_RUNNING
            self.gather_gpu_info()
            self.save()
        except Exception as e:
            self.status = Host.HOST_STATUS_UNKNOWN
            self.cpu_core = 0
            self.memory = 0
            self.os = "未知"
            self.volumes.set([])
            self.os_version = ""
            self.save()
            logger.error("host: {}  gather host info".format(self.name),
                         exc_info=True)