debuggers.hg

view tools/libxen/src/xen_network.c @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children
line source
1 /*
2 * Copyright (c) 2006-2007, XenSource Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library 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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
20 #include <stddef.h>
21 #include <stdlib.h>
23 #include "xen_internal.h"
24 #include <xen/api/xen_common.h>
25 #include <xen/api/xen_network.h>
26 #include <xen/api/xen_pif.h>
27 #include <xen/api/xen_string_string_map.h>
28 #include <xen/api/xen_vif.h>
31 XEN_FREE(xen_network)
32 XEN_SET_ALLOC_FREE(xen_network)
33 XEN_ALLOC(xen_network_record)
34 XEN_SET_ALLOC_FREE(xen_network_record)
35 XEN_ALLOC(xen_network_record_opt)
36 XEN_RECORD_OPT_FREE(xen_network)
37 XEN_SET_ALLOC_FREE(xen_network_record_opt)
40 static const struct_member xen_network_record_struct_members[] =
41 {
42 { .key = "uuid",
43 .type = &abstract_type_string,
44 .offset = offsetof(xen_network_record, uuid) },
45 { .key = "name_label",
46 .type = &abstract_type_string,
47 .offset = offsetof(xen_network_record, name_label) },
48 { .key = "name_description",
49 .type = &abstract_type_string,
50 .offset = offsetof(xen_network_record, name_description) },
51 { .key = "VIFs",
52 .type = &abstract_type_ref_set,
53 .offset = offsetof(xen_network_record, vifs) },
54 { .key = "PIFs",
55 .type = &abstract_type_ref_set,
56 .offset = offsetof(xen_network_record, pifs) },
57 { .key = "other_config",
58 .type = &abstract_type_string_string_map,
59 .offset = offsetof(xen_network_record, other_config) }
60 };
62 const abstract_type xen_network_record_abstract_type_ =
63 {
64 .typename = STRUCT,
65 .struct_size = sizeof(xen_network_record),
66 .member_count =
67 sizeof(xen_network_record_struct_members) / sizeof(struct_member),
68 .members = xen_network_record_struct_members
69 };
72 void
73 xen_network_record_free(xen_network_record *record)
74 {
75 if (record == NULL)
76 {
77 return;
78 }
79 free(record->handle);
80 free(record->uuid);
81 free(record->name_label);
82 free(record->name_description);
83 xen_vif_record_opt_set_free(record->vifs);
84 xen_pif_record_opt_set_free(record->pifs);
85 xen_string_string_map_free(record->other_config);
86 free(record);
87 }
90 bool
91 xen_network_get_record(xen_session *session, xen_network_record **result, xen_network network)
92 {
93 abstract_value param_values[] =
94 {
95 { .type = &abstract_type_string,
96 .u.string_val = network }
97 };
99 abstract_type result_type = xen_network_record_abstract_type_;
101 *result = NULL;
102 XEN_CALL_("network.get_record");
104 if (session->ok)
105 {
106 (*result)->handle = xen_strdup_((*result)->uuid);
107 }
109 return session->ok;
110 }
113 bool
114 xen_network_get_by_uuid(xen_session *session, xen_network *result, char *uuid)
115 {
116 abstract_value param_values[] =
117 {
118 { .type = &abstract_type_string,
119 .u.string_val = uuid }
120 };
122 abstract_type result_type = abstract_type_string;
124 *result = NULL;
125 XEN_CALL_("network.get_by_uuid");
126 return session->ok;
127 }
130 bool
131 xen_network_create(xen_session *session, xen_network *result, xen_network_record *record)
132 {
133 abstract_value param_values[] =
134 {
135 { .type = &xen_network_record_abstract_type_,
136 .u.struct_val = record }
137 };
139 abstract_type result_type = abstract_type_string;
141 *result = NULL;
142 XEN_CALL_("network.create");
143 return session->ok;
144 }
147 bool
148 xen_network_destroy(xen_session *session, xen_network network)
149 {
150 abstract_value param_values[] =
151 {
152 { .type = &abstract_type_string,
153 .u.string_val = network }
154 };
156 xen_call_(session, "network.destroy", param_values, 1, NULL, NULL);
157 return session->ok;
158 }
161 bool
162 xen_network_get_by_name_label(xen_session *session, struct xen_network_set **result, char *label)
163 {
164 abstract_value param_values[] =
165 {
166 { .type = &abstract_type_string,
167 .u.string_val = label }
168 };
170 abstract_type result_type = abstract_type_string_set;
172 *result = NULL;
173 XEN_CALL_("network.get_by_name_label");
174 return session->ok;
175 }
178 bool
179 xen_network_get_name_label(xen_session *session, char **result, xen_network network)
180 {
181 abstract_value param_values[] =
182 {
183 { .type = &abstract_type_string,
184 .u.string_val = network }
185 };
187 abstract_type result_type = abstract_type_string;
189 *result = NULL;
190 XEN_CALL_("network.get_name_label");
191 return session->ok;
192 }
195 bool
196 xen_network_get_name_description(xen_session *session, char **result, xen_network network)
197 {
198 abstract_value param_values[] =
199 {
200 { .type = &abstract_type_string,
201 .u.string_val = network }
202 };
204 abstract_type result_type = abstract_type_string;
206 *result = NULL;
207 XEN_CALL_("network.get_name_description");
208 return session->ok;
209 }
212 bool
213 xen_network_get_vifs(xen_session *session, struct xen_vif_set **result, xen_network network)
214 {
215 abstract_value param_values[] =
216 {
217 { .type = &abstract_type_string,
218 .u.string_val = network }
219 };
221 abstract_type result_type = abstract_type_string_set;
223 *result = NULL;
224 XEN_CALL_("network.get_VIFs");
225 return session->ok;
226 }
229 bool
230 xen_network_get_pifs(xen_session *session, struct xen_pif_set **result, xen_network network)
231 {
232 abstract_value param_values[] =
233 {
234 { .type = &abstract_type_string,
235 .u.string_val = network }
236 };
238 abstract_type result_type = abstract_type_string_set;
240 *result = NULL;
241 XEN_CALL_("network.get_PIFs");
242 return session->ok;
243 }
246 bool
247 xen_network_get_other_config(xen_session *session, xen_string_string_map **result, xen_network network)
248 {
249 abstract_value param_values[] =
250 {
251 { .type = &abstract_type_string,
252 .u.string_val = network }
253 };
255 abstract_type result_type = abstract_type_string_string_map;
257 *result = NULL;
258 XEN_CALL_("network.get_other_config");
259 return session->ok;
260 }
263 bool
264 xen_network_set_name_label(xen_session *session, xen_network network, char *label)
265 {
266 abstract_value param_values[] =
267 {
268 { .type = &abstract_type_string,
269 .u.string_val = network },
270 { .type = &abstract_type_string,
271 .u.string_val = label }
272 };
274 xen_call_(session, "network.set_name_label", param_values, 2, NULL, NULL);
275 return session->ok;
276 }
279 bool
280 xen_network_set_name_description(xen_session *session, xen_network network, char *description)
281 {
282 abstract_value param_values[] =
283 {
284 { .type = &abstract_type_string,
285 .u.string_val = network },
286 { .type = &abstract_type_string,
287 .u.string_val = description }
288 };
290 xen_call_(session, "network.set_name_description", param_values, 2, NULL, NULL);
291 return session->ok;
292 }
295 bool
296 xen_network_set_other_config(xen_session *session, xen_network network, xen_string_string_map *other_config)
297 {
298 abstract_value param_values[] =
299 {
300 { .type = &abstract_type_string,
301 .u.string_val = network },
302 { .type = &abstract_type_string_string_map,
303 .u.set_val = (arbitrary_set *)other_config }
304 };
306 xen_call_(session, "network.set_other_config", param_values, 2, NULL, NULL);
307 return session->ok;
308 }
311 bool
312 xen_network_add_to_other_config(xen_session *session, xen_network network, char *key, char *value)
313 {
314 abstract_value param_values[] =
315 {
316 { .type = &abstract_type_string,
317 .u.string_val = network },
318 { .type = &abstract_type_string,
319 .u.string_val = key },
320 { .type = &abstract_type_string,
321 .u.string_val = value }
322 };
324 xen_call_(session, "network.add_to_other_config", param_values, 3, NULL, NULL);
325 return session->ok;
326 }
329 bool
330 xen_network_remove_from_other_config(xen_session *session, xen_network network, char *key)
331 {
332 abstract_value param_values[] =
333 {
334 { .type = &abstract_type_string,
335 .u.string_val = network },
336 { .type = &abstract_type_string,
337 .u.string_val = key }
338 };
340 xen_call_(session, "network.remove_from_other_config", param_values, 2, NULL, NULL);
341 return session->ok;
342 }
345 bool
346 xen_network_get_all(xen_session *session, struct xen_network_set **result)
347 {
349 abstract_type result_type = abstract_type_string_set;
351 *result = NULL;
352 xen_call_(session, "network.get_all", NULL, 0, &result_type, result);
353 return session->ok;
354 }
357 bool
358 xen_network_get_uuid(xen_session *session, char **result, xen_network network)
359 {
360 abstract_value param_values[] =
361 {
362 { .type = &abstract_type_string,
363 .u.string_val = network }
364 };
366 abstract_type result_type = abstract_type_string;
368 *result = NULL;
369 XEN_CALL_("network.get_uuid");
370 return session->ok;
371 }