Documentation fixes.
[virt-hostinfo.git] / hostinfod / nodeinfo.c
1 /* virt-hostinfo
2  * Copyright (C) 2009 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 /* This file makes available all entries in the libvirt NodeInfo
20  * structure.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <ctype.h>
30
31 #include <libvirt/libvirt.h>
32
33 #include "hostinfod.h"
34
35 static void
36 model (struct guest_description *hval,
37        const char *cmd, apr_array_header_t *args)
38 {
39   if (get_args (args, "") == -1) {
40     warning ("%s: %s: wrong number or type of arguments",
41              hval->name, __func__);
42     send_error (hval, 400);
43     return;
44   }
45
46   send_reply (hval, 200, "%s", nodeinfo.model);
47 }
48 REGISTER_COMMAND (model)
49
50 static void
51 memory (struct guest_description *hval,
52         const char *cmd, apr_array_header_t *args)
53 {
54   if (get_args (args, "") == -1) {
55     warning ("%s: %s: wrong number or type of arguments",
56              hval->name, __func__);
57     send_error (hval, 400);
58     return;
59   }
60
61   send_reply (hval, 200, "%lu", nodeinfo.memory);
62 }
63 REGISTER_COMMAND (memory)
64
65 static void
66 availcpus (struct guest_description *hval,
67            const char *cmd, apr_array_header_t *args)
68 {
69   if (get_args (args, "") == -1) {
70     warning ("%s: %s: wrong number or type of arguments",
71              hval->name, __func__);
72     send_error (hval, 400);
73     return;
74   }
75
76   send_reply (hval, 200, "%u", nodeinfo.cpus);
77 }
78 REGISTER_COMMAND (availcpus)
79
80 static void
81 physcpus (struct guest_description *hval,
82           const char *cmd, apr_array_header_t *args)
83 {
84   if (get_args (args, "") == -1) {
85     warning ("%s: %s: wrong number or type of arguments",
86              hval->name, __func__);
87     send_error (hval, 400);
88     return;
89   }
90
91   send_reply (hval, 200, "%u", VIR_NODEINFO_MAXCPUS (nodeinfo));
92 }
93 REGISTER_COMMAND (physcpus)
94
95 static void
96 mhz (struct guest_description *hval,
97      const char *cmd, apr_array_header_t *args)
98 {
99   if (get_args (args, "") == -1) {
100     warning ("%s: %s: wrong number or type of arguments",
101              hval->name, __func__);
102     send_error (hval, 400);
103     return;
104   }
105
106   send_reply (hval, 200, "%u", nodeinfo.mhz);
107 }
108 REGISTER_COMMAND (mhz)
109
110 static void
111 nodes (struct guest_description *hval,
112        const char *cmd, apr_array_header_t *args)
113 {
114   if (get_args (args, "") == -1) {
115     warning ("%s: %s: wrong number or type of arguments",
116              hval->name, __func__);
117     send_error (hval, 400);
118     return;
119   }
120
121   send_reply (hval, 200, "%u", nodeinfo.nodes);
122 }
123 REGISTER_COMMAND (nodes)
124
125 static void
126 socketspernode (struct guest_description *hval,
127                 const char *cmd, apr_array_header_t *args)
128 {
129   if (get_args (args, "") == -1) {
130     warning ("%s: %s: wrong number or type of arguments",
131              hval->name, __func__);
132     send_error (hval, 400);
133     return;
134   }
135
136   send_reply (hval, 200, "%u", nodeinfo.sockets);
137 }
138 REGISTER_COMMAND (socketspernode)
139
140 static void
141 corespersocket (struct guest_description *hval,
142                 const char *cmd, apr_array_header_t *args)
143 {
144   if (get_args (args, "") == -1) {
145     warning ("%s: %s: wrong number or type of arguments",
146              hval->name, __func__);
147     send_error (hval, 400);
148     return;
149   }
150
151   send_reply (hval, 200, "%u", nodeinfo.cores);
152 }
153 REGISTER_COMMAND (corespersocket)
154
155 static void
156 threadspercore (struct guest_description *hval,
157                 const char *cmd, apr_array_header_t *args)
158 {
159   if (get_args (args, "") == -1) {
160     warning ("%s: %s: wrong number or type of arguments",
161              hval->name, __func__);
162     send_error (hval, 400);
163     return;
164   }
165
166   send_reply (hval, 200, "%u", nodeinfo.threads);
167 }
168 REGISTER_COMMAND (threadspercore)