def valid_structure_3(self, images): schema = { 'image': { 'file': ListOf(str) }, Optional('packages'): { 'file': ListOf(str) }, Optional('other'): { 'file': ListOf(str) } } try: Schema(schema).validate(images) except Exception: return False if len(images['image']['file']) != 1: return False else: setattr(self, 'image', images['image']['file']) if 'packages' in images: setattr(self, 'packages', images['packages']['file']) setattr(self, 'other', images.get('other', {}).get('file', [])) return True
def valid_structure_2(self, images): schema = { Optional('controller'): ListOf(str), Optional('switch'): ListOf(str) } try: Schema(schema).validate(images) except Exception: return False if ('controller' in images and 'switch' in images and len(images['controller']) == 1 and len(images['switch']) == 1): setattr(self, 'controller', images['controller']) setattr(self, 'switch', images['switch']) return True elif ('controller' in images and len(images['controller']) == 1): setattr(self, 'controller', images['controller']) return True elif ('switch' in images and len(images['switch']) == 1): setattr(self, 'switch', images['switch']) return True else: return False
def validate(self, data, top=False): sub_schema = self.schema \ if isinstance(self.schema, Schema) \ else Schema(self.schema) if not isinstance(data, Sequence): raise SchemaError('Not a sequence: %r' % (data, )) return [sub_schema.validate(e, top=top) for e in data]
def valid_structure_3(self, images): schema = { 'kickstart': { 'file': ListOf(str) }, 'system': { 'file': ListOf(str) }, Optional('other'): { 'file': ListOf(str) } } try: Schema(schema).validate(images) except Exception: return False if len(images['kickstart']['file']) == 1 and len( images['system']['file']) == 1: setattr(self, 'kickstart', images['kickstart']['file']) setattr(self, 'system', images['system']['file']) setattr(self, 'other', images.get('other', {}).get('file', [])) return True else: return False
def valid_structure_1(self, images): schema = ListOf(str) try: Schema(schema).validate(images) except Exception: return False if len(images) == 1: setattr(self, 'switch', images) return True else: return False
def valid_structure_3(self, images): schema = {'system': {'file': ListOf(str)}} try: Schema(schema).validate(images) except Exception: return False if len(images['system']['file']) == 1: setattr(self, 'system', images['system']['file']) return True else: return False
def valid_structure_1(self, images): schema = ListOf(str) try: Schema(schema).validate(images) except Exception: return False if len(images) == 2: setattr(self, 'kickstart', images[:1]) setattr(self, 'system', images[1:]) return True else: return False
def valid_structure_3(self, images): schema = {'switch': {'file': ListOf(str)}} try: Schema(schema).validate(images) except Exception: return False if ('switch' in images and len(images['switch']['file']) == 1): setattr(self, 'switch', images['switch']['file']) return True else: return False
def valid_structure_1(self, images): schema = ListOf(str) try: Schema(schema).validate(images) except Exception: return False if not images: return False else: setattr(self, 'system', images[0:1]) setattr(self, 'other', images[1:]) return True
def valid_structure_2(self, images): schema = {'system': ListOf(str), Optional('other'): ListOf(str)} try: Schema(schema).validate(images) except Exception: return False if len(images['system']) == 1: setattr(self, 'system', images['system']) setattr(self, 'other', images.get('other', [])) return True else: return False
def valid_structure_2(self, images): schema = {'kickstart': ListOf(str), 'system': ListOf(str)} try: Schema(schema).validate(images) except Exception: return False if len(images['kickstart']) == 1 and len(images['system']) == 1: setattr(self, 'kickstart', images['kickstart']) setattr(self, 'system', images['system']) return True else: return False
def valid_structure_1(self, images): schema = ListOf(str) try: Schema(schema).validate(images) except Exception: return False if len(images) < 2: return False else: setattr(self, 'kickstart', [images[0]]) setattr(self, 'system', [images[1]]) setattr(self, 'other', images[2:]) return True
def valid_structure_1(self, images): schema = ListOf(str) try: Schema(schema).validate(images) except Exception: return False if len(images) == 1: setattr(self, 'image', images) return True if len(images) >= 2: setattr(self, 'image', images[:1]) setattr(self, 'packages', images[1:]) return True else: return False
def valid_structure_2(self, images): schema = {'image': ListOf(str), Optional('packages'): ListOf(str)} try: Schema(schema).validate(images) except Exception: return False if len(images['image']) != 1: return False else: setattr(self, 'image', images['image']) if 'packages' in images: setattr(self, 'packages', images['packages']) return True
def valid_structure_1(self, images): schema = ListOf(str) try: Schema(schema).validate(images) except Exception: return False if len(images) == 1: # This is not a bug. It is optional to clean only switches or only # controllers but we do not know what type of image the user # provided if they only provide 1. setattr(self, 'controller', images) setattr(self, 'switch', images) return True if len(images) == 2: setattr(self, 'controller', images[:1]) setattr(self, 'switch', images[1:]) return True else: return False
def valid_structure_3(self, images): schema = { Optional('controller'): { 'file': ListOf(str) }, Optional('switch'): { 'file': ListOf(str) }, Optional('other'): { 'file': ListOf(str) } } try: Schema(schema).validate(images) except Exception: return False if ('controller' in images and 'switch' in images and len(images['controller']['file']) == 1 and len(images['switch']['file']) == 1): setattr(self, 'controller', images['controller']['file']) setattr(self, 'switch', images['switch']['file']) setattr(self, 'other', images.get('other', {}).get('file', [])) return True elif ('controller' in images and len(images['controller']['file']) == 1): setattr(self, 'controller', images['controller']['file']) setattr(self, 'other', images.get('other', {}).get('file', [])) return True elif ('switch' in images and len(images['switch']['file']) == 1): setattr(self, 'switch', images['switch']['file']) setattr(self, 'other', images.get('other', {}).get('file', [])) return True else: return False