Statistics
| Branch: | Tag: | Revision:

root / docs / examplesdir / server.rst @ 1c366ac9

History | View | Annotate | Download (11.6 kB)

1
Creating Servers (Virtual Machines)
2
===================================
3

    
4
A `server` (also known as `virtual machine`), is created based on a registered
5
`image` and a hardware setup (also known as `flavor`).
6

    
7
Create a virtual server
8
-----------------------
9

    
10
List available flavors
11

    
12
.. code-block:: console
13

    
14
    $ kamaki flavor list -l
15
    1 C1R128D1drbd
16
        SNF:disk_template: drbd
17
        disk:              1
18
        id:                1
19
        links:
20
                href: https://example.com/cyclades/compute/v2.0/flavors/1
21
                rel:  bookmark
22
                . . . . . . .
23
                href: https://example.com/cyclades/compute/v2.0/flavors/1
24
                rel:  self
25
        name:              C1R128D1drbd
26
        ram:               128
27
        vcpus:             1
28
    2 C1R128D1plain
29
        SNF:disk_template: plain
30
        disk:              1
31
        id:                2
32
        links:
33
                href: https://example.com/cyclades/compute/v2.0/flavors/2
34
                rel:  bookmark
35
                . . . . . . .
36
                href: https://example.com/cyclades/compute/v2.0/flavors/2
37
                rel:  self
38
        name:             C1R128D1plain
39
        ram:              128
40
        vcpus:            1
41

    
42
List available images
43

    
44
.. code-block:: console
45

    
46
    $ kamaki image list
47
    f1r57-1m4g3-1d Debian Base Alpha
48
    53c0nd-1m4g3-1d Beta Debian Base
49

    
50
Let's pick the `C1R128D1drbd` (id: 1) flavor and the `Debian Base Alpha` (id:
51
f1r57-1m4g3-1d) image to create a new virtual server called 'My First Server'
52

    
53
.. code-block:: console
54

    
55
    $ kamaki server create --name='My First Server' --flavor-id=1 --image-id=f1r57-1m4g3-1d
56
    accessIPv4:
57
    accessIPv6:
58
    addresses:
59
    adminPass:       Y0uW0nt5eeMeAg4in
60
    attachments:
61
    config_drive:
62
    created:         2013-06-19T12:34:47.362078+00:00
63
    diagnostics:
64
    flavor:
65
            id:    1
66
    hostId:
67
    id:              141
68
    image:
69
            id:    f1r57-1m4g3-1d
70
    key_name:        None
71
    metadata:
72
                   os:    debian
73
                   users: root
74
    name:            My First Server
75
    progress:        0
76
    security_groups:
77
                      name: default
78
    status:          BUILD
79
    suspended:       False
80
    tenant_id:       s0m3-u53r-1d
81
    updated:         2013-06-19T12:34:48.512867+00:00
82
    user_id:         s0m3-u53r-1d
83

    
84
.. note:: The adminPass field is not stored anywhere, therefore users would
85
    rather write it down and change it the first time they use the virtual
86
    server
87

    
88
Wait for the virtual server with id 141 to build (optional)
89

    
90
.. code-block:: console
91

    
92
    $ kamaki server wait 141
93
    <bar showing build progress, until 100%>
94
    Server 141 is now in ACTIVE mode
95

    
96
Destroy the virtual server (wait is still optional)
97

    
98
.. code-block:: console
99

    
100
    $ kamaki server delete 141 --wait
101
    <bar showing destruction progress, until 100%>
102
    Server 141 is now in DELETED mode
103

    
104
Inject ssh keys to a debian server
105
----------------------------------
106

    
107
Assume that the servers build from the image `Debian Base Alpha` accept ssh
108
connections. We need to build servers that can log us as root without a
109
password. This can be achieved if the `/root/.ssh/authorized_keys` file exists
110
and contains the public key of the current user.
111

    
112
Assume that the public key file of the current user is located at
113
`/home/someuser/.ssh/id_rsa.pub` . We need to inject this file as
114
`/root/.ssh/authorized_keys` while creating the virtual server.
115

    
116
Luckily, Synnefo fully supports the OpenStack suggestion for file injections on
117
virtual servers and kamaki features the **-p** argument (p stands for
118
`PERSONALITY` and is the term used in the respective
119
`respective OpenStack <http://docs.openstack.org/api/openstack-compute/2/content/CreateServers.html>`_ description).
120

    
121
The syntax of the -p argument is something called "the personality string"::
122

    
123
    -p <local file path>[,<remote path>[,<remote owner>[,<remote group>[,<mode>]]]]
124

    
125
    e.g.,
