Skip to content
Open

vlan #54

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/system_test/network/test_vlan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2017 Cisco Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime
from nose.tools import *
from ..connection.info import custom_setup, custom_teardown
from ucsmsdk.ucshandle import UcsHandle
from ucsm_apis.network.vlan import *

handle = None
vlan = "vlan" + datetime.date.today().strftime('%Y%b%d')

def setup_module():
global handle
handle = custom_setup()
# handle.set_dump_xml()


def teardown_module():
custom_teardown(handle)


def test_vlan_create():
vlan_create(handle, name=vlan, id="4000", sharing="none", mcast_policy_name="", policy_owner="local",
default_net="no", compression_type="included")
124 changes: 124 additions & 0 deletions ucsm_apis/network/vlan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Copyright 2017 Cisco Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
This module performs the operation related to user.
"""
from ucsmsdk.ucsexception import UcsOperationError
_base_dn = "fabric/lan"


def vlan_create(handle, name, id, sharing=None, mcast_policy_name=None, policy_owner=None,
default_net=None, compression_type=None, **kwargs):
"""
creates vlan
Args:
handle (UcsHandle)
name (string): VLAN name
sharing (string): sharing, valid values "community", "isolated", "none", "primary"
mcast_policy_name (string):
policy_owner (string): "local", "pending-policy", "policy"
default_net (string): "false", "no", "true", "yes"
compression_type (string): "excluded", "included"
**kwargs: Any additional key-value pair of managed object(MO)'s
property and value, which are not part of regular args.
This should be used for future version compatibility.
Returns:
FabricVlan: managed object
Raises:
None
Example:
vlan_create(handle, name="test", id=2, sharing="none", mcast_policy_name="", policy_owner="local",
default_net="no", compression_type="included")
"""
from ucsmsdk.mometa.fabric.FabricVlan import FabricVlan
vlan = FabricVlan(parent_mo_or_dn=_base_dn, name=name, sharing=sharing, id=id,
Copy link
Copy Markdown
Member

@vvb vvb Jul 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ReignInChaos this is perfect for global vlan, we need to see how to use the same APIs for other vlans. May be we could provide the base_dn in vlan_create and default it to fabric/lan. that way, fabric specific vlans would also just work by providing a different base_dn argument value. This would need similar changes in vlan_get etc..

WDYT?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great insight! That didn't even occur to me. I'll make updates accordingly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is a good reference for the base_dn values? Paramerterizing base_dn is an option but I think abstracting that from the user of API would be more beneficial.

mcast_policy_name=mcast_policy_name,
policy_owner=policy_owner, default_net=default_net, compression_type=compression_type)

vlan.set_prop_multiple(**kwargs)
handle.add_mo(vlan, modify_present=True)
handle.commit()
return vlan

def vlan_get(handle, name, caller="vlan_get"):
"""
gets user

Args:
handle (UcsHandle)
name (string): vlan name

Returns:
FabricVlan: managed object

Raises:
UcsOperationError: if FabricVlan is not present

Example:
vlan_get(handle, name="test")
"""
dn = _base_dn + "/net-" + name
mo = handle.query_dn(dn)
if mo is None:
raise UcsOperationError(caller, "VLAN '%s' does not exist" % dn)
return mo

def vlan_delete(handle, name):
"""
deletes vlan

Args:
handle (UcsHandle)
name (string): vlan name

Returns:
None

Raises:
UcsOperationError: if FabricVlan is not present

Example:
user_delete(handle, name="test")

"""
mo = vlan_get(handle, name, "vlan_delete")
handle.remove_mo(mo)
handle.commit()

def vlan_modify(handle, name, **kwargs):
"""
modifies vlan

Args:
handle (UcsHandle)
name (string): vlan name
**kwargs: key-value pair of managed object(MO) property and value, Use
'print(ucscoreutils.get_meta_info(<classid>).config_props)'
to get all configurable properties of class

Returns:
FabricVlan: managed object

Raises:
UcsOperationError: if AaaUser is not present

Example:
vlan_modify(handle, name="test", id=2, sharing="none", mcast_policy_name="", policy_owner="local",
default_net="no", compression_type="included")
"""
mo = vlan_get(handle, name, "vlan_modify")
mo.set_prop_multiple(**kwargs)
handle.set_mo(mo)
handle.commit()
return mo