def update_host_ovs(self, context, req, id, body, force, rollback): """ Update OpenVSwitch configuration. :param context: The HTTP request context. :param req: The HTTP request object. :param id: The host to update. :param body: The HTTP request body. :param force: Whether the operation should be forced through, even if potentially un-intended consequences are detected. :param rollback: Whether the operation should be rolled back before completion, often to test the rollback mechanism. :returns: A list of dictionaries with warnings and errors. """ # This class should only be used in PowerKVM environments self.raise_if_not_powerkvm() # Verify the host we're trying to update exists host_list = self._get_all_host_names(context) if id not in host_list: raise novaexception.ComputeHostNotFound(host=id) # Performing an update requires knowledge of the current state of the # host, retrieve a DOM of the current state with a remote call. current_dom = rpc_caller.get_host_ovs(context, [id])[0] if len(current_dom.error_list) > 0: raise net_excp.IBMPowerKVMVswitchUpdateException() # Validate the JSON in the PUT request body error_warning_dict = self._validate_put_body(body, current_dom) if error_warning_dict: return [error_warning_dict] # Get a DOM of the data the caller wants to update to body = self._augment_put_request(body, id) desired_dom = self._dict_to_dom(body, [current_dom])[0] # Make the remote call to the endpoint(s) to set ovs data error_warning_dict = rpc_caller.update_host_ovs(context, id, desired_dom.to_dict(), force, rollback) return error_warning_dict
def get_host_ovs(self, context, req, host_name=None): """ Read OpenVSwitch configuration. :param context: The HTTP request context. :param req: The HTTP request object. :param host_name: An optional host name to filter data with. :returns: A dictionary of host-ovs data. """ # This class should only be used in PowerKVM environments self.raise_if_not_powerkvm() # If a host was specified, verify it exists host_list = self._get_all_host_names(context) if host_name is not None: if host_name not in host_list: raise novaexception.ComputeHostNotFound(host=host_name) host_list = [host_name] LOG.debug("host-ovs GET for host(s) %s" % host_list) # Parse the vswitch_name from the request, if present vswitch_name = None if 'vswitch_name' in req.GET: vswitch_name = req.GET['vswitch_name'] if vswitch_name == '': raise net_excp.IBMPowerKVMVswitchNotFound(ovs_name='') # Make the remote call to the endpoint(s) to fetch ovs data dom_list = rpc_caller.get_host_ovs(context, host_list) # Filter based on the vswitch name, if necessary self._filter_vswitch(dom_list, vswitch_name) # Filter empty linux bridges self._filter_empty_bridges(dom_list) # Convert DOM objects into REST API dictionary format host_dict = self._dom_to_dict(dom_list) return host_dict