Newer
Older
#+STARTUP: content
* later :entry:
** 2015-11-04 warn when hypervisor can't start KVM type VM.
* current :entry:
**
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
** 2015-12-30 a new design of qvm.
- make create ubuntu VM easy. using qvm and sheepdog/nginx.
- qvm init
prepare env for HV.
- install libvirt, qemu, ovs, kvm-check etc.
- create ovs network or bridge. define libvirt network.
- [optional] create secrets for ceph.
- qvm create vm1 --core 2 --ram 512M --network nat --bridge br1 --image /path/to/foo.img
or --image ubuntu-14.04
or --image sheepdog:foo
or --image URL-to-img-file
They all means make a copy of the image/snapshot and use that as first
disk.
- create image for the vm.
- define and start the vm.
- supported network
--network type=bridge,bridge=br1,vlan=200,ip=192.168.1.2
--network type=nat,bridge=br1,ip=192.168.1.2
- qvm rm vm1
destroy domain and remove disk and xml file.
- implementation
- make nat and file base image work.
- DONE how to use relative file path in stFile?
renderXML d = [stFile|src/domain-templates/domain.xml|]
works. just need src/ there. build always happens in stack.yaml dir.
- DONE use text file template to render xml.
network and disk should be placed in as a whole.
Which library to use?
libraries - Which Haskell library for interpolated strings - Stack Overflow
http://stackoverflow.com/questions/8956801/which-haskell-library-for-interpolated-strings
try shakespeare
http://hackage.haskell.org/package/shakespeare
render to Text using quasiquotes works.
#+BEGIN_SRC haskell
renderXML :: QvmDomain -> T.Text
renderXML d = [st|
haha my core is #{core d}
|]
#+END_SRC
TODO how to render using external file?
I think the template file is compiled into the final binary.
compare it with lucius.
hamlet :: QuasiQuoter
hamletFile :: FilePath -> Q Exp
putStrLn $ renderHtml $ [hamlet|<body>|] render
template = $(luciusFile "template.lucius")
putStrLn $ renderCss $ template render
http://stackoverflow.com/questions/12791491/use-shakespeare-text-and-external-file
didn't mention a solution.
- I need to understand template haskell.
what does quasiquoter produce?
how to use Q Exp?
understand what st is doing, then do the similar for textFile.
http://hackage.haskell.org/package/shakespeare-2.0.7/docs/src/Text-Shakespeare-Text.html#stext
#+BEGIN_SRC haskell
stext :: QuasiQuoter
stext =
QuasiQuoter { quoteExp = \s -> do
rs <- settings
render <- [|toLazyText|]
rendered <- shakespeareFromString rs { justVarInterpolation = True } s
return (render `AppE` rendered)
}
textFile :: FilePath -> Q Exp
textFile fp = do
rs <- settings
shakespeareFile rs fp
#+END_SRC
QuasiQuoter {quoteExp :: String -> Q Exp}
shakespeareFromString :: ShakespeareSettings -> String -> Q Exp
shakespeareFile :: ShakespeareSettings -> FilePath -> Q Exp
- copied some code and it is working now.
- shift2space for pretty xml.
TIO.putStrLn $ shift2space $ renderNetwork $ DefaultNAT
printXML makeDomain
- DONE OO design or functional? I like functional.
do
makeDomain
setCore 2
setRAM "512M"
setNetwork {type: "nat", bridge: "br1"}
setDisk {src: "/path/to/foo.img"}
printDomainXML
store all useful info in data structure, then generate xml in the final
step. do not do xml level combination/replacing.
- DONE qvm config directory.
/data/qvm/images/
/data/qvm/images/cirros-0.3.4-x86_64-disk.img
/data/qvm/instances/
/data/qvm/instances/vm1/disk
/data/qvm/instances/vm1/domain.xml
- DONE network type
predefined nat. params: network name
#+BEGIN_SRC xml
<interface type='network'>
<source network='default'/>
<model type='virtio'/>
</interface>
#+END_SRC
bridge mode with vlan tag. params: bridge, vlanid
#+BEGIN_SRC xml
<interface type='bridge'>
<forward mode="bridge"/>
<source bridge="br1"/>
<virtualport type='openvswitch'/>
<model type='virtio'/>
<vlan trunk='no'>
<tag id='100'/>
</vlan>
</interface>
#+END_SRC
putStrLn $ T.unpack $ renderNetwork DefaultNAT
putStrLn $ T.unpack $ renderNetwork $ OvsBridge "br1"
putStrLn $ T.unpack $ renderNetwork $ OvsBridgeWithVLAN "br1" 100
** 2015-11-04 make this work:
qvm --core 4 --ram 2g --disk 20g
use NAT network and default disk image.
- check whether we have enough RAM for this.
- generate xml
- define domain
- start domain
** 2015-11-04 how to ensure VM get same IP across reboots?
how to list IPs for all VMs?
* done :entry: