-
Notifications
You must be signed in to change notification settings - Fork 12
vlan #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ReignInChaos
wants to merge
1
commit into
CiscoUcs:master
Choose a base branch
from
ReignInChaos:global_vlan
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
vlan #54
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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_dnin vlan_create and default it tofabric/lan. that way, fabric specific vlans would also just work by providing a differentbase_dnargument value. This would need similar changes invlan_getetc..WDYT?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.