126

    
127
    -p /home/someuser/.ssh/id_rsa.pub,/root/.ssh/authorized_keys,root,root,0777
128

    
129
.. note:: In case of omitting an optional part of the personality string, the
130
    default behavior depends on the remote server, e.g., for a debian image we
131
    expect the file to have root ownership, if the ownership is not specified.
132

    
133
Create a virtual server while injecting current user public key to root account
134

    
135
.. code-block:: console
136

    
137
    $ kamaki server create --name='NoPassword Server' --flavor-id=1 --image-id=f1r57-1m4g3-1d -p /home/someuser/.ssh/id_rsa.pub,/root/.ssh/authorized_keys
138
    accessIPv4:
139
    accessIPv6:
140
    addresses:
141
    adminPass:       Th1s1s4U5elessTh1ngN0w
142
    attachments:
143
    config_drive:
144
    created:         2013-06-19T12:34:47.362078+00:00
145
    diagnostics:
146
    flavor-id:    1
147
    hostId:
148
    id:              142
149
    image-id:     f1r57-1m4g3-1d
150
    key_name:        None
151
    metadata:
152
                    os:    debian
153
                    users: root
154
    name:           No Password Server
155
    progress:        0
156
    status:          BUILD
157
    suspended:       False
158
    tenant_id:       s0m3-u53r-1d
159
    updated:         2013-06-19T12:34:48.512867+00:00
160
    user_id:         s0m3-u53r-1d
161

    
162
When the virtual server is ready, get the virtual servers external IP from the
163
web UI. Let's assume the IP is 123.456.78.90 .
164

    
165
.. code-block:: console
166

    
167
    $ ssh root@123.456.78.90
168
    Linux remote-virtual server-4241 2.6.32-5-amd64 #1 SMP XXXX x86_64
169

    
170
    The programs included with the Debian GNU/Linux system are free software;
171
    the exact distribution terms for each program are described in the
