Project

General

Profile

6 Important Calamari API Methods for Developers » History » Version 1

Jessica Mack, 06/21/2015 12:45 AM

1 1 Jessica Mack
h1. 6 Important Calamari API Methods for Developers
2
3
The Calamari API packs a lot of raw power under its hood. But if you're just getting started, the "50 (or so) available API endpoints":http://calamari.readthedocs.org/en/latest/calamari_rest/resources/resources.html might be too much information to process at once.
4
That's where this cheat sheet comes in. It identifies 6 common developer use cases and gives you a quick snapshot of the API endpoint corresponding to each, so you can get up and running quickly. Use it to kickstart your Calamari API client development, or just to get a taster of what Calamari can do for you. Happy coding!
5
6
*1. Retrieve or update the CRUSH map: /api/v2/cluster/<fsid>/crush_map*
7
CRUSH maps contain rulesets that tell Ceph how data should be replicated across the cluster's storage pools. As such, they're pretty important - which gives this API endpoint instant VIP status on this short list. Use a GET request to retrieve the current CRUSH map for your cluster, or replace the current CRUSH map with a new one by including it in the POST request body. For example, the request below sends a new CRUSH map to the cluster:
8
<pre>
9
POST /api/v2/cluster/xyz/crush_map
10
# begin crush map
11
tunable choose_local_tries 0
12
tunable choose_local_fallback_tries 0
13
tunable choose_total_tries 50
14
tunable chooseleaf_descend_once 1
15
# devices
16
device 0 osd.0
17
device 1 device1
18
device 2 osd.2
19
# types
20
type 0 osd
21
type 1 host
22
type 2 chassis
23
type 3 rack
24
type 4 row
25
type 5 pdu
26
type 6 pod
27
type 7 room
28
type 8 datacenter
29
type 9 region
30
type 10 root
31
# buckets
32
host node2 {
33
        id -2           # do not change unnecessarily
34
        # weight 0.010
35
        alg straw
36
        hash 0  # rjenkins1
37
        item osd.0 weight 0.010
38
}
39
host node3 {
40
        id -3           # do not change unnecessarily
41
        # weight 0.010
42
        alg straw
43
        hash 0  # rjenkins1
44
        item osd.2 weight 0.010
45
}
46
root default {
47
        id -1           # do not change unnecessarily
48
        # weight 0.020
49
        alg straw
50
        hash 0  # rjenkins1
51
        item node2 weight 0.010
52
        item node3 weight 0.010
53
}
54
# rules
55
rule replicated_ruleset {
56
        ruleset 0
57
        type replicated
58
        min_size 1
59
        max_size 10
60
        step take default
61
        step chooseleaf firstn 0 type host
62
        step emit
63
}
64
# end crush map
65
</pre>
66
67
*2. Get an overview of the cluster: /api/v2/cluster/<fsid>/server*
68
When you have a few hundred OSDs to deal with, you'll appreciate this API endpoint, which gives you a birds-eye view of the servers in a specified cluster, together with their names, IP addresses and list of running services. Simply send a GET request as below, and be prepared to be awed with the amount of data available:
69
<pre>
70
GET /api/v2/cluster/xyz/server
71
</pre>
72
Unfortunately you can't yet filter that output but if what you're really after is a list of hosts running specific services, you can always use _/api/v2/cluster/<fsid>/osd_ to get a list of OSDs or _/api/v2/cluster/<fsid>/mon_ to get a list of monitor nodes.
73
 
74
*3. Create new storage pools: /api/v2/cluster/<fsid>/pool*
75
The Calamari API makes it possible to create, delete and manage your pools remotely. Send a GET request to this API endpoint to retrieve a list of available pools, or send a POST request with the pool name and number of placement groups to create a new pool. For example, to create a new pool named 'test' with 64 placement groups, perform a POST request as below:
76
<pre>
77
POST /api/v2/cluster/xyz/pool
78
{"name": "test", "pg_num": 64, "crush_ruleset": 2}   
79
</pre> 
80
 
81
*4. Repair or scrub OSDs: /api/v2/cluster/<fsid>/osd/<id>/command/<command>*
82
Want to scrub or repair your OSDs? Send a POST request to this API endpoint, remembering to specify the OSD ID and one of the commands 'scrub', 'deep_scrub' or 'repair' to perform the corresponding operation on the OSD. For example, to repair OSD 1, perform a POST request as below:
83
<pre>
84
POST /api/v2/cluster/xyz/osd/1/command/repair
85
</pre>
86
 
87
*5. Get cluster health and status: /api/v1/cluster/<fsid>/health*
88
Need to quickly check on your cluster's health? Use this API endpoint to get a quick snapshot of whether things are terrible or terrific. The output is equivalent to that of the 'ceph health' command.
89
Here's an example:
90
<pre>
91
GET /api/v1/cluster/xyz/health
92
</pre>
93
The response includes an 'overall_status' field which reports the current state of the cluster and additional 'summary' fields containing more granular information.
94
 
95
*6. Watch cluster activity in real time: /api/v2/cluster/<fsid>/log
96
*The larger the cluster, the more there is going on at any given time. Use the API endpoint above to get an ongoing log of cluster events. To see it in action, send a GET request as below:
97
<pre>
98
GET /api/v2/cluster/xyz/log
99
</pre>