def purge_deleted(tacker_config, table_name, age, granularity='days'): try: age = int(age) except ValueError: msg = _("'%s' - age should be an integer") % age raise exceptions.InvalidInput(error_message=msg) if age < 0: msg = _("'%s' - age should be a positive integer") % age raise exceptions.InvalidInput(error_message=msg) if granularity not in GRANULARITY.keys(): msg = _("'%s' granularity should be days, hours, minutes, " "or seconds") % granularity raise exceptions.InvalidInput(error_message=msg) age *= GRANULARITY[granularity] time_line = timeutils.utcnow() - datetime.timedelta(seconds=age) engine = get_engine(tacker_config) meta = sqlalchemy.MetaData() meta.bind = engine inspector = inspect(engine) assoc_map = _generate_associated_tables_map(inspector) if table_name == 'events': _purge_events_table(meta, engine, time_line) elif table_name == 'all': _purge_events_table(meta, engine, time_line) for t in ['vnf', 'vnfd', 'vims']: _purge_resource_tables(t, meta, engine, time_line, assoc_map) else: _purge_resource_tables(table_name, meta, engine, time_line, assoc_map)
def _validate_no_whitespace(data): """Validates that input has no whitespace.""" if len(data.split()) > 1: msg = _("'%s' contains whitespace") % data LOG.debug(msg) raise n_exc.InvalidInput(error_message=msg) return data
def _get_vnfd(self): self.attributes = self.vnf['vnfd']['attributes'].copy() self.vnfd_yaml = self.attributes.pop('vnfd', None) if self.vnfd_yaml is None: LOG.error("VNFD is not provided, so no vnf is created !!") raise exceptions.InvalidInput("VNFD template is None.") LOG.debug('vnfd_yaml %s', self.vnfd_yaml)
def convert_kvp_str_to_list(data): """Convert a value of the form 'key=value' to ['key', 'value']. :raises: n_exc.InvalidInput if any of the strings are malformed (e.g. do not contain a key). """ kvp = [x.strip() for x in data.split('=', 1)] if len(kvp) == 2 and kvp[0]: return kvp msg = _("'%s' is not of the form <key>=[value]") % data raise n_exc.InvalidInput(error_message=msg)
def convert_to_boolean(data): if isinstance(data, basestring): val = data.lower() if val == "true" or val == "1": return True if val == "false" or val == "0": return False elif isinstance(data, bool): return data elif isinstance(data, int): if data == 0: return False elif data == 1: return True msg = _("'%s' cannot be converted to boolean") % data raise n_exc.InvalidInput(error_message=msg)
def process_input(self): """Process input of vnfd template""" self.attributes = self.vnf['vnfd']['attributes'].copy() self.vnfd_yaml = self.attributes.pop('vnfd', None) if self.vnfd_yaml is None: LOG.error("VNFD is not provided, so no vnf is created !!") raise exceptions.InvalidInput("VNFD template is None.") LOG.debug('vnfd_yaml %s', self.vnfd_yaml) vnfd_dict = yamlparser.simple_ordered_parse(self.vnfd_yaml) LOG.debug('vnfd_dict %s', vnfd_dict) # Read parameter and process inputs if 'get_input' in str(vnfd_dict): self._process_parameterized_input(self.vnf['attributes'], vnfd_dict) return vnfd_dict
def convert_to_int(data): try: return int(data) except (ValueError, TypeError): msg = _("'%s' is not a integer") % data raise n_exc.InvalidInput(error_message=msg)