mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-10-29 01:42:37 +00:00
driver.py: CloudShell dataplane attachment (proof of concept)
This commit is contained in:
@@ -3,6 +3,10 @@ from cloudshell.shell.core.driver_context import InitCommandContext, ResourceCom
|
|||||||
AutoLoadAttribute, AutoLoadDetails, CancellationContext
|
AutoLoadAttribute, AutoLoadDetails, CancellationContext
|
||||||
from cloudshell.shell.core.session.cloudshell_session import CloudShellSessionContext
|
from cloudshell.shell.core.session.cloudshell_session import CloudShellSessionContext
|
||||||
from cloudshell.api.cloudshell_api import CloudShellAPISession
|
from cloudshell.api.cloudshell_api import CloudShellAPISession
|
||||||
|
from cloudshell.helpers.scripts.cloudshell_scripts_helpers import get_api_session, get_reservation_context_details
|
||||||
|
from cloudshell.shell.core.session.cloudshell_session import CloudShellSessionContext
|
||||||
|
import cloudshell.helpers.scripts.cloudshell_scripts_helpers as script_help
|
||||||
|
import cloudshell.helpers.scripts.cloudshell_dev_helpers as dev_helpers
|
||||||
# from cloudshell.shell.core.resource_driver_interface import ResourceDriverInterface
|
# from cloudshell.shell.core.resource_driver_interface import ResourceDriverInterface
|
||||||
# from cloudshell.shell.core.context import InitCommandContext, ResourceCommandContext
|
# from cloudshell.shell.core.context import InitCommandContext, ResourceCommandContext
|
||||||
import mock
|
import mock
|
||||||
@@ -14,6 +18,9 @@ import os
|
|||||||
import importlib
|
import importlib
|
||||||
import paramiko
|
import paramiko
|
||||||
from scp import SCPClient
|
from scp import SCPClient
|
||||||
|
import requests
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
|
||||||
# command = "./lanforge-scripts/py-scripts/update_dependencies.py"
|
# command = "./lanforge-scripts/py-scripts/update_dependencies.py"
|
||||||
# print("running:[{}]".format(command))
|
# print("running:[{}]".format(command))
|
||||||
@@ -150,7 +157,37 @@ class LanforgeResourceDriver (ResourceDriverInterface):
|
|||||||
return saved_details_object[u'saved_artifact'][u'identifier']
|
return saved_details_object[u'saved_artifact'][u'identifier']
|
||||||
'''
|
'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def attach_file(self, report_server, resid, file_path, user, password, domain, filename):
|
||||||
|
|
||||||
|
# st = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d%H%M%S')
|
||||||
|
data = {
|
||||||
|
'username': user,
|
||||||
|
'password': password,
|
||||||
|
'domain': domain
|
||||||
|
}
|
||||||
|
qq = 'Basic ' + requests.put(
|
||||||
|
url='http://' + report_server + ':9000/API/Auth/Login',
|
||||||
|
data=data
|
||||||
|
).text[1:-1]
|
||||||
|
head = {
|
||||||
|
'Authorization': qq,
|
||||||
|
}
|
||||||
|
dat_json ={
|
||||||
|
"reservationId": resid,
|
||||||
|
"saveFileAs": filename,
|
||||||
|
"overwriteIfExists": "true",
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(file_path, 'rb') as upload_file:
|
||||||
|
xx = requests.post(
|
||||||
|
url='http://' + report_server + ':9000/API/Package/AttachFileToReservation',
|
||||||
|
headers=head,
|
||||||
|
data=dat_json,
|
||||||
|
files={'QualiPackage': upload_file}
|
||||||
|
)
|
||||||
|
return xx
|
||||||
|
|
||||||
def send_command(self, context, cmd):
|
def send_command(self, context, cmd):
|
||||||
|
|
||||||
msg = ""
|
msg = ""
|
||||||
@@ -237,7 +274,7 @@ class LanforgeResourceDriver (ResourceDriverInterface):
|
|||||||
|
|
||||||
def pull_reports(self, hostname="", port=22,
|
def pull_reports(self, hostname="", port=22,
|
||||||
username="lanforge", password="lanforge",
|
username="lanforge", password="lanforge",
|
||||||
report_location="/home/lanforge/html_reports/",
|
report_location="/home/lanforge/html-reports/",
|
||||||
report_dir="./"):
|
report_dir="./"):
|
||||||
|
|
||||||
ssh = paramiko.SSHClient()
|
ssh = paramiko.SSHClient()
|
||||||
@@ -282,11 +319,27 @@ class LanforgeResourceDriver (ResourceDriverInterface):
|
|||||||
resource_model_name = resource.cloudshell_model_name
|
resource_model_name = resource.cloudshell_model_name
|
||||||
terminal_pass = session.DecryptPassword(context.resource.attributes[f'{resource_model_name}.Password']).Value
|
terminal_pass = session.DecryptPassword(context.resource.attributes[f'{resource_model_name}.Password']).Value
|
||||||
terminal_user = context.resource.attributes[f'{resource_model_name}.User']
|
terminal_user = context.resource.attributes[f'{resource_model_name}.User']
|
||||||
|
reservation_id = context.reservation.reservation_id
|
||||||
|
api = CloudShellSessionContext(context).get_api()
|
||||||
|
cwd = os.getcwd()
|
||||||
# session.AttachFileToReservation(context.reservation.reservation_id, f"C:/Users/Administrator/{output_report_dir}", "C:/Users/Administrator/AppData/Local/Temp", True)
|
# session.AttachFileToReservation(context.reservation.reservation_id, f"C:/Users/Administrator/{output_report_dir}", "C:/Users/Administrator/AppData/Local/Temp", True)
|
||||||
self.pull_reports(hostname=context.resource.address, port=22,
|
self.pull_reports(hostname=context.resource.address, port=22,
|
||||||
username=terminal_user, password=terminal_pass,
|
username=terminal_user, password=terminal_pass,
|
||||||
report_location=f"/home/lanforge/html-reports",
|
report_location="/home/lanforge/html-reports/",
|
||||||
report_dir=f"C:/Users/Administrator/{output_report_dir}")
|
report_dir=f"C:/Users/Administrator/{output_report_dir}")
|
||||||
|
|
||||||
|
# api = get_api_session()
|
||||||
|
# api.WriteMessageToReservationOutput(reservation_id, f"Attaching report to sandbox.")
|
||||||
|
api.WriteMessageToReservationOutput(reservation_id, f"The current working directory is {cwd}")
|
||||||
|
self.attach_file(
|
||||||
|
report_server=context.connectivity.server_address,
|
||||||
|
resid=context.reservation.reservation_id,
|
||||||
|
user='admin',
|
||||||
|
password='admin',
|
||||||
|
domain=context.reservation.domain,
|
||||||
|
file_path="C:/Users/Administrator/Desktop/My_Reports/html-reports/dataplane-2021-10-13-03-32-40/dataplane-report-2021-10-13-03-31-50.pdf",
|
||||||
|
filename="C:/Users/Administrator/Desktop/test_report.txt"
|
||||||
|
)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def scenario(self, context, load):
|
def scenario(self, context, load):
|
||||||
|
|||||||
@@ -150,7 +150,7 @@
|
|||||||
<Parameter Name="duration"
|
<Parameter Name="duration"
|
||||||
Type="String"
|
Type="String"
|
||||||
Mandatory="False"
|
Mandatory="False"
|
||||||
DefaultValue="15s"
|
DefaultValue="2s"
|
||||||
Description="The duration of the test (append 's' for seconds)"/>
|
Description="The duration of the test (append 's' for seconds)"/>
|
||||||
<Parameter Name="download_speed"
|
<Parameter Name="download_speed"
|
||||||
Type="String"
|
Type="String"
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
mock
|
mock
|
||||||
cloudshell-shell-core>=5.0.3,<6.0.0
|
cloudshell-shell-core>=5.0.3,<6.0.0
|
||||||
cloudshell-automation-api
|
cloudshell-automation-api
|
||||||
|
cloudshell-orch-core
|
||||||
|
requests
|
||||||
paramiko
|
paramiko
|
||||||
scp
|
scp
|
||||||
|
|||||||
Reference in New Issue
Block a user