class VirtualCompute(Schema): """Attributes for the VirtualCompute information element.""" computeId = fields.Str( required=True, description='Identifier of the virtualised compute resource.') computeName = fields.Str( required=True, description='Name of the virtualised compute resource.') flavourId = fields.Str( required=True, description='Identifier of the given compute flavour used to ' 'instantiate this virtual compute.') accelerationCapability = fields.List( fields.String(), required=True, description='Selected acceleration capabilities (e.g. crypto, GPU) ' 'from the set of capabilities offered by the compute node ' 'acceleration resources. The cardinality can be 0, if no ' 'particular acceleration capability is provided.') virtualCpu = fields.Nested( VirtualCpu, required=True, description='The virtual CPU(s) of the virtualised compute.') virtualMemory = fields.Nested( VirtualMemory, required=True, description='The virtual memory of the compute.') virtualNetworkInterface = fields.Nested( VirtualNetworkInterface, required=True, many=True, description='Element with information of the instantiated virtual ' 'network interfaces of the compute resource.') virtualDisks = fields.Str( VirtualStorage, required=True, many=True, description='Element with information of the virtualised storage ' 'resources (volumes, ephemeral that are attached to the ' 'compute resource.)') vcImageId = fields.Str( required=True, description='Identifier of the virtualisation container software ' 'image (e.g. virtual machine image). Cardinality can be 0 ' 'if an "empty" virtualisation container is allocated.') zoneId = fields.Str( required=True, description='If present, it identifies the Resource Zone where the ' 'virtual compute resources have been allocated.') hostId = fields.Str( required=True, description='Identifier of the host the virtualised compute resource ' 'is allocated on.') operationalState = fields.Str( required=True, description='Operational state of the compute resource.')
class Body(Schema): color = fields.List(fields.String(), required=True, validate=Length(max=5), example=["white", "blue", "red"]) def swag_validation_function(self, data, main_def): self.load(data) def swag_validation_error_handler(self, err, data, main_def): abort(400, err)
class AffinityOrAntiAffinityResourceList(Schema): """AffinityOrAntiAffinityResourceList. The AffinityOrAntiAffinityResourceList information element defines an explicit list of resources to express affinity or anti-affinity between these resources and a current resource. The scope of the affinity or anti-affinity can also be defined. """ resource = fields.List( fields.Str(), required=True, description='List of identifiers of virtualised resources.')
class GrapheSchema(Schema): """ A graphe is composed of nodes and edges """ end_points = fields.List(fields.Str(), required=True, description="End points of the graphe") hotpoints = fields.List(fields.Str(), required=True, description="The hotpoint of the graphe") nodes = fields.Nested(NodeSchema, many=True, required=True) edges = fields.Nested(EdgeSchema, many=True, required=True) @post_load def make_graphe(self, data): graphe = Graphe("GrapheFromApiRest") graphe.endpoints = data["end_points"] graphe.hotpoints = data["hotpoints"] graphe.nodes = {d.name: d for d in data["nodes"]} graphe.edges = { Edge._compute_name(d.source, d.dest): d for d in data["edges"] } for node_name, node in graphe.nodes.items(): for name, edge in graphe.edges.items(): if node_name == edge.source or node_name == edge.dest: node.edges.append(edge) return graphe @pre_dump def graphe_helper(self, data): return DummyGraphe([d for d in data.nodes.values()], [e for e in data.edges.values()], data.end_points, data.hotpoints)
class KellyCriterionRequest(Schema): # type: ignore start_date = fields.Str(description='Start date of the sampling period', example='2018-1-1', default='', required=True, validate=_validate_date) end_date = fields.Str(description='End date of the sampling period', example='2018-12-31', default='', required=True, validate=_validate_date) securities = fields.List( description='List of securities (stock symbols) to calculate ' 'the leverage using the given sampling period.', example=['IBM', 'AAPL'], default=[], cls_or_instance=fields.Str()) risk_free_rate = fields.Float(description='Risk free rate', example=0.04, default=0.04)
class User(Schema): username = fields.Str(required=True) age = fields.Int(required=True, min=18) tags = fields.List(fields.Str())
class User(Schema): username = fields.Str(required=True, default="Sirius Black") # wrong default "180" to force validation error age = fields.Int(required=True, min=18, default="180") tags = fields.List(fields.Str(), default=["wizard", "hogwarts", "dead"])