def load_policies(self): """Load the policy domains from file. :return: A list of policies to create. """ policies = [] pd_assignments = [] try: self._logging.info("Loading config from file: %s", self._policy_file) with open(self._policy_file) as buf_in: pd_yaml = yaml.load(buf_in) except: self._logging.error("Error reading from file %s: %s", self._policy_file, sys.exc_info()[0]) sys.exit("Error reading from file {0}: {1}".format( self._policy_file, sys.exc_info()[1])) # Perform a configuration file key check if not self._check_conf_keys(pd_yaml, self._PD_CONF_KEYS, self._policy_file): self._logging.critical("Please correct configuration file: " "%s", self._policy_file) sys.exit("Please correct configuration file: {0}".format( self._policy_file)) # Copy declared policy domains into a list, if there are any if pd_yaml["policy_domains"] is not None: for policy in pd_yaml["policy_domains"]: if policy is not None: self._logging.debug("Reading Policy Domain: %s", policy) policies.append(policy) # Read in policy assignments, if there are any if pd_yaml["pd_assignments"] is not None: for assignment in pd_yaml["pd_assignments"]: if assignment is not None: if not data_templates.check_policy_assign_data(assignment): self._logging.warning( "%s is not formatted " "correctly.", assignment) continue self._logging.debug( "Reading Policy Domain " "assignment: %s", str(assignment)) pd_assignments.append(assignment) return policies, pd_assignments
def load_policies(self): """Load the policy domains from file. :return: A list of policies to create. """ policies = [] pd_assignments = [] try: self._logging.info("Loading config from file: %s", self._policy_file) with open(self._policy_file) as buf_in: pd_yaml = yaml.load(buf_in) except: self._logging.error("Error reading from file %s: %s", self._policy_file, sys.exc_info()[0]) sys.exit("Error reading from file {0}: {1}".format( self._policy_file, sys.exc_info()[1])) # Perform a configuration file key check if not self._check_conf_keys(pd_yaml, self._PD_CONF_KEYS, self._policy_file): self._logging.critical("Please correct configuration file: " "%s", self._policy_file) sys.exit("Please correct configuration file: {0}".format( self._policy_file)) # Copy declared policy domains into a list, if there are any if pd_yaml["policy_domains"] is not None: for policy in pd_yaml["policy_domains"]: if policy is not None: self._logging.debug("Reading Policy Domain: %s", policy) policies.append(policy) # Read in policy assignments, if there are any if pd_yaml["pd_assignments"] is not None: for assignment in pd_yaml["pd_assignments"]: if assignment is not None: if not data_templates.check_policy_assign_data( assignment): self._logging.warning("%s is not formatted " "correctly.", assignment) continue self._logging.debug("Reading Policy Domain " "assignment: %s", str(assignment)) pd_assignments.append(assignment) return policies, pd_assignments
def delete_policy_revoke(self, req, **kwargs): """Endpoint for revoking a policy from a switch. :return: A response containing the result of the operation. """ try: policy_revoke_req = json.loads(req.body) if not data_templates.check_policy_assign_data( policy_revoke_req): raise KeyError except (ValueError, KeyError): error = self._MSG_ERROR.copy() error["error"] = "Invalid policy domain assignment revoke " \ "JSON passed." return Response(status=400, body=json.dumps(error)) return_status = self._api.policy_revoke_switch( policy_revoke_req["switch_id"], policy_revoke_req["policy"]) return self._api_response(return_status)