mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-10-31 02:38:03 +00:00 
			
		
		
		
	rename lanforge-resource to lanforge_resource
This commit is contained in:
		
							
								
								
									
										60
									
								
								Quali/lanforge_resource/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								Quali/lanforge_resource/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | ||||
| # Byte-compiled / optimized / DLL files | ||||
| __pycache__/ | ||||
| *.py[cod] | ||||
| *$py.class | ||||
|  | ||||
| # C extensions | ||||
| *.so | ||||
|  | ||||
| # Distribution / packaging | ||||
| .Python | ||||
| env/ | ||||
| build/ | ||||
| develop-eggs/ | ||||
| dist/ | ||||
| downloads/ | ||||
| eggs/ | ||||
| .eggs/ | ||||
| lib/ | ||||
| lib64/ | ||||
| parts/ | ||||
| sdist/ | ||||
| var/ | ||||
| *.egg-info/ | ||||
| .installed.cfg | ||||
| *.egg | ||||
|  | ||||
| # PyInstaller | ||||
| #  Usually these files are written by a python script from a template | ||||
| #  before PyInstaller builds the exe, so as to inject date/other infos into it. | ||||
| *.manifest | ||||
| *.spec | ||||
|  | ||||
| # Installer logs | ||||
| pip-log.txt | ||||
| pip-delete-this-directory.txt | ||||
|  | ||||
| # Unit test / coverage reports | ||||
| htmlcov/ | ||||
| .tox/ | ||||
| .coverage | ||||
| .coverage.* | ||||
| .cache | ||||
| nosetests.xml | ||||
| coverage.xml | ||||
| *,cover | ||||
| .hypothesis/ | ||||
|  | ||||
| # Translations | ||||
| *.mo | ||||
| *.pot | ||||
|  | ||||
| # Django stuff: | ||||
| *.log | ||||
|  | ||||
| # Sphinx documentation | ||||
| docs/_build/ | ||||
|  | ||||
| # PyBuilder | ||||
| target/ | ||||
| cloudshell_config.yml | ||||
							
								
								
									
										4
									
								
								Quali/lanforge_resource/TOSCA-Metadata/TOSCA.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								Quali/lanforge_resource/TOSCA-Metadata/TOSCA.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| TOSCA-Meta-File-Version: 1.0 | ||||
| CSAR-Version: 0.1.0 | ||||
| Created-By: Anonymous | ||||
| Entry-Definitions: shell-definition.yaml | ||||
							
								
								
									
										
											BIN
										
									
								
								Quali/lanforge_resource/canvil2-64x64-gray-yel-ico.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Quali/lanforge_resource/canvil2-64x64-gray-yel-ico.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 2.3 KiB | 
							
								
								
									
										53
									
								
								Quali/lanforge_resource/deployment.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								Quali/lanforge_resource/deployment.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | ||||
