diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/libxen/include/xen_vif.h | 17 | ||||
-rw-r--r-- | tools/libxen/include/xen_vif_metrics.h | 183 | ||||
-rw-r--r-- | tools/libxen/include/xen_vif_metrics_decl.h | 30 | ||||
-rw-r--r-- | tools/libxen/src/xen_vif.c | 36 | ||||
-rw-r--r-- | tools/libxen/src/xen_vif_metrics.c | 150 | ||||
-rw-r--r-- | tools/python/xen/xend/XendAPI.py | 73 |
6 files changed, 428 insertions, 61 deletions
diff --git a/tools/libxen/include/xen_vif.h b/tools/libxen/include/xen_vif.h index 7141bf3197..160d8a02b3 100644 --- a/tools/libxen/include/xen_vif.h +++ b/tools/libxen/include/xen_vif.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, XenSource Inc. + * Copyright (c) 2006-2007, XenSource Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,6 +22,7 @@ #include "xen_common.h" #include "xen_network_decl.h" #include "xen_vif_decl.h" +#include "xen_vif_metrics_decl.h" #include "xen_vm_decl.h" @@ -69,8 +70,7 @@ typedef struct xen_vif_record struct xen_vm_record_opt *vm; char *mac; int64_t mtu; - double io_read_kbs; - double io_write_kbs; + struct xen_vif_metrics_record_opt *metrics; } xen_vif_record; /** @@ -223,17 +223,10 @@ xen_vif_get_mtu(xen_session *session, int64_t *result, xen_vif vif); /** - * Get the io/read_kbs field of the given VIF. + * Get the metrics field of the given VIF. */ extern bool -xen_vif_get_io_read_kbs(xen_session *session, double *result, xen_vif vif); - - -/** - * Get the io/write_kbs field of the given VIF. - */ -extern bool -xen_vif_get_io_write_kbs(xen_session *session, double *result, xen_vif vif); +xen_vif_get_metrics(xen_session *session, xen_vif_metrics *result, xen_vif vif); /** diff --git a/tools/libxen/include/xen_vif_metrics.h b/tools/libxen/include/xen_vif_metrics.h new file mode 100644 index 0000000000..2b150d0a68 --- /dev/null +++ b/tools/libxen/include/xen_vif_metrics.h @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2006-2007, XenSource Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef XEN_VIF_METRICS_H +#define XEN_VIF_METRICS_H + +#include "xen_common.h" +#include "xen_vif_metrics_decl.h" + + +/* + * The VIF_metrics class. + * + * The metrics associated with a virtual network device. + */ + + +/** + * Free the given xen_vif_metrics. The given handle must have been + * allocated by this library. + */ +extern void +xen_vif_metrics_free(xen_vif_metrics vif_metrics); + + +typedef struct xen_vif_metrics_set +{ + size_t size; + xen_vif_metrics *contents[]; +} xen_vif_metrics_set; + +/** + * Allocate a xen_vif_metrics_set of the given size. + */ +extern xen_vif_metrics_set * +xen_vif_metrics_set_alloc(size_t size); + +/** + * Free the given xen_vif_metrics_set. The given set must have been + * allocated by this library. + */ +extern void +xen_vif_metrics_set_free(xen_vif_metrics_set *set); + + +typedef struct xen_vif_metrics_record +{ + xen_vif_metrics handle; + char *uuid; + double io_read_kbs; + double io_write_kbs; +} xen_vif_metrics_record; + +/** + * Allocate a xen_vif_metrics_record. + */ +extern xen_vif_metrics_record * +xen_vif_metrics_record_alloc(void); + +/** + * Free the given xen_vif_metrics_record, and all referenced values. + * The given record must have been allocated by this library. + */ +extern void +xen_vif_metrics_record_free(xen_vif_metrics_record *record); + + +typedef struct xen_vif_metrics_record_opt +{ + bool is_record; + union + { + xen_vif_metrics handle; + xen_vif_metrics_record *record; + } u; +} xen_vif_metrics_record_opt; + +/** + * Allocate a xen_vif_metrics_record_opt. + */ +extern xen_vif_metrics_record_opt * +xen_vif_metrics_record_opt_alloc(void); + +/** + * Free the given xen_vif_metrics_record_opt, and all referenced + * values. The given record_opt must have been allocated by this library. + */ +extern void +xen_vif_metrics_record_opt_free(xen_vif_metrics_record_opt *record_opt); + + +typedef struct xen_vif_metrics_record_set +{ + size_t size; + xen_vif_metrics_record *contents[]; +} xen_vif_metrics_record_set; + +/** + * Allocate a xen_vif_metrics_record_set of the given size. + */ +extern xen_vif_metrics_record_set * +xen_vif_metrics_record_set_alloc(size_t size); + +/** + * Free the given xen_vif_metrics_record_set, and all referenced + * values. The given set must have been allocated by this library. + */ +extern void +xen_vif_metrics_record_set_free(xen_vif_metrics_record_set *set); + + + +typedef struct xen_vif_metrics_record_opt_set +{ + size_t size; + xen_vif_metrics_record_opt *contents[]; +} xen_vif_metrics_record_opt_set; + +/** + * Allocate a xen_vif_metrics_record_opt_set of the given size. + */ +extern xen_vif_metrics_record_opt_set * +xen_vif_metrics_record_opt_set_alloc(size_t size); + +/** + * Free the given xen_vif_metrics_record_opt_set, and all referenced + * values. The given set must have been allocated by this library. + */ +extern void +xen_vif_metrics_record_opt_set_free(xen_vif_metrics_record_opt_set *set); + + +/** + * Get a record containing the current state of the given VIF_metrics. + */ +extern bool +xen_vif_metrics_get_record(xen_session *session, xen_vif_metrics_record **result, xen_vif_metrics vif_metrics); + + +/** + * Get a reference to the VIF_metrics instance with the specified UUID. + */ +extern bool +xen_vif_metrics_get_by_uuid(xen_session *session, xen_vif_metrics *result, char *uuid); + + +/** + * Get the uuid field of the given VIF_metrics. + */ +extern bool +xen_vif_metrics_get_uuid(xen_session *session, char **result, xen_vif_metrics vif_metrics); + + +/** + * Get the io/read_kbs field of the given VIF_metrics. + */ +extern bool +xen_vif_metrics_get_io_read_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics); + + +/** + * Get the io/write_kbs field of the given VIF_metrics. + */ +extern bool +xen_vif_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics); + + +#endif diff --git a/tools/libxen/include/xen_vif_metrics_decl.h b/tools/libxen/include/xen_vif_metrics_decl.h new file mode 100644 index 0000000000..5734723adf --- /dev/null +++ b/tools/libxen/include/xen_vif_metrics_decl.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2006-2007, XenSource Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef XEN_VIF_METRICS_DECL_H +#define XEN_VIF_METRICS_DECL_H + +typedef void *xen_vif_metrics; + +struct xen_vif_metrics_set; +struct xen_vif_metrics_record; +struct xen_vif_metrics_record_set; +struct xen_vif_metrics_record_opt; +struct xen_vif_metrics_record_opt_set; + +#endif diff --git a/tools/libxen/src/xen_vif.c b/tools/libxen/src/xen_vif.c index 47ef4730f6..3fc214b16e 100644 --- a/tools/libxen/src/xen_vif.c +++ b/tools/libxen/src/xen_vif.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, XenSource Inc. + * Copyright (c) 2006-2007, XenSource Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,6 +24,7 @@ #include "xen_internal.h" #include "xen_network.h" #include "xen_vif.h" +#include "xen_vif_metrics.h" #include "xen_vm.h" @@ -56,12 +57,9 @@ static const struct_member xen_vif_record_struct_members[] = { .key = "MTU", .type = &abstract_type_int, .offset = offsetof(xen_vif_record, mtu) }, - { .key = "io_read_kbs", - .type = &abstract_type_float, - .offset = offsetof(xen_vif_record, io_read_kbs) }, - { .key = "io_write_kbs", - .type = &abstract_type_float, - .offset = offsetof(xen_vif_record, io_write_kbs) } + { .key = "metrics", + .type = &abstract_type_ref, + .offset = offsetof(xen_vif_record, metrics) } }; const abstract_type xen_vif_record_abstract_type_ = @@ -87,6 +85,7 @@ xen_vif_record_free(xen_vif_record *record) xen_network_record_opt_free(record->network); xen_vm_record_opt_free(record->vm); free(record->mac); + xen_vif_metrics_record_opt_free(record->metrics); free(record); } @@ -247,23 +246,7 @@ xen_vif_get_mtu(xen_session *session, int64_t *result, xen_vif vif) bool -xen_vif_get_io_read_kbs(xen_session *session, double *result, xen_vif vif) -{ - abstract_value param_values[] = - { - { .type = &abstract_type_string, - .u.string_val = vif } - }; - - abstract_type result_type = abstract_type_float; - - XEN_CALL_("VIF.get_io_read_kbs"); - return session->ok; -} - - -bool -xen_vif_get_io_write_kbs(xen_session *session, double *result, xen_vif vif) +xen_vif_get_metrics(xen_session *session, xen_vif_metrics *result, xen_vif vif) { abstract_value param_values[] = { @@ -271,9 +254,10 @@ xen_vif_get_io_write_kbs(xen_session *session, double *result, xen_vif vif) .u.string_val = vif } }; - abstract_type result_type = abstract_type_float; + abstract_type result_type = abstract_type_string; - XEN_CALL_("VIF.get_io_write_kbs"); + *result = NULL; + XEN_CALL_("VIF.get_metrics"); return session->ok; } diff --git a/tools/libxen/src/xen_vif_metrics.c b/tools/libxen/src/xen_vif_metrics.c new file mode 100644 index 0000000000..1f43993024 --- /dev/null +++ b/tools/libxen/src/xen_vif_metrics.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2006-2007, XenSource Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include <stddef.h> +#include <stdlib.h> + +#include "xen_common.h" +#include "xen_internal.h" +#include "xen_vif_metrics.h" + + +XEN_FREE(xen_vif_metrics) +XEN_SET_ALLOC_FREE(xen_vif_metrics) +XEN_ALLOC(xen_vif_metrics_record) +XEN_SET_ALLOC_FREE(xen_vif_metrics_record) +XEN_ALLOC(xen_vif_metrics_record_opt) +XEN_RECORD_OPT_FREE(xen_vif_metrics) +XEN_SET_ALLOC_FREE(xen_vif_metrics_record_opt) + + +static const struct_member xen_vif_metrics_record_struct_members[] = + { + { .key = "uuid", + .type = &abstract_type_string, + .offset = offsetof(xen_vif_metrics_record, uuid) }, + { .key = "io_read_kbs", + .type = &abstract_type_float, + .offset = offsetof(xen_vif_metrics_record, io_read_kbs) }, + { .key = "io_write_kbs", + .type = &abstract_type_float, + .offset = offsetof(xen_vif_metrics_record, io_write_kbs) } + }; + +const abstract_type xen_vif_metrics_record_abstract_type_ = + { + .typename = STRUCT, + .struct_size = sizeof(xen_vif_metrics_record), + .member_count = + sizeof(xen_vif_metrics_record_struct_members) / sizeof(struct_member), + .members = xen_vif_metrics_record_struct_members + }; + + +void +xen_vif_metrics_record_free(xen_vif_metrics_record *record) +{ + if (record == NULL) + { + return; + } + free(record->handle); + free(record->uuid); + free(record); +} + + +bool +xen_vif_metrics_get_record(xen_session *session, xen_vif_metrics_record **result, xen_vif_metrics vif_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vif_metrics } + }; + + abstract_type result_type = xen_vif_metrics_record_abstract_type_; + + *result = NULL; + XEN_CALL_("VIF_metrics.get_record"); + + if (session->ok) + { + (*result)->handle = xen_strdup_((*result)->uuid); + } + + return session->ok; +} + + +bool +xen_vif_metrics_get_by_uuid(xen_session *session, xen_vif_metrics *result, char *uuid) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = uuid } + }; + + abstract_type result_type = abstract_type_string; + + *result = NULL; + XEN_CALL_("VIF_metrics.get_by_uuid"); + return session->ok; +} + + +bool +xen_vif_metrics_get_io_read_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vif_metrics } + }; + + abstract_type result_type = abstract_type_float; + + XEN_CALL_("VIF_metrics.get_io_read_kbs"); + return session->ok; +} + + +bool +xen_vif_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vif_metrics } + }; + + abstract_type result_type = abstract_type_float; + + XEN_CALL_("VIF_metrics.get_io_write_kbs"); + return session->ok; +} + + +bool +xen_vif_metrics_get_uuid(xen_session *session, char **result, xen_vif_metrics vif_metrics) +{ + *result = session->ok ? xen_strdup_((char *)vif_metrics) : NULL; + return session->ok; +} diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py index c56a3afba0..ca5059157c 100644 --- a/tools/python/xen/xend/XendAPI.py +++ b/tools/python/xen/xend/XendAPI.py @@ -229,6 +229,16 @@ def valid_vif(func): _check_ref(lambda r: XendDomain.instance().is_valid_dev('vif', r), 'VIF', func, *args, **kwargs) +def valid_vif_metrics(func): + """Decorator to verify if ref is valid before calling method. + + @param func: function with params: (self, session, ref, ...) + @rtype: callable object + """ + return lambda *args, **kwargs: \ + _check_ref(lambda r: XendDomain.instance().is_valid_dev('vif', r), + 'VIF_metrics', func, *args, **kwargs) + def valid_vdi(func): """Decorator to verify if vdi_ref is valid before calling method. @@ -390,6 +400,7 @@ class XendAPI(object): 'VBD' : valid_vbd, 'VBD_metrics' : valid_vbd_metrics, 'VIF' : valid_vif, + 'VIF_metrics' : valid_vif_metrics, 'VDI' : valid_vdi, 'VTPM' : valid_vtpm, 'console' : valid_console, @@ -1592,18 +1603,17 @@ class XendAPI(object): { 'io_read_kbs' : vm.get_dev_property('vbd', ref, 'io_read_kbs'), 'io_write_kbs' : vm.get_dev_property('vbd', ref, 'io_write_kbs') }) - def VBD_metrics_get_io_write_kbs(self, _, ref): + def VBD_metrics_get_io_read_kbs(self, _, ref): return self._VBD_get(ref, 'io_read_kbs') - def VBD_metrics_get_io_write_kbs(self, session, vbd_ref): + def VBD_metrics_get_io_write_kbs(self, session, ref): return self._VBD_get(ref, 'io_write_kbs') # Xen API: Class VIF # ---------------------------------------------------------------- - VIF_attr_ro = ['io_read_kbs', - 'io_write_kbs'] + VIF_attr_ro = ['metrics'] VIF_attr_rw = ['device', 'network', 'VM', @@ -1633,6 +1643,8 @@ class XendAPI(object): if k in valid_vif_keys: return_cfg[k] = cfg[k] + return_cfg['metrics'] = vif_ref + return xen_api_success(return_cfg) # class methods @@ -1659,36 +1671,28 @@ class XendAPI(object): vm.destroy_vif(vif_ref) return xen_api_success_void() + def _VIF_get(self, ref, prop): + return xen_api_success( + XendDomain.instance().get_dev_property_by_uuid('vif', ref, prop)) + # getters/setters + def VIF_get_metrics(self, _, vif_ref): + return xen_api_success(vif_ref) + def VIF_get_VM(self, session, vif_ref): xendom = XendDomain.instance() vm = xendom.get_vm_with_dev_uuid('vif', vif_ref) return xen_api_success(vm.get_uuid()) def VIF_get_MTU(self, session, vif_ref): - xendom = XendDomain.instance() - return xen_api_success(xendom.get_dev_property_by_uuid('vif', vif_ref, - 'MTU')) + return self._VIF_get(vif_ref, 'MTU') + def VIF_get_MAC(self, session, vif_ref): - xendom = XendDomain.instance() - return xen_api_success(xendom.get_dev_property_by_uuid('vif', vif_ref, - 'MAC')) + return self._VIF_get(vif_ref, 'MAC') def VIF_get_device(self, session, vif_ref): - xendom = XendDomain.instance() - return xen_api_success(xendom.get_dev_property_by_uuid('vif', vif_ref, - 'device')) + return self._VIF_get(vif_ref, 'device') - def VIF_get_io_read_kbs(self, session, vif_ref): - xendom = XendDomain.instance() - return xen_api_success(xendom.get_dev_property_by_uuid('vif', vif_ref, - 'io_read_kbs')) - - def VIF_get_io_write_kbs(self, session, vif_ref): - xendom = XendDomain.instance() - return xen_api_success(xendom.get_dev_property_by_uuid('vif', vif_ref, - 'io_write_kbs')) - def VIF_get_all(self, session): xendom = XendDomain.instance() vifs = [d.get_vifs() for d in XendDomain.instance().list('all')] @@ -1696,6 +1700,29 @@ class XendAPI(object): return xen_api_success(vifs) + # Xen API: Class VIF_metrics + # ---------------------------------------------------------------- + + VIF_metrics_attr_ro = ['io_read_kbs', + 'io_write_kbs'] + VIF_metrics_attr_rw = [] + VIF_methods = [] + + def VIF_metrics_get_record(self, _, ref): + vm = XendDomain.instance().get_vm_with_dev_uuid('vif', ref) + if not vm: + return xen_api_error(['HANDLE_INVALID', 'VIF_metrics', ref]) + return xen_api_success( + { 'io_read_kbs' : vm.get_dev_property('vif', ref, 'io_read_kbs'), + 'io_write_kbs' : vm.get_dev_property('vif', ref, 'io_write_kbs') }) + + def VIF_metrics_get_io_read_kbs(self, _, ref): + return self._VIF_get(ref, 'io_read_kbs') + + def VIF_metrics_get_io_write_kbs(self, session, ref): + return self._VIF_get(ref, 'io_write_kbs') + + # Xen API: Class VDI # ---------------------------------------------------------------- VDI_attr_ro = ['VBDs', |