summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9b022eb)
raw | patch | inline | side by side (parent: 9b022eb)
author | Remi Ferrand <remi.ferrand@cc.in2p3.fr> | |
Tue, 30 Jul 2013 13:01:38 +0000 (15:01 +0200) | ||
committer | Remi Ferrand <remi.ferrand@cc.in2p3.fr> | |
Tue, 30 Jul 2013 15:45:00 +0000 (17:45 +0200) |
src/libvirt.c | patch | blob | history |
diff --git a/src/libvirt.c b/src/libvirt.c
index cfabaaa235d6efe81da7896e4c51185d6afa08a3..3cec03509403a80b19d4f804da3a099564b4ac39 100644 (file)
--- a/src/libvirt.c
+++ b/src/libvirt.c
"HostnameFormat",
"InterfaceFormat",
+ "PluginInstanceFormat",
+
NULL
};
#define NR_CONFIG_KEYS ((sizeof config_keys / sizeof config_keys[0]) - 1)
static enum hf_field hostname_format[HF_MAX_FIELDS] =
{ hf_name };
+/* PluginInstanceFormat */
+#define PLGINST_MAX_FIELDS 2
+
+enum plginst_field {
+ plginst_none = 0,
+ plginst_name,
+ plginst_uuid
+};
+
+static enum plginst_field plugin_instance_format[PLGINST_MAX_FIELDS] =
+ { plginst_name };
+
/* InterfaceFormat. */
enum if_field {
if_address,
}
vl->host[sizeof (vl->host) - 1] = '\0';
+
+ /* Construct the plugin instance field according to PluginInstanceFormat. */
+ for (i = 0; i < PLGINST_MAX_FIELDS; ++i) {
+ if (plugin_instance_format[i] == plginst_none)
+ continue;
+
+ n = DATA_MAX_NAME_LEN - strlen (vl->plugin_instance) - 2;
+
+ if (i > 0 && n >= 1) {
+ strncat (vl->plugin_instance, ":", 1);
+ n--;
+ }
+
+ switch (plugin_instance_format[i]) {
+ case plginst_none: break;
+ case plginst_name:
+ name = virDomainGetName (dom);
+ if (name)
+ strncat (vl->plugin_instance, name, n);
+ break;
+ case plginst_uuid:
+ if (virDomainGetUUIDString (dom, uuid) == 0)
+ strncat (vl->plugin_instance, uuid, n);
+ break;
+ }
+ }
+
+ vl->plugin_instance[sizeof (vl->plugin_instance) - 1] = '\0';
+
} /* void init_value_list */
static void
return 0;
}
+ if (strcasecmp (key, "PluginInstanceFormat") == 0) {
+ char *value_copy;
+ char *fields[PLGINST_MAX_FIELDS];
+ int i, n;
+
+ value_copy = strdup (value);
+ if (value_copy == NULL) {
+ ERROR ("libvirt plugin: strdup failed.");
+ return -1;
+ }
+
+ n = strsplit (value_copy, fields, PLGINST_MAX_FIELDS);
+ if (n < 1) {
+ sfree (value_copy);
+ ERROR ("PluginInstanceFormat: no fields");
+ return -1;
+ }
+
+ for (i = 0; i < n; ++i) {
+ if (strcasecmp (fields[i], "name") == 0)
+ plugin_instance_format[i] = plginst_name;
+ else if (strcasecmp (fields[i], "uuid") == 0)
+ plugin_instance_format[i] = plginst_uuid;
+ else {
+ sfree (value_copy);
+ ERROR ("unknown HostnameFormat field: %s", fields[i]);
+ return -1;
+ }
+ }
+ sfree (value_copy);
+
+ for (i = n; i < PLGINST_MAX_FIELDS; ++i)
+ plugin_instance_format[i] = plginst_none;
+
+ return 0;
+ }
+
if (strcasecmp (key, "InterfaceFormat") == 0) {
if (strcasecmp (value, "name") == 0)
interface_format = if_name;