| <?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||||
| <properties> | ||||
|  | ||||
|     <!-- The address of the Quali server on which to deploy, mandatory --> | ||||
|     <serverRootAddress>localhost</serverRootAddress> | ||||
|  | ||||
|     <!-- The port of the Quali server on which to deploy, defaults to "8029" --> | ||||
|     <port>8029</port> | ||||
|  | ||||
|     <!-- The server admin username, password and domain to use when deploying --> | ||||
|     <username>YOUR_USERNAME</username> | ||||
|     <password>YOUR_PASSWORD</password> | ||||
|     <domain>Global</domain> | ||||
|  | ||||
|     <!-- Simple patterns to filter when sending the driver to the server separated by semicolons (e.g. "file.xml;logs/", also supports regular expressions), | ||||
|  on top of the patterns specified here the plugin will automatically filter the "deployment/" and ".idea/" folders and the "deployment.xml" file --> | ||||
|     <fileFilters>dont_upload_me.xml</fileFilters> | ||||
|  | ||||
|     <!-- The drivers to update, holds one or more drivers --> | ||||
|     <drivers> | ||||
|        <!-- runFromLocalProject - Decides whether to run the driver from the current project directory for debugging purposes, defaults to "false" --> | ||||
|        <!-- waitForDebugger - When `runFromLocalProject` is enabled, decides whether to wait for a debugger to attach before running any Python driver code, defaults to "false" --> | ||||
|        <!-- sourceRootFolder - The folder to refer to as the project source root (if specified, the folder will be zipped and deployed instead of the whole project), defaults to the root project folder --> | ||||
|         <driver runFromLocalProject="true" waitForDebugger="true" sourceRootFolder="lanforge-resource"> | ||||
|             <!-- A list of paths to the driver's files or folders relative to the project's root. | ||||
|  may be a path to a directory, in which case all the files and folders under the directory are added into the driver's zip file. | ||||
|  if the <sources> element is not specified, all the files under the project are added to the driver's zip file --> | ||||
|             <sources> | ||||
|                  <source>src</source> | ||||
|             </sources> | ||||
|             <!-- the driver name of the driver to update --> | ||||
|             <targetName>LanforgeResourceDriver</targetName> | ||||
|         </driver> | ||||
|     </drivers> | ||||
|  | ||||
|     <!-- The scripts to update, holds one or more scripts --> | ||||
|     <!-- A list of paths to the script's files or folders relative to the project's root. | ||||
|  if the <sources> element is not specified, all the files under the project are added to the script's zip file. | ||||
|  if only one file is specified, the file will not be compressed into a zip file. | ||||
|  --> | ||||
|     <!-- | ||||
|     <scripts> | ||||
|  | ||||
|         <script> | ||||
|  | ||||
|             <sources> | ||||
|                 <source>script1.py</source> | ||||
|             </sources> | ||||
|             <targetName>scriptToUpdate</targetName> | ||||
|         </script> | ||||
|     </scripts> | ||||
|         --> | ||||
| </properties> | ||||
							
								
								
									
										3
									
								
								Quali/lanforge_resource/docs/readme.rst
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								Quali/lanforge_resource/docs/readme.rst
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| .. _readme: | ||||
|  | ||||
| .. include:: ../README.rst | ||||
							
								
								
									
										45
									
								
								Quali/lanforge_resource/shell-definition.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								Quali/lanforge_resource/shell-definition.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| tosca_definitions_version: tosca_simple_yaml_1_0 | ||||
