def test_sanitize_name(self): self.assertEqual( 'z23tosoitfutobxn4hrqzgjjwp6v3wjgcy4ddqx3rpkb43x3ceta', internal_utils.sanitize_name('test')) self.assertEqual( 'xz4j2rrayb4ebrjdzc4rmrudirw6sp7bggcpjrihdav4zrw3mtnq', internal_utils.sanitize_name('test', 'a', 'b', 'c')) self.assertEqual( 'esy7rw6xsfko2pbtocshyccpkcni7rrsngh7wehjskc66pgh2gha', internal_utils.sanitize_name('test', '0', '1', '9')) self.assertEqual( 'ksult6xm2m6vu47vcmwfvsly27x7ai4whduys5mruzcn5qogs6pq', internal_utils.sanitize_name('test', 'AA', 'BB', 'ZZ')) self.assertEqual( 'vvxojw5rwlmq6abg3trx6nchbffez4lxfhalgidxlyhtlh3r4jwq', internal_utils.sanitize_name('test', 'a -', '-', '_'))
def build_selectors(self, aim_klass, filters): result = 'aim_type=%s' % utils.camel_to_snake(aim_klass.__name__) for fltr in filters: if fltr in aim_klass.identity_attributes: result += ',%s=%s' % (fltr, utils.sanitize_name(filters[fltr])) selectors = self._get_aim_id_selector(filters) selectors['label_selector'] = result return selectors
def build_selectors(self, aim_klass, filters): result = 'aim_type=%s' % utils.camel_to_snake(aim_klass.__name__) for fltr in filters: if fltr in aim_klass.identity_attributes: result += ',%s=%s' % ( fltr, utils.sanitize_name(filters[fltr])) selectors = self._get_aim_id_selector(filters) selectors['label_selector'] = result return selectors
def from_attr(self, resource_klass, attribute_dict): name = utils.camel_to_snake(resource_klass.__name__) self.setdefault('spec', {'type': name, name: {}}) self.setdefault('metadata', {'labels': {'aim_type': name}}) labels = self['metadata']['labels'] attrs = self['spec'][name] for k, v in attribute_dict.iteritems(): if k in resource_klass.identity_attributes: labels[k] = utils.sanitize_name(v) attrs[k] = v if 'name' not in self['metadata']: self['metadata']['name'] = self._build_name(name, resource_klass)
def from_attr(self, resource_klass, attribute_dict): name = utils.camel_to_snake(resource_klass.__name__) self.setdefault('spec', {'type': name, name: {}}) self.setdefault('metadata', {'labels': {'aim_type': name}}) labels = self['metadata']['labels'] attrs = self['spec'][name] for k, v in attribute_dict.iitems(): if k in resource_klass.identity_attributes: labels[k] = utils.sanitize_name(v) attrs[k] = v if 'name' not in self['metadata']: self['metadata']['name'] = self._build_name(name, resource_klass)
def _build_name(self, type, resource_klass): components = [] for attr in sorted(resource_klass.identity_attributes): components.append(self['spec'][type][attr]) return utils.sanitize_name(type, *components)