def switch_register(switch, type, **kwargs): _assert_absent(model.Switch, switch) cls = concrete_class_for(model.Switch, type) if cls is None: raise BadArgumentError('%r is not a valid switch type.' % type) cls.validate(kwargs) obj = cls(**kwargs) obj.label = switch obj.type = type local.db.add(obj) local.db.commit()
def switch_register(switch, type, **kwargs): get_auth_backend().require_admin() _assert_absent(model.Switch, switch) cls = concrete_class_for(model.Switch, type) if cls is None: raise BadArgumentError('%r is not a valid switch type.' % type) cls.validate(kwargs) obj = cls(**kwargs) obj.label = switch obj.type = type db.session.add(obj) db.session.commit()
def node_register(node, **kwargs): """Create node. If the node already exists, a DuplicateError will be raised. The node is initially registered with no nics; see the method node_register_nic. """ get_auth_backend().require_admin() _assert_absent(model.Node, node) obm_type = kwargs['obm']['type'] cls = concrete_class_for(model.Obm, obm_type) if cls is None: raise BadArgumentError('%r is not a valid OBM type.' % obm_type) cls.validate(kwargs['obm']) node_obj = model.Node(label=node, obm=cls(**kwargs['obm'])) db.session.add(node_obj) db.session.commit()