|  | ||||
| metadata: | ||||
|   template_name: Lanforge Resource | ||||
|   template_author: Anonymous | ||||
|   template_version: 0.1.0 | ||||
|   template_icon: shell-icon.png | ||||
|  | ||||
| description: > | ||||
|   TOSCA based resource shell | ||||
|  | ||||
| imports: | ||||
|   - cloudshell_standard: cloudshell_resource_standard_2_0_3.yaml | ||||
|  | ||||
| node_types: | ||||
|  | ||||
|   vendor.resource.Lanforge Resource: | ||||
|     derived_from: cloudshell.nodes.GenericResource | ||||
|     #properties: | ||||
|     #  my_property: | ||||
|     #    type: string          # optional values: string, integer, float, boolean, cloudshell.datatypes.Password | ||||
|     #    default: fast | ||||
|     #    description: Some attribute description | ||||
|     #    constraints: | ||||
|     #      - valid_values: [fast, slow] | ||||
|     capabilities: | ||||
|       auto_discovery_capability: | ||||
|         type: cloudshell.capabilities.AutoDiscovery | ||||
|         properties:         | ||||
|           enable_auto_discovery: | ||||
|             type: boolean | ||||
|             default: true | ||||
|           auto_discovery_description: | ||||
|             type: string | ||||
|             default: Describe the auto discovery | ||||
|           inventory_description: | ||||
|             type: string | ||||
|             default: Describe the resource shell template | ||||
|     artifacts: | ||||
|       icon: | ||||
|         file: canvil2-64x64-gray-yel-ico.png | ||||
|         type: tosca.artifacts.File | ||||
|       driver: | ||||
|         file: LanforgeResourceDriver.zip | ||||
|         type: tosca.artifacts.File | ||||
							
								
								
									
										
											BIN
										
									
								
								Quali/lanforge_resource/shell-icon.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Quali/lanforge_resource/shell-icon.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 461 B | 
							
								
								
									
										1029
									
								
								Quali/lanforge_resource/src/data_model.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1029
									
								
								Quali/lanforge_resource/src/data_model.py
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										309
									
								
								Quali/lanforge_resource/src/driver.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										309
									
								
								Quali/lanforge_resource/src/driver.py
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,309 @@ | ||||
| from cloudshell.shell.core.resource_driver_interface import ResourceDriverInterface | ||||
| from cloudshell.shell.core.driver_context import InitCommandContext, ResourceCommandContext, AutoLoadResource, \ | ||||
|     AutoLoadAttribute, AutoLoadDetails, CancellationContext | ||||
| from cloudshell.shell.core.session.cloudshell_session import CloudShellSessionContext | ||||
| import mock | ||||
| from data_model import * | ||||
| # run 'shellfoundry generate' to generate data model classes | ||||
| import subprocess | ||||
| import sys | ||||
| import os | ||||
| import importlib | ||||
| import paramiko | ||||
|  | ||||
| # command = "./lanforge-scripts/py-scripts/update_dependencies.py" | ||||
| # print("running:[{}]".format(command)) | ||||
| # process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) | ||||
| # outs, errs = process.communicate() | ||||
| # print(outs) | ||||
| # print(errs) | ||||
|  | ||||
| # if 'lanforge-scripts' not in sys.path: | ||||
| #     sys.path.append('./lanforge-scripts') | ||||
|  | ||||
| # create_wanlink = importlib.import_module("lanforge-scripts.py-json.create_wanlink") | ||||
| # create_l3 = importlib.import_module("lanforge-scripts.py-scripts.create_l3") | ||||
| # CreateL3 = create_l3.CreateL3 | ||||
| class LanforgeResourceDriver (ResourceDriverInterface): | ||||
|  | ||||
|     def __init__(self): | ||||
|         """ | ||||
|         ctor must be without arguments, it is created with reflection at run time | ||||
|         """ | ||||
|         pass | ||||
|  | ||||
|     def initialize(self, context): | ||||
|         """ | ||||
|         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. | ||||
|         :param InitCommandContext context: the context the command runs on | ||||
|         """ | ||||
|         pass | ||||
|  | ||||
|     def cleanup(self): | ||||
|         """ | ||||
|         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 | ||||
|         """ | ||||
|         pass | ||||
|  | ||||
|     def get_inventory(self, context): | ||||
|         """ | ||||
|         Discovers the resource structure and attributes. | ||||
|         :param AutoLoadCommandContext context: the context the command runs on | ||||
|         :return Attribute and sub-resource information for the Shell resource you can return an AutoLoadDetails object | ||||
|         :rtype: AutoLoadDetails | ||||
|         """ | ||||
|         # See below some example code demonstrating how to return the resource structure and attributes | ||||
|         # In real life, this code will be preceded by SNMP/other calls to the resource details and will not be static | ||||
|         # run 'shellfoundry generate' in order to create classes that represent your data model | ||||
|  | ||||
|         ''' | ||||
|         resource = LanforgeResource.create_from_context(context) | ||||
|         resource.vendor = 'specify the shell vendor' | ||||
|         resource.model = 'specify the shell model' | ||||
|  | ||||
|         port1 = ResourcePort('Port 1') | ||||
|         port1.ipv4_address = '192.168.10.7' | ||||
|         resource.add_sub_resource('1', port1) | ||||
|  | ||||
|         return resource.create_autoload_details() | ||||
|         ''' | ||||
|         return AutoLoadDetails([], []) | ||||
|  | ||||
|     def orchestration_save(self, context, cancellation_context, mode, custom_params): | ||||
|         """ | ||||
|         Saves the Shell state and returns a description of the saved artifacts and information | ||||
|         This command is intended for API use only by sandbox orchestration scripts to implement | ||||
|         a save and restore workflow | ||||
|         :param ResourceCommandContext context: the context object containing resource and reservation info | ||||
|         :param CancellationContext cancellation_context: Object to signal a request for cancellation. Must be enabled in drivermetadata.xml as well | ||||
|         :param str mode: Snapshot save mode, can be one of two values 'shallow' (default) or 'deep' | ||||
|         :param str custom_params: Set of custom parameters for the save operation | ||||
|         :return: SavedResults serialized as JSON | ||||
|         :rtype: OrchestrationSaveResult | ||||
|         """ | ||||
|  | ||||
|         # See below an example implementation, here we use jsonpickle for serialization, | ||||
|         # to use this sample, you'll need to add jsonpickle to your requirements.txt file | ||||
|         # The JSON schema is defined at: | ||||
|         # https://github.com/QualiSystems/sandbox_orchestration_standard/blob/master/save%20%26%20restore/saved_artifact_info.schema.json | ||||
|         # You can find more information and examples examples in the spec document at | ||||
|         # https://github.com/QualiSystems/sandbox_orchestration_standard/blob/master/save%20%26%20restore/save%20%26%20restore%20standard.md | ||||
|         ''' | ||||
|             # By convention, all dates should be UTC | ||||
|             created_date = datetime.datetime.utcnow() | ||||
|  | ||||
|             # This can be any unique identifier which can later be used to retrieve the artifact | ||||
|             # such as filepath etc. | ||||
|  | ||||
|             # By convention, all dates should be UTC | ||||
|             created_date = datetime.datetime.utcnow() | ||||
|  | ||||
|             # This can be any unique identifier which can later be used to retrieve the artifact | ||||
|             # such as filepath etc. | ||||
|             identifier = created_date.strftime('%y_%m_%d %H_%M_%S_%f') | ||||
|  | ||||
|             orchestration_saved_artifact = OrchestrationSavedArtifact('REPLACE_WITH_ARTIFACT_TYPE', identifier) | ||||
|  | ||||
|             saved_artifacts_info = OrchestrationSavedArtifactInfo( | ||||
|                 resource_name="some_resource", | ||||
|                 created_date=created_date, | ||||
|                 restore_rules=OrchestrationRestoreRules(requires_same_resource=True), | ||||
|                 saved_artifact=orchestration_saved_artifact) | ||||
|  | ||||
|             return OrchestrationSaveResult(saved_artifacts_info) | ||||
|       ''' | ||||
|         pass | ||||
|  | ||||
|     def orchestration_restore(self, context, cancellation_context, saved_artifact_info, custom_params): | ||||
|         """ | ||||
|         Restores a saved artifact previously saved by this Shell driver using the orchestration_save function | ||||
|         :param ResourceCommandContext context: The context object for the command with resource and reservation info | ||||
|         :param CancellationContext cancellation_context: Object to signal a request for cancellation. Must be enabled in drivermetadata.xml as well | ||||
|         :param str saved_artifact_info: A JSON string representing the state to restore including saved artifacts and info | ||||
|         :param str custom_params: Set of custom parameters for the restore operation | ||||
|         :return: None | ||||
|         """ | ||||
|         ''' | ||||
|         # The saved_details JSON will be defined according to the JSON Schema and is the same object returned via the | ||||
|         # orchestration save function. | ||||
|         # Example input: | ||||
|         # { | ||||
|         #     "saved_artifact": { | ||||
|         #      "artifact_type": "REPLACE_WITH_ARTIFACT_TYPE", | ||||
|         #      "identifier": "16_08_09 11_21_35_657000" | ||||
|         #     }, | ||||
|         #     "resource_name": "some_resource", | ||||
|         #     "restore_rules": { | ||||
|         #      "requires_same_resource": true | ||||
|         #     }, | ||||
|         #     "created_date": "2016-08-09T11:21:35.657000" | ||||
|         #    } | ||||
|  | ||||
|         # The example code below just parses and prints the saved artifact identifier | ||||
|         saved_details_object = json.loads(saved_details) | ||||
|         return saved_details_object[u'saved_artifact'][u'identifier'] | ||||
|         ''' | ||||
|         pass | ||||
|  | ||||
|     def example_command(self, context): | ||||
|         """ | ||||
|         this is my example command | ||||
|         :param ResourceCommandContext context | ||||
|         :return: str | ||||
|         """ | ||||
|         resource = LanforgeResource.create_from_context(context) | ||||
|         msg = "My resource: " + resource.name | ||||
|         msg += ", at address: " + context.resource.address | ||||
|         return msg | ||||
|  | ||||
|     def create_wanlink(self, context, name, latency, rate): | ||||
|         resource = LanforgeResource.create_from_context(context) | ||||
|         terminal_ip = context.resource.address | ||||
|         terminal_user = context.resource.attributes["{}User".format(shell_name)] = "lanforge" | ||||
|         terminal_pass = context.resource.attributes["{}Password".format(shell_name)] = "lanforge" | ||||
|  | ||||
|         print("Initializing SSH connection to {ip}, with user {user} and password {password}".format(ip=terminal_ip, user=terminal_user, password=terminal_pass)) | ||||
|         s = paramiko.SSHClient() | ||||
|         s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | ||||
|         s.connect(hostname=terminal_ip, username=terminal_user, password=terminal_pass) | ||||
|          | ||||
|         command = "/home/lanforge/lanforge-scripts/py-json/create_wanlink.py --host {host} --port_A {port_A} --port_B {port_B} --name \"{name}\" --latency \"{latency}\" --latency_A \"{latency_A}\" --latency_B \"{latency_B}\" --rate {rate} --rate_A {rate_A} --rate_B {rate_B} --jitter {jitter} --jitter_A {jitter_A} --jitter_B {jitter_B} --jitter_freq_A {jitter_freq_A} --jitter_freq_B {jitter_freq_B} --drop_A {drop_A} --drop_B {drop_B}".format( | ||||
|             host="localhost", | ||||
|             port_A="eth1", | ||||
|             port_B="eth2", | ||||
|             name=name, | ||||
|             latency=latency, | ||||
|             latency_A=latency, | ||||
|             latency_B=latency, | ||||
|             rate=rate, | ||||
|             rate_A=rate, | ||||
|             rate_B=rate, | ||||
|             jitter="0", | ||||
|             jitter_A="0", | ||||
|             jitter_B="0", | ||||
|             jitter_freq_A="0", | ||||
|             jitter_freq_B="0", | ||||
|             drop_A="0", | ||||
|             drop_B="0" | ||||
|         ) | ||||
|          | ||||
|         (stdin, stdout, stderr) = s.exec_command(command) | ||||
|         output = '' | ||||
|         errors = '' | ||||
|         for line in stdout.readlines(): | ||||
|             output += line | ||||
|         for line in stderr.readlines(): | ||||
|             errors += line | ||||
|         print(errors) | ||||
|         # if errors != '': | ||||
|         print(errors) | ||||
|         # else: | ||||
|         print(output) | ||||
|         s.close() | ||||
|  | ||||
|         # print(args) | ||||
|         # command = "./lanforge-scripts/py-json/create_wanlink.py --host \"{host}\" --name my_wanlink4 --latency \"{latency}\" --rate \"{rate}\"".format( | ||||
|         #     host = context.resource.address, | ||||
|         #     name=args['name'], | ||||
|         #     latency=args['latency'], | ||||
|         #     rate=args['rate'] | ||||
|         # ) | ||||
|         # print("running:[{}]".format(command)) | ||||
|         # process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) | ||||
|         # outs, errs = process.communicate() | ||||
|         # print(outs) | ||||
|         # print(errs) | ||||
|  | ||||
|     def create_l3(self, context, name, min_rate_a, min_rate_b, endp_a, endp_b): | ||||
|         # api_session = CloudShellSessionContext(context) | ||||
|         resource = LanforgeResource.create_from_context(context) | ||||
|         args = { | ||||
|             "host": context.resource.address, | ||||
|             "name_prefix": name, | ||||
|             "min_rate_a": min_rate_a, | ||||
|             "min_rate_b": min_rate_b, | ||||
|             "endp_a": endp_a, | ||||
|             "endp_b": endp_b | ||||
|         } | ||||
|         # ip_var_test = CreateL3( | ||||
|         #     host=context.resource.address, | ||||
|         #     name_prefix=name, | ||||
|         #     endp_a=[endp_a], | ||||
|         #     endp_b=endp_b, | ||||
|         #     min_rate_a=min_rate_a, | ||||
|         #     min_rate_b=min_rate_b | ||||
|         # ) | ||||
|  | ||||
|         print(args) | ||||
|         terminal_ip = context.resource.address | ||||
|         terminal_user = context.resource.attributes["{}.User".format(shell_name)] = "lanforge" | ||||
|         terminal_pass = context.resource.attributes["{}.Password".format(shell_name)] = "lanforge" | ||||
|          | ||||
|         print("Initializing SSH connection to {ip}, with user {user} and password {password}".format(ip=terminal_ip, user=terminal_user, password=terminal_pass)) | ||||
|         s = paramiko.SSHClient() | ||||
|         s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | ||||
|         s.connect(hostname=terminal_ip, username=terminal_user, password=terminal_pass) | ||||
|          | ||||
|         command = "/home/lanforge/lanforge-scripts/py-scripts/create_l3.py --endp_a \"{endp_a}\" --endp_b \"{endp_b}\" --min_rate_a \"{min_rate_a}\" --min_rate_b \"{min_rate_b}\"".format( | ||||
|             endp_a=args['endp_a'], | ||||
|             endp_b=args['endp_b'], | ||||
|             min_rate_a=args['min_rate_a'], | ||||
|             min_rate_b=args['min_rate_b'] | ||||
|         ) | ||||
|          | ||||
|         (stdin, stdout, stderr) = s.exec_command(command) | ||||
|         output = '' | ||||
|         errors = '' | ||||
|         for line in stdout.readlines(): | ||||
|             output += line | ||||
|         for line in stderr.readlines(): | ||||
|             errors += line | ||||
|         print(errors) | ||||
|         if errors != '': | ||||
|             print(errors) | ||||
|         else: | ||||
|             print(output) | ||||
|         s.close() | ||||
|          | ||||
|         # print("running:[{}]".format(command)) | ||||
|         # process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) | ||||
|         # outs, errs = process.communicate() | ||||
|         # print(outs) | ||||
|         # print(errs) | ||||
|  | ||||
|         # num_sta = 2 | ||||
|         # ip_var_test.pre_cleanup() | ||||
|         # ip_var_test.build() | ||||
|         # if not ip_var_test.passes(): | ||||
|         #     print(ip_var_test.get_fail_message()) | ||||
|         #     ip_var_test.exit_fail() | ||||
|         # print('Created %s stations and connections' % num_sta) | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     # setup for mock-debug environment | ||||
|     shell_name = "LanforgeResource" | ||||
|     cancellation_context = mock.create_autospec(CancellationContext) | ||||
|     context = mock.create_autospec(ResourceCommandContext) | ||||
|     context.resource = mock.MagicMock() | ||||
|     context.reservation = mock.MagicMock() | ||||
|     context.connectivity = mock.MagicMock() | ||||
|     context.reservation.reservation_id = "<RESERVATION_ID>" | ||||
|     context.resource.address = "192.168.100.176" | ||||
|     context.resource.name = "Lanforge_Resource" | ||||
|     context.resource.attributes = dict() | ||||
|     context.resource.attributes["{}.User".format(shell_name)] = "lanforge" | ||||
|     context.resource.attributes["{}.Password".format(shell_name)] = "lanforge" | ||||
|     context.resource.attributes["{}.SNMP Read Community".format(shell_name)] = "<READ_COMMUNITY_STRING>" | ||||
|  | ||||
|     # add information for api connectivity | ||||
|     context.reservation.domain = "Global" | ||||
|     context.connectivity.server_address = "192.168.100.131" | ||||
|     driver = LanforgeResourceDriver() | ||||
|     # print driver.run_custom_command(context, custom_command="sh run", cancellation_context=cancellation_context) | ||||
|     # result = driver.example_command_with_api(context) | ||||
|  | ||||
|     driver.create_l3(context, "my_fire", "69000", "41000", "eth1", "eth2") | ||||
|     driver.create_wanlink(context, name="my_wanlin", latency="49", rate="6000") | ||||
|     print("done") | ||||
							
								
								
									
										73
									
								
								Quali/lanforge_resource/src/drivermetadata.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								Quali/lanforge_resource/src/drivermetadata.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,73 @@ | ||||
