-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsampleShelldriver.py
More file actions
66 lines (54 loc) · 2.71 KB
/
sampleShelldriver.py
File metadata and controls
66 lines (54 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from cloudshell.shell.core.driver_context import *
from cloudshell.shell.core.resource_driver_interface import ResourceDriverInterface
class SampleShellDriver (ResourceDriverInterface):
def __init__(self):
pass
# Initialize the driver session, this function is called everytime a new instance of the driver is created
# This is a good place to load and cache the driver configuration, initiate sessions etc.
def initialize(self, context):
"""
:type context: cloudshell.shell.core.driver_context.InitCommandContext
"""
return 'Finished initializing'
# Destroy the driver session, this function is called everytime a driver instance is destroyed
# This is a good place to close any open sessions, finish writing to log files
def cleanup(self):
pass
# An example command
def example_command(self, context, user_param1, user_param2):
"""
:type context: cloudshell.shell.core.driver_context.ResourceCommandContext
"""
result = self._helper_method(user_param1)
return result
# An example command that that supports cancellation
def example_command_with_cancellation(self, context, cancellation_token, user_param1):
"""
:type context: cloudshell.shell.core.driver_context.ResourceCommandContext
:type cancellation_token: cloudshell.shell.core.driver_context.CancellationContext
"""
result = self._helper_method(user_param1)
return result
# private functions are always hidden
def _helper_method(self,title):
return "---====%s====---" % title
def get_inventory(self, context):
"""
:type context: cloudshell.shell.core.driver_context.AutoLoadCommandContext
"""
# example autoload return results
resources = [AutoLoadResource('Generic Chassis', 'Chassis 1', '1'),
AutoLoadResource('Generic Module', 'Module 1', '1/1'),
AutoLoadResource('Generic Port', 'Port 1', '1/1/1')]
attributes = [
AutoLoadAttribute('', 'Location', 'Santa Clara Lab'),
AutoLoadAttribute('', 'Model', 'Catalyst 3850'),
AutoLoadAttribute('', 'Vendor', 'Cisco'),
AutoLoadAttribute('1', 'Serial Number', 'JAE053002JD'),
AutoLoadAttribute('1', 'Model', 'WS-X4232-GB-RJ'),
AutoLoadAttribute('1/1', 'Model', 'WS-X4233-GB-EJ'),
AutoLoadAttribute('1/1', 'Serial Number', 'RVE056702UD'),
AutoLoadAttribute('1/1/1', 'IPv4 Address', '192.168.10.7')
]
result = AutoLoadDetails(resources, attributes)
return result