os-cmpi-xen

diff src/Xen_VirtualSystemManagementService.c @ 89:93600f4355d8

Added support for Xen_ConsoleSettingData.ConsoleConfigInfo
in Xen_VirtualSystemManagementService.DefineSystem(). This
allows specifying additional console configuration such as
vncunused=1, vncpasswd=foobar, etc.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Wed Feb 28 16:28:14 2007 -0700 (2007-02-28)
parents 9a96ebba2b60
children 66600aae1e53
line diff
     1.1 --- a/src/Xen_VirtualSystemManagementService.c	Mon Feb 26 14:52:36 2007 -0700
     1.2 +++ b/src/Xen_VirtualSystemManagementService.c	Wed Feb 28 16:28:14 2007 -0700
     1.3 @@ -34,6 +34,7 @@
     1.4  #include <xen_vif.h>
     1.5  #include <xen_vbd.h>
     1.6  #include <xen_console.h>
     1.7 +#include <xen_string_string_map.h>
     1.8  
     1.9  /* Include utility functions */
    1.10  #include "cmpiutil.h"
    1.11 @@ -1667,7 +1668,7 @@ static int vssd2xenconfig(CMPIInstance *
    1.12           vm_rec->platform_std_vga = propertyvalue.value.boolean;
    1.13     }
    1.14     else {
    1.15 -      _SBLIM_TRACE(1,("--- Invalide VirtualSystemType %s specified", vsType));
    1.16 +      _SBLIM_TRACE(1,("--- Invalid VirtualSystemType %s specified", vsType));
    1.17        CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER,
    1.18                             "Invalid VirtualSystemType specified");
    1.19        return 0;
    1.20 @@ -1744,21 +1745,24 @@ static int disk_rasd2vmconfig(CMPIInstan
    1.21        tok = strtok_r(string, ",", &next_tok);
    1.22        if (tok == NULL) {
    1.23           _SBLIM_TRACE(1,("--- Malformed DiskConfigInfo property in disk setting data"));
    1.24 -         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalide disk setting data");
    1.25 +         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid disk setting data");
    1.26 +         free(string);
    1.27           goto Error;
    1.28        }
    1.29        (*vbd_rec)->image = strdup(tok);
    1.30  
    1.31        if ((tok = strtok_r(NULL, ",", &next_tok)) == NULL) {
    1.32           _SBLIM_TRACE(1,("--- Malformed DiskConfigInfo property in disk setting data"));
    1.33 -         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalide disk setting data");
    1.34 +         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid disk setting data");
    1.35 +         free(string);
    1.36           goto Error;
    1.37        }
    1.38        (*vbd_rec)->device = strdup(tok);
    1.39  
    1.40        if ((tok = strtok_r(NULL, ",", &next_tok)) == NULL) {
    1.41           _SBLIM_TRACE(1,("--- Malformed DiskConfigInfo property in disk setting data"));
    1.42 -         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalide disk setting data");
    1.43 +         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid disk setting data");
    1.44 +         free(string);
    1.45           goto Error;
    1.46        }
    1.47        if (strcmp(tok, "w") == 0)
    1.48 @@ -1791,52 +1795,53 @@ static int nic_rasd2vmconfig(CMPIInstanc
    1.49     
    1.50     /* Set the domain config data from the Xen_NetworkPortSettingData. */
    1.51     propertyvalue = CMGetProperty(nic_rasd, "NICConfigInfo", status);
    1.52 -   if ((status->rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) {
    1.53 -      *vif_rec = xen_vif_record_alloc();
    1.54 -      if (*vif_rec == NULL) {
    1.55 -         _SBLIM_TRACE(1,("--- Cannot malloc memory for virtual network device"));
    1.56 -         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, "Unable to malloc memory");
    1.57 -         return 0;
    1.58 -      }
    1.59 -
    1.60 -      /* Extract the type, mac and network params from the NicConfigInfo
    1.61 -       * string.  Expected syntax is "key=value,key=value" */
    1.62 -      char * next_tok;
    1.63 -      char * string = strdup(CMGetCharPtr(propertyvalue.value.string));
    1.64 -      char *tok = strtok_r(string, ",", &next_tok);
    1.65 -      /* If tok is NULL, then string contains only 1 key/value pair */
    1.66 -      if (tok == NULL)
    1.67 -         tok = string;
    1.68 -      while (tok) {
    1.69 -         if (strncmp(tok, "mac", 3) == 0)
    1.70 -            (*vif_rec)->mac = strdup(tok + 4);
    1.71 -         /*
    1.72 -          * TODO:
    1.73 -          * Map other config items in the NIC info to xen_vif_record struct.
    1.74 -          */
    1.75 -         
    1.76 -         tok = strtok_r(NULL, ",", &next_tok);
    1.77 -      }
    1.78 +   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) {
    1.79 +      _SBLIM_TRACE(1,("--- No NICConfigInfo specified in network port setting data"));
    1.80 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "No NICConfigInfo specified in network port setting data");
    1.81        
    1.82 -      free(string);
    1.83 -      _SBLIM_TRACE(2,("--- mac = %s",
    1.84 -                      (*vif_rec)->mac ?  (*vif_rec)->mac : "not specified"));
    1.85 -    
    1.86 -      return 1;
    1.87 +      *vif_rec = NULL;
    1.88 +      return 0;
    1.89 +   }
    1.90 +   
    1.91 +   *vif_rec = xen_vif_record_alloc();
    1.92 +   if (*vif_rec == NULL) {
    1.93 +      _SBLIM_TRACE(1,("--- Cannot malloc memory for virtual network device"));
    1.94 +      CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, "Unable to malloc memory");
    1.95 +      return 0;
    1.96     }
    1.97     
    1.98 -   *vif_rec = NULL;
    1.99 -   return 0;
   1.100 +   /* Extract the type, mac and network params from the NicConfigInfo
   1.101 +    * string.  Expected syntax is "key=value,key=value" */
   1.102 +   char * next_tok;
   1.103 +   char * string = strdup(CMGetCharPtr(propertyvalue.value.string));
   1.104 +   char *tok = strtok_r(string, ",", &next_tok);
   1.105 +   while (tok) {
   1.106 +      if (strncmp(tok, "mac", 3) == 0)
   1.107 +         (*vif_rec)->mac = strdup(tok + 4);
   1.108 +      /*
   1.109 +       * TODO:
   1.110 +       * Map other config items in the NIC info to xen_vif_record struct.
   1.111 +       */
   1.112 +      
   1.113 +      tok = strtok_r(NULL, ",", &next_tok);
   1.114 +   }
   1.115 +   
   1.116 +   free(string);
   1.117 +   _SBLIM_TRACE(2,("--- mac = %s",
   1.118 +                   (*vif_rec)->mac ?  (*vif_rec)->mac : "not specified"));
   1.119 +   
   1.120 +   return 1;
   1.121  }
   1.122  
   1.123  
   1.124  static int con_rasd2vmconfig(CMPIInstance *con_rasd, xen_console_record *con_rec,
   1.125                               CMPIStatus *status)
   1.126  {
   1.127 +   CMPIStatus local_status = {CMPI_RC_OK, NULL};
   1.128     CMPIData propertyvalue;
   1.129     
   1.130 -   propertyvalue = CMGetProperty(con_rasd, "Protocol", status);
   1.131 -   if ((status->rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) {
   1.132 +   propertyvalue = CMGetProperty(con_rasd, "Protocol", &local_status);
   1.133 +   if ((local_status.rc != CMPI_RC_OK) || CMIsNullValue(propertyvalue)) {
   1.134        _SBLIM_TRACE(1,("--- No protocol field specified in console setting data"));
   1.135        CMSetStatusWithChars(_BROKER, status,  CMPI_RC_ERR_INVALID_PARAMETER, "No protocol specified in console setting data");
   1.136        return 0;
   1.137 @@ -1858,6 +1863,60 @@ static int con_rasd2vmconfig(CMPIInstanc
   1.138           return 0;
   1.139     }
   1.140  
   1.141 +   /*
   1.142 +    * Get any additional config from ConsoleConfigInfo.
   1.143 +    * Expected syntax is "key=value,key=value"
   1.144 +    */
   1.145 +   propertyvalue = CMGetProperty(con_rasd, "ConsoleConfigInfo", &local_status);
   1.146 +   if ((local_status.rc == CMPI_RC_OK) && !CMIsNullValue(propertyvalue)) {
   1.147 +      /* Count number of config items */
   1.148 +      int num_items = 0;
   1.149 +      char *next_tok;
   1.150 +      char *string = strdup(CMGetCharPtr(propertyvalue.value.string));
   1.151 +      char *tok = strtok_r(string, ",", &next_tok);
   1.152 +      while (tok) {
   1.153 +         num_items++;
   1.154 +         tok = strtok_r(NULL, ",", &next_tok);
   1.155 +      }
   1.156 +      free(string);
   1.157 +      
   1.158 +      xen_string_string_map *con_params = xen_string_string_map_alloc(num_items);
   1.159 +      if (con_params == NULL) {
   1.160 +         _SBLIM_TRACE(1,("--- Cannot malloc memory for console options"));
   1.161 +         CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERROR_SYSTEM, "Unable to malloc memory");
   1.162 +         return 0;
   1.163 +      }
   1.164 +      
   1.165 +      /*
   1.166 +       * Go back through the options and populate the string map.
   1.167 +       */
   1.168 +      string = strdup(CMGetCharPtr(propertyvalue.value.string));
   1.169 +      tok = strtok_r(string, ",", &next_tok);
   1.170 +      /* If tok is NULL, then string contains only 1 key/value pair */
   1.171 +      if (tok == NULL)
   1.172 +         tok = string;
   1.173 +      int i = 0;
   1.174 +      while (tok) {
   1.175 +         char *val = strchr(tok, '=');
   1.176 +         if (val == NULL) {
   1.177 +            _SBLIM_TRACE(1,("--- Invalid console option specified in console setting data"));
   1.178 +            CMSetStatusWithChars(_BROKER, status, CMPI_RC_ERR_INVALID_PARAMETER, "Invalid console option specified in console setting data");
   1.179 +            xen_string_string_map_free(con_params);
   1.180 +            free(string);
   1.181 +            return 0;
   1.182 +         }
   1.183 +         *val = '\0';
   1.184 +         val++;
   1.185 +         con_params->contents[i].key = strdup(tok);
   1.186 +         con_params->contents[i].val = strdup(val);
   1.187 +         i++;
   1.188 +         tok = strtok_r(NULL, ",", &next_tok);
   1.189 +      }
   1.190 +      
   1.191 +      con_rec->other_config = con_params;
   1.192 +      free(string);
   1.193 +   }
   1.194 +
   1.195     return 1;
   1.196  }
   1.197