Skip to content

Commit

Permalink
gofmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldin95 committed Feb 21, 2020
1 parent 4441bc7 commit 188f0ee
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion compute/libvirt/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (h *HyperVisor) Init() {
}
}

func (h *HyperVisor) GetCPU() (int, string){
func (h *HyperVisor) GetCPU() (int, string) {
if c, err := cpu.Info(); err == nil {
return len(c), c[0].VendorID
}
Expand Down
1 change: 0 additions & 1 deletion compute/libvirt/instanceXML.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (domain *DomainXML) VNCDisplay() (string, string) {
return "", ""
}


type VCPUXML struct {
XMLName xml.Name `xml:"vcpu" json:"-"`
Placement string `xml:"placement,attr" json:"placement"`
Expand Down
32 changes: 16 additions & 16 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ func (h *Server) GetInstance(w http.ResponseWriter, r *http.Request) {

func (h *Server) GetStore(store, name string) string {
if strings.HasPrefix(store, qemuimgdriver.Location) {
return store+"/"+name+"/"
return store + "/" + name + "/"
} else {
return qemuimgdriver.Location+store+"/"+name+"/"
return qemuimgdriver.Location + store + "/" + name + "/"
}
}

Expand All @@ -357,7 +357,7 @@ func (h *Server) NewImage(conf *InstanceConfSchema) (*qemuimgdriver.Image, error
return nil, err
}
}
file := path+"disk0.qcow2"
file := path + "disk0.qcow2"
size := libstar.ToBytes(conf.DiskSize, conf.DiskUnit)
img := qemuimgdriver.NewImage(file, size)
if err := img.Create(); err != nil {
Expand All @@ -371,19 +371,19 @@ func (h *Server) InstanceConf2XML(conf *InstanceConfSchema) (libvirtdriver.Domai
Type: "kvm",
Name: conf.Name,
Devices: libvirtdriver.DevicesXML{
Disks: make([]libvirtdriver.DiskXML, 2),
Disks: make([]libvirtdriver.DiskXML, 2),
Graphics: make([]libvirtdriver.GraphicsXML, 1),
},
OS: libvirtdriver.OSXML{
Type: libvirtdriver.OSTypeXML{
Arch: conf.Arch,
Arch: conf.Arch,
Value: "hvm",
},
Boot: make([]libvirtdriver.OSBootXML, 3),
},
}
if dom.OS.Type.Arch == "" {
dom.OS.Type.Arch = "x86_64"
dom.OS.Type.Arch = "x86_64"
}
// create new disk firstly.
img, err := h.NewImage(conf)
Expand All @@ -402,24 +402,24 @@ func (h *Server) InstanceConf2XML(conf *InstanceConfSchema) (libvirtdriver.Domai
}
dom.VCPUXml = libvirtdriver.VCPUXML{
Placement: "static",
Value: conf.Cpu,
Value: conf.Cpu,
}
dom.Memory = libvirtdriver.MemXML{
Value: conf.MemorySize,
Type: conf.MemoryUnit,
Type: conf.MemoryUnit,
}
dom.CurMem = libvirtdriver.CurMemXML{
Value: conf.MemorySize,
Type: conf.MemoryUnit,
Type: conf.MemoryUnit,
}
dom.Devices.Graphics[0] = libvirtdriver.GraphicsXML{
Type: "vnc",
Type: "vnc",
Listen: "0.0.0.0",
Port: "-1",
Port: "-1",
}
if strings.HasPrefix(conf.IsoFile, "/dev") {
dom.Devices.Disks[0] = libvirtdriver.DiskXML{
Type: "block",
Type: "block",
Device: "cdrom",
Driver: libvirtdriver.DiskDriverXML{
Name: "qemu",
Expand All @@ -435,7 +435,7 @@ func (h *Server) InstanceConf2XML(conf *InstanceConfSchema) (libvirtdriver.Domai
}
} else {
dom.Devices.Disks[0] = libvirtdriver.DiskXML{
Type: "file",
Type: "file",
Device: "cdrom",
Driver: libvirtdriver.DiskDriverXML{
Name: "qemu",
Expand All @@ -451,7 +451,7 @@ func (h *Server) InstanceConf2XML(conf *InstanceConfSchema) (libvirtdriver.Domai
}
}
dom.Devices.Disks[1] = libvirtdriver.DiskXML{
Type: "file",
Type: "file",
Device: "disk",
Driver: libvirtdriver.DiskDriverXML{
Name: "qemu",
Expand Down Expand Up @@ -499,7 +499,7 @@ func (h *Server) AddInstance(w http.ResponseWriter, r *http.Request) {
return
}
//libstar.Info("Server.AddInstance: xmlData: %s", xmlData)
file := h.GetStore(conf.DataStore, conf.Name)+"/define.xml"
file := h.GetStore(conf.DataStore, conf.Name) + "/define.xml"
libstar.XML.MarshalSave(xmlObj, file, true)

if dom, err := hyper.DomainDefineXML(xmlData); err == nil {
Expand Down Expand Up @@ -611,4 +611,4 @@ func (h *Server) GetISO(w http.ResponseWriter, r *http.Request) {

func (h *Server) GetBridge(w http.ResponseWriter, r *http.Request) {
h.ResponseJson(w, nil)
}
}
2 changes: 1 addition & 1 deletion learn/newqcow2.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func main() {
if err != nil {
log.Fatal(err)
}
}
}
3 changes: 1 addition & 2 deletions libstar/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ func (x xmlUtils) UnmarshalLoad(v interface{}, file string) error {
return nil
}


type Dir struct {
}

Expand Down Expand Up @@ -294,4 +293,4 @@ func (d Dir) ListDirs(dirPth string) (dirs []string, err error) {
}

return dirs, nil
}
}
12 changes: 6 additions & 6 deletions storage/qemu/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (i *Image) Create() error {
}

type IsoFile struct {
Name string `json:"name"`
Path string `json:"path"`
Name string `json:"name"`
Path string `json:"path"`
}

type IsoMgr struct {
Expand Down Expand Up @@ -64,8 +64,8 @@ var ISO = IsoMgr{
}

type DataStore struct {
Name string `json:"name"`
Path string `json:"path"`
Name string `json:"name"`
Path string `json:"path"`
}

type DataStoreMgr struct {
Expand All @@ -75,7 +75,7 @@ type DataStoreMgr struct {
func (store DataStoreMgr) List() []DataStore {
stores := make([]DataStore, 0, 32)

if dirs, err := libstar.DIR.ListDirs(Location+"datastore"); err == nil {
if dirs, err := libstar.DIR.ListDirs(Location + "datastore"); err == nil {
for _, dir := range dirs {
path := strings.Replace(dir, Location, "", 1)
name := strings.Replace(path, "/", ".", 4)
Expand All @@ -87,4 +87,4 @@ func (store DataStoreMgr) List() []DataStore {

var DATASTOR = DataStoreMgr{
Storage: make([]DataStore, 0, 32),
}
}

0 comments on commit 188f0ee

Please sign in to comment.