172
    individual files in /usr/share/doc/*/copyright.
173

    
174
    Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
175
    permitted by applicable law.
176
    root@remote-virtual server-4241:~# ls -l .ssh/
177
    total 4
178
    -rw-r--r-- 1 root root 399 Jun 19 12:34 authorized_keys
179
    root@remote-virtual server-4241:~#
180

    
181
You can now log to your remote virtual server as root, without a password. Well done!
182

    
183
.. note:: There is no reason to limit injections to ssh keys. Users with an
184
    adequate understanding of the remote OS are encouraged to prepare and
185
    inject all kinds of useful files, e.g., **lists of package sources**,
186
    **default user profiles**, **device mount configurations**, etc.
187

    
188
Clusters of virtual servers
189
---------------------------
190

    
191
A virtual cluster is a number of virtual servers which have names starting with
192
the same prefix e.g., *cluster1*, *cluster2*, etc. This prefix acts as the
193
cluster name. Still, users must be careful not to confuse cluster servers with
194
other servers that coincidentally have the same prefix (e.g.,
195
*cluster_of_stars*).
196

    
197
First, let's create a cluster of 4 servers. Each server will run the image with
198
id *f1r57-1m4g3-1d* on the hardware specified by the flavor with id *1*. The
199
prefix of the cluster will be "my cluster "
200

    
201
.. code-block:: console
202

    
203
    $ kamaki
204
    $ kamaki server
205
    $ kamaki server create --name="my cluster " --flavor-id=1 --image=if1r57-1m4g3-1d --cluster-size=4 --wait
206
    ... <omitted for clarity>
207
    adminPass:       S0mePassw0rd0n3
208
    flavor-id: 1
209
    id: 322
210
    image-id: f1r57-1m4g3-1d
211
    name: my cluster 1
212
    [progress bar waiting server to build]
213
    Server 321: status is now ACTIVE
214

    
215
    ... <omitted for clarity>
216
    adminPass: S0mePassw0rdTwo
217
    flavor-id: 1
218
    id: 321
219
    image-id: f1r57-1m4g3-1d
220
    name: my cluster 2
221
    [progress bar waiting server to build]
222
    Server 322: status is now ACTIVE
223

    
224
    ... <omitted for clarity>
225
    adminPass: S0mePassw0rdThree
226
    created: 2013-06-19T12:34:55.362078+00:00
227
    flavor0id: 1
228
    id: 323
229
    image-id: f1r57-1m4g3-1d
230
    name: my cluster 3
231
    [progress bar waiting server to build]
232
    Server 323: status is now ACTIVE
233

    
234
    ... <omitted for clarity>
235
    adminPass:  S0mePassw0rdFour
236
    created: 2013-06-19T12:34:59.362078+00:00
237
    flavor-id: 1
238
    id: 324
239
    image-id: f1r57-1m4g3-1d
240
    name: my cluster 4
241
    [progress bar waiting server to build]
242
    Server 324: status is now ACTIVE
243

    
244
.. note:: The virtual servers can be created asynchronously. To activate
245
    asynchronous operations, set max_theads to some value greater than 1.
246
    Default is 1, though.
247

    
248
    .. code-block:: console
249

    
250
        # Create a cluster using multithreading (4 threads)
251

    
252
        $ kamaki server create --name="my cluster " --flavor-id=1 --image=if1r57-1m4g3-1d --cluster-size=4 --wait --threads=4
253

    
254
.. note:: the *- - wait* argument is optional, but if not used, the *create*
255
    call will terminate as long as the servers are spawned, even if they are
256
    not built yet.
257

    
258
.. warning:: The server details (password, etc.) are printed in
259
    **standard output** while the progress bar and notification messages are
260
    printed in **standard error**
261

    
262
Now, let's see our clusters:
263

    
264
.. code-block:: console
265

    
266
    $ kamaki server list --name-prefix 'my cluster '
267
    321 my cluster 2
268
    322 my cluster 1
269
    323 my cluster 3
270
    324 my cluster 4
271

    
272
For demonstration purposes, let's suppose that the maximum resource limit is
273
reached if we create 2 more servers. We will attempt to expand "my cluster" by
274
4 servers, expecting kamaki to raise a quota error.
275

    
276
.. code-block:: console
277

    
278
    $ kamaki server create --name="my cluster " --flavor-id=1 --image-id=f1r57-1m4g3-1d --cluster-size=4 --wait
279
    Failed to build 4 servers
280
    Found 2 matching servers:
281
    325 my cluster 1
282
    326 my cluster 2
283
    Check if any of these servers should be removed
284

    
285
    (413) REQUEST ENTITY TOO LARGE overLimit (Resource Limit Exceeded for your
286
    account.)
287
    |  Limit for resource 'Virtual Machine' exceeded for your account.
288
    Available: 0, Requested: 1
289

    
290
The cluster expansion has failed, but 2 of the attempted 4 servers are being
291
created right now. It's up to the users judgment to destroy or keep them.
292

    
293
First, we need to list all servers:
294

    
295
.. code-block:: console
296

    
297
    $ kamaki server list --name-prefix="my cluster "
298
    321 my cluster 2
299
    322 my cluster 1
300
    323 my cluster 3
301
    324 my cluster 4
302
    325 my cluster 1
303
    326 my cluster 2
304

    
305
.. warning:: Kamaki will always create clusters by attaching an increment at
306
    the right of the prefix. The increments always start from 1.
307

    
308
Now, our cluster seems messed up. Let's destroy it and rebuilt it.
309

    
310
.. code-block:: console
311

    
312
    $ kamaki server delete --cluster "my cluster " --wait
313
    [progress bar waiting server to be deleted]
314
    Server 321: status is now DELETED
315

    
316
    [progress bar waiting server to be deleted]
317
    Server 322: status is now DELETED
318

    
319
    [progress bar waiting server to be deleted]
320
    Server 323: status is now DELETED
321

    
322
    [progress bar waiting server to be deleted]
323
    Server 324: status is now DELETED
324

    
325
    [progress bar waiting server to be deleted]
326
    Server 325: status is now DELETED
327

    
328
    [progress bar waiting server to be deleted]
329
    Server 326: status is now DELETED
330

    
331
.. note:: *delete* performs a single deletion if fed with a server id, but it
332
    performs a mass deletion based on the name, if called with --cluster
333

    
334
While creating the first cluster, we had to write down all passwords 
335

    
336
The passwords for each server are printed on the console while creating them.
337
It would be far more convenient, though, if we could massively inject an ssh
338
key into all of them. Let's do that!
339

    
340
.. code-block:: console
341

    
342
    $ kamaki server create --name="my new cluster " --flavor-id=1 --image-id=f1r57-1m4g3-1d --cluster-size=4 --wait --personality=/home/someuser/.ssh/id_rsa.pub,/root/.ssh/authorized_keys,root,root,0777
343

    
344
    ... <output omitted for clarity>
345

    
346
Now, let's check if the cluster has been created.
347

    
348
.. code-block:: console
349

    
350
    $ kamaki server list --name-prefix="my new cluster "
351
    321 my new cluster 1
352
    322 my new cluster 2
353
    323 my new cluster 3
354
    324 my new cluster 4
355

    
356
We now have a cluster of 4 virtual servers and we can ssh in all of them
357
without a password.