mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
Move xml strings to xml files
Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
This commit is contained in:
@@ -55,9 +55,9 @@ curl -i -X POST -H "Content-Type: application/json" localhost:9021/mfxkit -d '{"
|
||||
## Virsh
|
||||
|
||||
```sh
|
||||
virsh undefine QEmu-alpine-standard-x86_64
|
||||
virsh shutdown QEmu-alpine-standard-x86_64
|
||||
virsh destroy QEmu-alpine-standard-x86_64
|
||||
rm -rf ~/go/src/github.com/ultravioletrs/cocosvm/cmd/manager/img/boot.img
|
||||
virsh undefine QEmu-alpine-standard-x86_64; \
|
||||
virsh shutdown QEmu-alpine-standard-x86_64; \
|
||||
virsh destroy QEmu-alpine-standard-x86_64; \
|
||||
rm -rf ~/go/src/github.com/ultravioletrs/cocosvm/cmd/manager/img/boot.img; \
|
||||
virsh pool-destroy --pool virtimages
|
||||
```
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<domain type='qemu'>
|
||||
<name>QEmu-alpine-standard-x86_64</name>
|
||||
<uuid>c7a5fdbd-cdaf-9455-926a-d65c16db1809</uuid>
|
||||
<memory>219200</memory>
|
||||
<currentMemory>219200</currentMemory>
|
||||
<vcpu>2</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc'>hvm</type>
|
||||
<boot dev='cdrom'/>
|
||||
</os>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='file' device='cdrom'>
|
||||
<source file='/home/darko/go/src/github.com/ultravioletrs/cocosvm/cmd/manager/iso/alpine-standard-3.17.2-x86_64.iso'/>
|
||||
<target dev='hdc'/>
|
||||
<readonly/>
|
||||
</disk>
|
||||
<disk type='file' device='disk'>
|
||||
<source file='/home/darko/go/src/github.com/ultravioletrs/cocosvm/cmd/manager/img/boot.img'/>
|
||||
<target dev='hda'/>
|
||||
</disk>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
</interface>
|
||||
<graphics type='vnc' port='-1'/>
|
||||
</devices>
|
||||
</domain>
|
||||
@@ -0,0 +1,6 @@
|
||||
<pool type="dir">
|
||||
<name>virtimages</name>
|
||||
<target>
|
||||
<path>/home/darko/go/src/github.com/ultravioletrs/cocosvm/cmd/manager/img</path>
|
||||
</target>
|
||||
</pool>
|
||||
@@ -0,0 +1,14 @@
|
||||
<volume>
|
||||
<name>boot.img</name>
|
||||
<allocation>0</allocation>
|
||||
<capacity unit="T">1</capacity>
|
||||
<target>
|
||||
<path>/home/darko/go/src/github.com/ultravioletrs/cocosvm/cmd/manager/img/boot.img</path>
|
||||
<permissions>
|
||||
<owner>107</owner>
|
||||
<group>107</group>
|
||||
<mode>0744</mode>
|
||||
<label>virt_image_t</label>
|
||||
</permissions>
|
||||
</target>
|
||||
</volume>
|
||||
@@ -2,61 +2,6 @@ package manager
|
||||
|
||||
import "github.com/digitalocean/go-libvirt"
|
||||
|
||||
const poolXML string = `
|
||||
<pool type="dir">
|
||||
<name>virtimages</name>
|
||||
<target>
|
||||
<path>/home/darko/go/src/github.com/ultravioletrs/cocosvm/cmd/manager/img</path>
|
||||
</target>
|
||||
</pool>
|
||||
`
|
||||
const volXML string = `
|
||||
<volume>
|
||||
<name>boot.img</name>
|
||||
<allocation>0</allocation>
|
||||
<capacity unit="T">1</capacity>
|
||||
<target>
|
||||
<path>/home/darko/go/src/github.com/ultravioletrs/cocosvm/cmd/manager/img/boot.img</path>
|
||||
<permissions>
|
||||
<owner>107</owner>
|
||||
<group>107</group>
|
||||
<mode>0744</mode>
|
||||
<label>virt_image_t</label>
|
||||
</permissions>
|
||||
</target>
|
||||
</volume>
|
||||
`
|
||||
|
||||
const domXML string = `
|
||||
<domain type='qemu'>
|
||||
<name>QEmu-alpine-standard-x86_64</name>
|
||||
<uuid>c7a5fdbd-cdaf-9455-926a-d65c16db1809</uuid>
|
||||
<memory>219200</memory>
|
||||
<currentMemory>219200</currentMemory>
|
||||
<vcpu>2</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc'>hvm</type>
|
||||
<boot dev='cdrom'/>
|
||||
</os>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='file' device='cdrom'>
|
||||
<source file='/home/darko/go/src/github.com/ultravioletrs/cocosvm/cmd/manager/iso/alpine-standard-3.17.2-x86_64.iso'/>
|
||||
<target dev='hdc'/>
|
||||
<readonly/>
|
||||
</disk>
|
||||
<disk type='file' device='disk'>
|
||||
<source file='/home/darko/go/src/github.com/ultravioletrs/cocosvm/cmd/manager/img/boot.img'/>
|
||||
<target dev='hda'/>
|
||||
</disk>
|
||||
<interface type='network'>
|
||||
<source network='default'/>
|
||||
</interface>
|
||||
<graphics type='vnc' port='-1'/>
|
||||
</devices>
|
||||
</domain>
|
||||
`
|
||||
|
||||
func createDomain(libvirtConn *libvirt.Libvirt, poolXML string, volXML string, domXML string) (libvirt.Domain, error) {
|
||||
pool, err := libvirtConn.StoragePoolCreateXML(poolXML, 0)
|
||||
if err != nil {
|
||||
|
||||
+29
-1
@@ -5,10 +5,17 @@ package manager
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/digitalocean/go-libvirt"
|
||||
)
|
||||
|
||||
const (
|
||||
poolXML = "xml/pool.xml"
|
||||
volXML = "xml/vol.xml"
|
||||
domXML = "xml/dom.xml"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrMalformedEntity indicates malformed entity specification (e.g.
|
||||
// invalid username or password).
|
||||
@@ -17,6 +24,9 @@ var (
|
||||
// ErrUnauthorizedAccess indicates missing or invalid credentials provided
|
||||
// when accessing a protected resource.
|
||||
ErrUnauthorizedAccess = errors.New("missing or invalid credentials provided")
|
||||
|
||||
// ErrNotFound indicates a non-existent entity request.
|
||||
ErrNotFound = errors.New("entity not found")
|
||||
)
|
||||
|
||||
// Service specifies an API that must be fullfiled by the domain service
|
||||
@@ -42,7 +52,25 @@ func New(secret string, libvirtConn *libvirt.Libvirt) Service {
|
||||
}
|
||||
|
||||
func (ks *managerService) Ping(secret string) (string, error) {
|
||||
dom, err := createDomain(ks.libvirt, poolXML, volXML, domXML)
|
||||
bytes, err := os.ReadFile(poolXML)
|
||||
if err != nil {
|
||||
return "", ErrNotFound
|
||||
}
|
||||
poolStr := string(bytes)
|
||||
|
||||
bytes, err = os.ReadFile(volXML)
|
||||
if err != nil {
|
||||
return "", ErrNotFound
|
||||
}
|
||||
volStr := string(bytes)
|
||||
|
||||
bytes, err = os.ReadFile(domXML)
|
||||
if err != nil {
|
||||
return "", ErrNotFound
|
||||
}
|
||||
domStr := string(bytes)
|
||||
|
||||
dom, err := createDomain(ks.libvirt, poolStr, volStr, domStr)
|
||||
if err != nil {
|
||||
return "", ErrMalformedEntity
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user