| <Driver Description="Describe the purpose of your CloudShell shell" MainClass="driver.LanforgeResourceDriver" Name="LanforgeResourceDriver" Version="1.0.0" PythonVersion="3"> | ||||
|     <Layout> | ||||
| 	<Category Name="Hidden Commands"> | ||||
| 		<Command Description=""  | ||||
| 			 DisplayName="Orchestration Save"  | ||||
| 			 Name="orchestration_save" /> | ||||
| 		<Command Description=""  | ||||
| 			 DisplayName="Orchestration Restore"  | ||||
| 			 Name="orchestration_restore" /> | ||||
| 	</Category> | ||||
| 	<Category Name="Example Commands"> | ||||
| 		<Command Description="Example Command from Demo" | ||||
| 			 DisplayName="Example Command" | ||||
| 			 Name="example_command"/> | ||||
| 	</Category> | ||||
| 	<Category Name="ICE"> | ||||
| 		<Command Description="Create a virtual wanlink with custom impairments." | ||||
| 			 DisplayName="Create Wanlink" | ||||
| 			 Name="create_wanlink"> | ||||
| 			<Parameters> | ||||
| 				<Parameter Name="name" | ||||
| 				 Type="String"  | ||||
| 				 Mandatory="False"  | ||||
| 				 DefaultValue="wl_eg1"  | ||||
| 				 Description="Enter a name for the wanlink."/> | ||||
| 				<Parameter Name="latency" | ||||
| 				 Type="String" | ||||
| 				 Mandatory="False" | ||||
| 				 DefaultValue="20" | ||||
| 				 Description="Latency of both endpoints"/> | ||||
| 				<Parameter Name="rate" | ||||
| 				 Type="String" | ||||
| 				 Mandatory="False" | ||||
| 				 DefaultValue="1000" | ||||
| 				 Description="The total throughput capacity of the wanlink."/> | ||||
| 			</Parameters> | ||||
| 		</Command>	 | ||||
| 	</Category> | ||||
| 	<Category Name="FIRE"> | ||||
| 	  <Command Description="Generate traffic between two existing ports" | ||||
| 		   DisplayName="Create Layer-3" | ||||
| 		   Name="create_l3"> | ||||
| 	    <Parameters> | ||||
| 	      <Parameter Name="name" | ||||
| 			 Type="String" | ||||
| 			 Mandatory="False" | ||||
| 			 DefaultValue="scr-test-1" | ||||
| 			 Description="Enter a name for the connection"/> | ||||
| 	      <Parameter Name="min_rate_a" | ||||
| 			 Type="String" | ||||
| 			 Mandatory="False" | ||||
| 			 DefaultValue="56000" | ||||
| 			 Description="Minimum transfer rate of side a"/> | ||||
| 	      <Parameter Name="min_rate_b" | ||||
| 			 Type="String" | ||||
| 			 Mandatory="False" | ||||
| 			 DefaultValue="56000" | ||||
| 			 Description="Minimum transfer rate of side b"/> | ||||
| 	      <Parameter Name="endp_a" | ||||
| 			 Type="String" | ||||
| 			 Mandatory="False" | ||||
| 			 DefaultValue="eth1" | ||||
| 			 Description="Station list"/> | ||||
| 	      <Parameter Name="endp_b" | ||||
| 			 Type="String" | ||||
| 			 Mandatory="False" | ||||
| 			 DefaultValue="eth2" | ||||
| 			 Description="Upstream port"/> | ||||
| 	    </Parameters> | ||||
| 	  </Command> | ||||
| 	</Category> | ||||
|     </Layout> | ||||
| </Driver> | ||||
							
								
								
									
										0
									
								
								Quali/lanforge_resource/src/importlib
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								Quali/lanforge_resource/src/importlib
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										25
									
								
								Quali/lanforge_resource/src/requirements.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								Quali/lanforge_resource/src/requirements.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| mock | ||||
