Project

General

Profile

Ucloud » History » Version 10

Nico Schottelius, 07/21/2019 09:34 AM

1 1 Ahmed Bilal
h1. ucloud (To Be Continued)
2
3 7 Nico Schottelius
{{toc}}
4
5 5 Ahmed Bilal
6 6 Ahmed Bilal
h2. Installation
7
8
**Note:** This installation guide assumes that the ~ is /root
9
10
* **Install QEMU**
11
<pre><code class="shell">
12
sudo apt install qemu qemu-kvm
13
</code></pre>
14
15
16
* **Create Directory Structure**
17
<pre><code class="shell">
18
mkdir /var/vm/
19
mkdir /var/www/
20
</code></pre>
21
22
23
* **Create User Directories**
24
<pre><code class="shell">
25
mkdir /var/www/ahmedbilal-admin
26
mkdir /var/www/nico
27
mkdir /var/www/kjg
28
cd ~
29
</code></pre>
30
31
* **Download and place Alpine Linux image in _/var/www/ahmedbilal-admin_**
32
<pre><code class="shell">
33
wget https://www.dropbox.com/s/5eyryhxun6847hx/alpine.zip?dl=1 -O alpine.zip
34
unzip alpine.zip
35
mv alpine.qcow2 /var/www/ahmedbilal-admin
36
</code></pre>
37
38
* **Clone repos**
39
<pre><code class="shell">
40
git clone --recurse-submodules git@code.ungleich.ch:ungleich-public/ucloud-api.git
41
git clone --recurse-submodules git@code.ungleich.ch:ungleich-public/ucloud-scheduler.git
42
git clone --recurse-submodules git@code.ungleich.ch:ungleich-public/ucloud-vm.git
43
git clone --recurse-submodules git@code.ungleich.ch:ungleich-public/ucloud-file-scan.git
44
git clone --recurse-submodules git@code.ungleich.ch:ungleich-public/ucloud-image-scanner.git
45
</code></pre>
46
47
48
h2. *+Put related .env inside all the above directories+*
49
50
* **Run "ucloud-api" as daemon**
51
<pre><code class="shell">
52
cd ucloud-api
53
pipenv install
54
pipenv run gunicorn --bind [::]:80 main:app --daemon
55
wget https://www.dropbox.com/s/lyu3atymxyw3846/setup.py?dl=1 -O setup.py
56
pipenv run python setup.py
57
cd ~
58
</code></pre>
59
60
* **Run "ucloud-scheduler" as daemon**
61
<pre><code class="shell">
62
cd ucloud-scheduler
63
pipenv install
64
pipenv run python main.py &>/dev/null &
65
cd ~
66
</code></pre>
67
68
* **Run "ucloud-vm" as daemon**
69
<pre><code class="shell">
70
cd ucloud-vm
71
pipenv install
72
pipenv run python main.py /v1/host/1 --vm True &>/dev/null &
73
cd ~
74
</code></pre>
75
76
* **Install ucloud-file-scan**
77
<pre><code class="shell">
78
cd ucloud-file-scan
79
pipenv install
80
cd ~
81
</code></pre>
82
83
* **Install ucloud-image-scanner**
84
<pre><code class="shell">
85
cd ucloud-image-scanner
86
pipenv install
87
cd ~
88
</code></pre>
89
90
* **Run @crontab -e@ and put these entries there and save by pressing @Ctrl+x@ then @y@ then @enter@**
91
<pre>
92
*/1 * * * * (cd /root/ucloud-file-scan && /usr/local/bin/pipenv run python main.py)
93
*/1 * * * * (cd /root/ucloud-image-scanner/ && /usr/local/bin/pipenv run python main.py)
94
</pre>
95
96 1 Ahmed Bilal
h2. ucloud-api
97
98
Outside world (indirect) communication with the internal systems.
99
100
Its responsibilities are
101
* Create VM *(Done)* POST _/vm/create_ 
102
<pre><code class="javascript">
103
{
104
	"name": "username",
105
	"realm": "user_realm",
106
	"seed": "user_seed",
107
	"specs": {
108
		"cpu": 16,
109
		"ram": 256,
110 2 Ahmed Bilal
		"hdd": 2000,
111
		"ssd": 256
112 1 Ahmed Bilal
	}
113
}
114
</code></pre>
115
116
* Delete VM *(Done)* POST _/vm/delete_
117
<pre><code class="javascript">
118
{
119
	"name": "username",
120
	"realm": "user_realm",
121
	"seed": "user_seed",
122
	"vmid": "id_of_virtual_machine"
123
}
124
</code></pre>
125
126
* Status VM *(Done)* GET _/vm/status_
127
<pre><code class="javascript">
128
{
129
	"id": "id_of_virtual_machine"
130
}
131
</code></pre>
132
133
* Create new network
134
* Attach network to VM
135
* Detach network from VM
136
* Delete network
137
138
h2. ucloud-scheduler
139
140
It schedules/reschedules VM that are created using ucloud-api. How does it schedules? It does by watching any changes under the _/v1/vm/_ prefix. Basically, it deals with two ETCD entries
141
142
1. Virtual Machines Entries that looks like
143
<pre><code class="javascript">
144
/v1/vm/1
145
{
146
  "owner": "ahmedbilal-admin",
147
  "specs": {
148
    "cpu": 20,
149
    "ram": 2,
150
    "hdd": 10,
151 3 Ahmed Bilal
    "ssd": 10
152 1 Ahmed Bilal
  },
153
  "hostname": "",
154
  "status": "REQUESTED_NEW" 
155
}
156
</code></pre>
157
2. Hosts Entries that look like
158
<pre><code class="javascript">
159
/v1/host/1
160
{
161
    "cpu": 32,
162
    "ram": 128,
163
    "hdd": 1024,
164 3 Ahmed Bilal
    "ssd": 0
165 1 Ahmed Bilal
    "status": "UP"
166
}
167
</code></pre>
168
169
It loop through list of host entries found under _/v1/host/_ and check whether we can run the incoming VM on that host. if we can, then it (ucloud-scheduler) sets the hostname key of incoming VM to that host. Suppose, our scheduler decides that we can run the earlier shown VM _/v1/vm/1_ on _/v1/host/1_. Then, our updated entry would look like
170
171
<pre><code class="javascript">
172
/v1/vm/1
173
{
174
  "owner": "ahmedbilal-admin",
175
  "specs": {
176
    "cpu": 20,
177
    "ram": 2,
178
    "hdd": 10,
179 3 Ahmed Bilal
    "ssd": 10
180 1 Ahmed Bilal
  },
181
  "hostname": "/v1/host/1",
182
  "status": "REQUESTED_NEW" 
183
}
184
</code></pre>
185
186
*Note* the hostname key/value pair.
187
188
h2. ucloud-vm
189
It is responsible for creating (running) / deleting (stopping) / monitoring virtual machines
190
191
It watches the _/v1/vm/_ prefix for any changes like (Virtual Machines with status like *SCHEDULED_DEPLOY* or *REQUEST_DELETE*.
192
193
On, *SCHEDULED_DEPLOY* it creates the VM and run it. On, *REQUEST_DELETE* it stops the VM. 
194
195
It is also responsible for monitoring VM statues i.e whether they are RUNNING or KILLED (in action). If a VM is killed we put that in log file, notify system administrator and restart it.
196 8 Nico Schottelius
197 9 Nico Schottelius
h2. Preface
198
199 10 Nico Schottelius
The main development work is described in ticked #6869.
200
201 9 Nico Schottelius
Notations:
202
203
* $DOMAIN: refers to a dns domain that you will use for running ucloud
204
205 8 Nico Schottelius
h2. Administrator Manual
206
207
(being written: how to setup the ucloud infrastructure)
208
209
h3. Requirements
210
211
ucloud is an opinionated cloud management framework. It is made to solve the problem of "virtual machine hosting" including migrations, scale out, etc. While there are many different ways on how to run, store and distribute VMs, there are not that many ways that work reliable and scale out. For this reason ucloud is based on existing software that has proven to be working for virtual machine hosting.
212 1 Ahmed Bilal
213
The following components are required for running ucloud:
214
215 9 Nico Schottelius
1. Python 3.7, pip, pipenv (the programming language of choice)
216
2. etcd (for data storage)
217
3. ceph (for storage of VMs)
218
4. Guacamole (for console access)
219 8 Nico Schottelius
220
Setting up these components is out of scope of this manual.
221
222
h2. User Manual
223
224
(being written: how to use ucloud as a user)
225
226
h3. Creating a VM
227 1 Ahmed Bilal
228
(to be filled in by ahmed)
229
230 9 Nico Schottelius
h3. Viewing the console of the VM
231
232
* Go to console.$DOMAIN
233
* Login with your username password
234
* Select the VM that you want to view
235 8 Nico Schottelius
236
h3. Deleting a VM
237
238
239
h2. API reference
240
241
(to be moved here by Ahmed)