forked from CiscoUcs/imcsdk
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rahul Gupta <ragupta4@cisco.com>
- Loading branch information
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,91 @@ | ||
# Copyright 2016 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 implements all the sol related config | ||
""" | ||
|
||
from imcsdk.imcexception import ImcOperationError | ||
from imcsdk.imccoreutils import get_server_dn | ||
from imcsdk.mometa.sol.SolIf import SolIfConsts | ||
|
||
|
||
def sol_get(handle, server_id=1, caller="sol_get"): | ||
parent_dn = get_server_dn(handle, server_id) | ||
dn = parent_dn + "/sol-if" | ||
mo = handle.query_dn(dn) | ||
if mo is None: | ||
raise ImcOperationError(caller, | ||
"SOL '%s' doesn't exist." % dn) | ||
return mo | ||
|
||
|
||
def sol_enable(handle, speed=None, comport=None, ssh_port=None, server_id=1, | ||
**kwargs): | ||
""" | ||
This method will setup serial over lan connection | ||
Args: | ||
handle (ImcHandle) | ||
speed (string): "9600", "19200", "38400", "57600", "115200" | ||
comport (string): "com0", "com1" | ||
ssh_port (int): port for ssh | ||
server_id (int): Server Id to be specified for C3260 platforms | ||
Returns: | ||
SolIf object | ||
""" | ||
|
||
mo = sol_get(handle, server_id=server_id, caller="sol_enable") | ||
params = { | ||
"admin_state": SolIfConsts.ADMIN_STATE_ENABLE, | ||
"speed": str(speed), | ||
"comport": comport, | ||
"ssh_port": str(ssh_port), | ||
} | ||
|
||
mo.set_prop_multiple(**kwargs) | ||
mo.set_prop_multiple(**params) | ||
handle.set_mo(mo) | ||
return mo | ||
|
||
|
||
def sol_exists(handle, server_id=1, **kwargs): | ||
try: | ||
mo = sol_get(handle, server_id=server_id, caller="sol_enable") | ||
except ImcOperationError: | ||
return (False, None) | ||
|
||
kwargs['admin_state'] = SolIfConsts.ADMIN_STATE_ENABLE | ||
|
||
mo_exists = mo.check_prop_match(**kwargs) | ||
return (mo_exists, mo if mo_exists else None) | ||
|
||
|
||
def sol_disable(handle, server_id=1): | ||
""" | ||
This method will disable Serial over Lan connection | ||
Args: | ||
handle (ImcHandle) | ||
server_id (int): Server Id to be specified for C3260 platforms | ||
Returns: | ||
None | ||
""" | ||
|
||
mo = sol_get(handle, server_id=server_id, caller="sol_enable") | ||
mo.admin_state = SolIfConsts.ADMIN_STATE_DISABLE | ||
handle.set_mo(mo) | ||
return mo |