func (store *LibvirtMachinerep) fillVm(vm *models.VirtualMachine, domain libvirt.VirDomain) error { name, err := domain.GetName() if err != nil { return err } uuid, err := domain.GetUUID() if err != nil { return err } info, err := domain.GetInfo() if err != nil { return err } xmlString, err := domain.GetXMLDesc(0) if err != nil { return err } domainConfig := domainXMLConfig{} if err := xml.Unmarshal([]byte(xmlString), &domainConfig); err != nil { return fmt.Errorf("failed to parse domain xml:", err) } log.WithField("name", name).WithField("domain", domainConfig).Debug("domain xml fetched") switch info.GetState() { default: vm.State = models.STATE_UNKNOWN case 1: vm.State = models.STATE_RUNNING case 5: vm.State = models.STATE_STOPPED } if len(domainConfig.Disks) > 0 { volume, err := store.conn.LookupStorageVolByPath(domainConfig.Disks[0].Source.File) if err != nil { return err } volumeInfo, err := volume.GetInfo() if err != nil { return err } vm.Disk = &models.VirtualMachineDisk{} vm.Disk.Driver = domainConfig.Disks[0].Driver.Name vm.Disk.Size = volumeInfo.GetCapacityInBytes() } else { vm.Disk = nil } vm.Name = name vm.Uuid = fmt.Sprintf("%x", uuid) vm.Memory = int(info.GetMaxMem()) vm.Cpus = int(info.GetNrVirtCpu()) return nil }
func fillOvzVm(vm *models.VirtualMachine, info *VZInfo) { vm.Name = info.Name vm.Uuid = fmt.Sprintf("%d", info.ID) vm.Cpus = info.Cpus vm.Memory = info.Physpages["limit"] switch info.Status { default: vm.State = models.STATE_UNKNOWN case "running": vm.State = models.STATE_RUNNING } }