| cloudshell-shell-core>=5.0.3,<6.0.0 | ||||
| cloudshell-automation-api | ||||
| pandas | ||||
| plotly | ||||
| numpy==1.16.6 | ||||
| cryptography | ||||
| paramiko | ||||
| bokeh | ||||
| streamlit==0.62.0 | ||||
| cython | ||||
| pyarrow==4.0.0 | ||||
| websocket-client | ||||
| xlsxwriter | ||||
| pyshark | ||||
| influxdb | ||||
| influxdb-client | ||||
| matplotlib | ||||
| pdfkit | ||||
| pip-search | ||||
| pyserial | ||||
| pexpect-serial | ||||
| scp | ||||
| dash | ||||
| kaleido | ||||
							
								
								
									
										0
									
								
								Quali/lanforge_resource/src/sys
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								Quali/lanforge_resource/src/sys
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										7
									
								
								Quali/lanforge_resource/test_requirements.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								Quali/lanforge_resource/test_requirements.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| nose | ||||
| coverage | ||||
| unittest2 | ||||
| mock | ||||
| teamcity-messages | ||||
| jsonpickle | ||||
| nose-exclude | ||||
							
								
								
									
										1
									
								
								Quali/lanforge_resource/tests/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								Quali/lanforge_resource/tests/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
							
								
								
									
										27
									
								
								Quali/lanforge_resource/tests/test_lanforge-resource.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Quali/lanforge_resource/tests/test_lanforge-resource.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| #!/usr/bin/env python | ||||
| # -*- coding: utf-8 -*- | ||||
|  | ||||
| """ | ||||
| Tests for `LanforgeResourceDriver` | ||||
| """ | ||||
|  | ||||
| import unittest | ||||
|  | ||||
| from driver import LanforgeResourceDriver | ||||
|  | ||||
|  | ||||
| class TestLanforgeResourceDriver(unittest.TestCase): | ||||
|  | ||||
|     def setUp(self): | ||||
|         pass | ||||
|  | ||||
|     def tearDown(self): | ||||
|         pass | ||||
|  | ||||
|     def test_000_something(self): | ||||
|         pass | ||||
|  | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|     import sys | ||||
|     sys.exit(unittest.main()) | ||||
		Reference in New Issue
	
	Block a user
	 erinnerim
					erinnerim