Beispiel #1
0
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()
Beispiel #2
0
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 errors.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()
Beispiel #3
0
def test_class_resolver():
    build_class_map_for(Food)
    build_class_map_for(Drink)

    assert concrete_class_for(Food, 'apple') is Apple
    assert concrete_class_for(Food, 'orange') is Orange
    assert concrete_class_for(Food, 'grape') is None
    assert concrete_class_for(Drink, 'apple') is None
    assert concrete_class_for(Drink, 'orange') is OrangeJuice
    assert concrete_class_for(Drink, 'grape') is GrapeJuice
Beispiel #4
0
def test_class_resolver():
    """Test class_resolver with our test classes, above."""
    build_class_map_for(Food)
    build_class_map_for(Drink)

    assert concrete_class_for(Food, 'apple') is Apple
    assert concrete_class_for(Food, 'orange') is Orange
    assert concrete_class_for(Food, 'grape') is None
    assert concrete_class_for(Drink, 'apple') is None
    assert concrete_class_for(Drink, 'orange') is OrangeJuice
    assert concrete_class_for(Drink, 'grape') is GrapeJuice
Beispiel #5
0
def switch_register(switch, type, **kwargs):
    """Register a new switch"""
    get_auth_backend().require_admin()
    absent_or_conflict(model.Switch, switch)

    cls = concrete_class_for(model.Switch, type)
    if cls is None:
        raise errors.BadArgumentError('%r is not a valid switch type.' % type)
    try:
        cls.validate(kwargs)
    except SchemaError:
        raise errors.BadArgumentError(
            'The arguments are not valid for this switch type')

    obj = cls(**kwargs)
    obj.label = switch
    obj.type = type

    db.session.add(obj)
    db.session.commit()
Beispiel #6
0
def switch_register(switch, type, **kwargs):
    """Register a new switch"""
    get_auth_backend().require_admin()
    absent_or_conflict(model.Switch, switch)

    cls = concrete_class_for(model.Switch, type)
    if cls is None:
        raise errors.BadArgumentError('%r is not a valid switch type.' % type)
    try:
        cls.validate(kwargs)
    except SchemaError:
        raise errors.BadArgumentError(
                        'The arguments are not valid for this switch type')

    obj = cls(**kwargs)
    obj.label = switch
    obj.type = type

    db.session.add(obj)
    db.session.commit()
Beispiel #7
0
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']))
    if 'metadata' in kwargs:
        for label, value in kwargs['metadata'].items():
            metadata_obj = model.Metadata(label, json.dumps(value), node_obj)
            db.session.add(metadata_obj)
    db.session.add(node_obj)
    db.session.commit()
Beispiel #8
0
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()
    absent_or_conflict(model.Node, node)
    obm_type = kwargs['obm']['type']
    cls = concrete_class_for(model.Obm, obm_type)
    if cls is None:
        raise errors.BadArgumentError('%r is not a valid OBM type.' % obm_type)
    cls.validate(kwargs['obm'])
    node_obj = model.Node(label=node, obm=cls(**kwargs['obm']))
    if 'metadata' in kwargs:
        for label, value in kwargs['metadata'].items():
            metadata_obj = model.Metadata(label, json.dumps(value), node_obj)
            db.session.add(metadata_obj)
    db.session.add(node_obj)
    db.session.commit()
Beispiel #9
0
def test_class_Switch():
    build_class_map_for(model.Switch)
    assert concrete_class_for(model.Switch, mockapi_name + "switches/mock") \
        is hil.ext.switches.mock.MockSwitch
Beispiel #10
0
def test_class_Obm():
    build_class_map_for(model.Obm)
    assert concrete_class_for(model.Obm, mockapi_name + "obm/mock") \
        is hil.ext.obm.mock.MockObm
Beispiel #11
0
def test_class_Switch():
    """Test class_resolver with MockSwitch"""
    build_class_map_for(model.Switch)
    assert concrete_class_for(model.Switch, mockapi_name + "switches/mock") \
        is hil.ext.switches.mock.MockSwitch
Beispiel #12
0
def test_class_Obm():
    """Test class_resolver with MockObm"""
    build_class_map_for(model.Obm)
    assert concrete_class_for(model.Obm, mockapi_name + "obm/mock") \
        is hil.ext.obm.mock.MockObm