def resource_context() -> ResourceCommandContext: connectivity = ConnectivityContext( server_address="localhost", quali_api_port="9000", cloudshell_version="2020.1", cloudshell_api_scheme="http", cloudshell_api_port="8029", admin_auth_token="token", ) resource_context_details = ResourceContextDetails( address="NA", app_context=AppContext(app_request_json="", deployed_app_json=""), description="", family="Cloud Provider", fullname="OpenStack Cloud Provider", id="a95027f6-98bf-4177-8d40-d610f0179107", model="OpenStack", name="OpenStack Cloud Provider", networks_info=None, shell_standard="", shell_standard_version="", type="Resource", attributes={ f"{SHELL_NAME}.OpenStack Project Name": "admin", f"{SHELL_NAME}.Execution Server Selector": "", f"{SHELL_NAME}.OpenStack Physical Interface Name": "", f"{SHELL_NAME}.User": "******", f"{SHELL_NAME}.OpenStack Domain Name": "default", f"{SHELL_NAME}.OpenStack Management Network ID": "9ce15bef-c7a1-4982-910c-0427555236a5", # noqa: E501 f"{SHELL_NAME}.Floating IP Subnet ID": "b79772e5-3f2f-4bff-b106-61e666bd65e7", # noqa: E501 f"{SHELL_NAME}.OpenStack Reserved Networks": "192.168.1.0/24;192.168.2.0/24", # noqa: E501 f"{SHELL_NAME}.Password": "******", f"{SHELL_NAME}.VLAN Type": "VXLAN", f"{SHELL_NAME}.Controller URL": "http://openstack.example/identity", }, ) reservation_context = ReservationContextDetails( **{ "domain": "Global", "owner_email": None, "description": "", "environment_name": "CloudShell Sandbox Template3", "environment_path": "CloudShell Sandbox Template3", "owner_user": "******", "saved_sandbox_id": "", "saved_sandbox_name": "", "reservation_id": "8574cce6-adba-4e2c-86f7-a146475943c6", "running_user": "******", }, ) return ResourceCommandContext(connectivity, resource_context_details, reservation_context, [])
def _conn_and_res(self, family: str, model: str, address: str, attributes: dict, type_: str, full_name: str) -> Tuple[ConnectivityContext, ResourceContextDetails]: if not attributes: attributes = {} connectivity = ConnectivityContext(self.session.host, '8029', '9000', self.session.token_id, '9.1', CloudShellSessionContext.DEFAULT_API_SCHEME) resource = ResourceContextDetails(id='ididid', name=path.basename(full_name), fullname=full_name, type=type_, address=address, model=model, family=family, attributes=attributes, app_context=AppContext('', ''), networks_info='', description='', shell_standard='', shell_standard_version='') return connectivity, resource
resource_attributes = dict() resource_attributes["{}.User".format(RESOURCE_MODEL)] = USER_NAME resource_attributes["{}.Password".format(RESOURCE_MODEL)] = PASSWORD resource_attributes["{}.SNMP Read Community".format( RESOURCE_MODEL)] = SNMP_READ_COMMUNITY resource_context = ResourceContextDetails(id="", name=RESOURCE_NAME, fullname="", type="Resource", address=RESOURCE_ADDRESS, model=RESOURCE_MODEL, family=RESOURCE_FAMILY, description="", attributes=resource_attributes, app_context=AppContext("", ""), networks_info=None, shell_standard="", shell_standard_version="") connectivity_context = ConnectivityContext(server_address=CS_SERVER, cloudshell_api_port="8028", quali_api_port="9000", admin_auth_token="", cloudshell_version="9.3", cloudshell_api_scheme="") context = AutoLoadCommandContext( connectivity=connectivity_context, resource=resource_context, )
def test_static_deployed_app(): app_name = "win-test" address = "192.168.26.43" uuid = "42282856-0637-216a-511d-ccd88aa07e8f" vm_name = "static-vms/win-test" app_context = AppContext( app_request_json="", deployed_app_json=json.dumps({ "name": app_name, "family": "CS_GenericAppFamily", "model": StaticApp.DEPLOYMENT_PATH, "address": address, "attributes": [ { "name": f"{StaticApp.DEPLOYMENT_PATH}.VM Name", "value": "static-vms/win-test", }, { "name": f"{StaticApp.DEPLOYMENT_PATH}.vCenter Resource Name", "value": "vcenter", }, { "name": f"{StaticApp.DEPLOYMENT_PATH}.User", "value": "" }, { "name": f"{StaticApp.DEPLOYMENT_PATH}.Password", "value": "" }, { "name": f"{StaticApp.DEPLOYMENT_PATH}.Public IP", "value": "" }, { "name": "Execution Server Selector", "value": "" }, ], "vmdetails": { "id": "8b6c4c4d-e2c9-47c9-b260-9a33688bf78a", "cloudProviderId": "d4d679c6-3049-4e55-9e64-8692a3400b6a", "uid": uuid, "vmCustomParams": [], }, }), ) resource = ResourceContextDetails( id="0917eb75-92ad-4291-9623-4235c81be76b", name=app_name, fullname=app_name, type="Resource", address=address, model=StaticApp.DEPLOYMENT_PATH, family="CS_GenericAppFamily", description=None, attributes={ "Generic Static vCenter VM 2G.VM Name": vm_name, "Generic Static vCenter VM 2G.vCenter Resource Name": "vcenter", "Generic Static vCenter VM 2G.User": "", "Generic Static vCenter VM 2G.Password": "******", "Generic Static vCenter VM 2G.Public IP": "", "Execution Server Selector": "", }, app_context=app_context, networks_info=None, shell_standard=None, shell_standard_version=None, ) DeployedVMActions.register_deployment_path(StaticApp) actions = DeployedVMActions.from_remote_resource(resource, Mock()) app = actions.deployed_app assert isinstance(app, StaticApp) assert app.name == app_name assert app.model == app.deployment_service_model == StaticApp.DEPLOYMENT_PATH assert app.private_ip == address assert app.vmdetails.uid == uuid assert app.attributes[f"{StaticApp.DEPLOYMENT_PATH}.VM Name"] == vm_name
def test_deployed_app(): app_name = "Azureubuntusimple" address = "10.0.1.3" deployed_model = "Generic App Model" uuid = "3d750874-09f1-4243-a598-6700bb648655" app_context = AppContext( app_request_json=json.dumps({ "name": app_name, "description": None, "logicalResource": { "family": "GenericAppFamily", "model": "GenericAppModel", "driver": None, "description": "", "attributes": [ { "name": "Password", "value": "" }, { "name": "PublicIP", "value": "" }, { "name": "User", "value": "" }, ], }, "deploymentService": { "cloudProviderName": "Azure2Goldcode", "name": "Microsoft Azure 2nd Gen.Azure VM From Marketplace 2nd Gen", "model": MyDeployedApp.DEPLOYMENT_PATH, "driver": None, "attributes": [ { "name": "MicrosoftAzure2G.AzureVMFromMarketplace2G.Disk", "value": "HDD", }, ], }, }), deployed_app_json=json.dumps({ "name": app_name, "family": "Generic App Family", "model": "Generic App Model", "address": address, "attributes": [ { "name": "Password", "value": "3M3u7nkDzxWb0aJ/IZYeWw==" }, { "name": "User", "value": "adminuser" }, { "name": "Public IP", "value": "" }, ], "vmdetails": { "id": "4da74d28-50d9-4271-b2e4-b49eed1bb0fe", "cloudProviderId": "129b8fac-fd8d-4c37-bb1a-fdceba2f38d7", "uid": uuid, "vmCustomParams": [], }, }), ) resource = ResourceContextDetails( id="0917eb75-92ad-4291-9623-4235c81be76b", name=app_name, fullname=app_name, type="Resource", address=address, model="Generic App Model", family="Generic App Family", description=None, attributes={ "Password": "******", "User": "******", "Public IP": "", }, app_context=app_context, networks_info=None, shell_standard=None, shell_standard_version=None, ) DeployedVMActions.register_deployment_path(MyDeployedApp) actions = DeployedVMActions.from_remote_resource(resource, Mock()) app = actions.deployed_app assert isinstance(app, MyDeployedApp) assert app.name == app_name assert app.model == deployed_model assert app.deployment_service_model == MyDeployedApp.DEPLOYMENT_PATH assert app.private_ip == address assert app.vmdetails.uid == uuid assert app.attributes[f"{MyDeployedApp.DEPLOYMENT_PATH}.Disk"] == "HDD" assert app.attributes["User"] == "adminuser"
def resource_remote_context(connectivity_context, resource_context_details, reservation_context_details): d_path = f"{SHELL_NAME}.OpenStack Deploy Glance Image 2G." deployment_service = { "cloudProviderName": "OS", "name": f"{SHELL_NAME}.OpenStack Deploy Glance Image 2G", "model": f"{SHELL_NAME}.OpenStack Deploy Glance Image 2G", "driver": None, "attributes": [ { "name": f"{d_path}Availability Zone", "value": "", }, { "name": f"{d_path}Image ID", "value": "image id", }, { "name": f"{d_path}Instance Flavor", "value": "flavor name", }, { "name": f"{d_path}Add Floating IP", "value": "True", }, { "name": f"{d_path}Autoload", "value": "True", }, { "name": f"{d_path}Affinity Group ID", "value": "", }, { "name": f"{d_path}Floating IP Subnet ID", "value": "", }, { "name": f"{d_path}Auto udev", "value": "True", }, { "name": f"{d_path}Wait for IP", "value": "False", }, ], } app_context = AppContext( **{ "app_request_json": json.dumps({ "name": "app name", "description": None, "logicalResource": { "family": "Generic App Family", "model": "Generic App Model", "driver": None, "description": "", "attributes": [ { "name": "Password", "value": "password" }, { "name": "Public IP", "value": "" }, { "name": "User", "value": "" }, ], }, "deploymentService": deployment_service, }), "deployed_app_json": json.dumps({ "name": "app-name-cs", "family": "Generic App Family", "model": "Generic App Model", "address": "app ip address", "attributes": [ { "name": "Password", "value": "password" }, { "name": "User", "value": "" }, { "name": "Public IP", "value": "8.8.8.8" }, ], "vmdetails": { "id": "app id", "cloudProviderId": "cloud provider id", "uid": "app uid", "vmCustomParams": [], }, }), }) remote_endpoints = [ ResourceContextDetails( **{ "name": "app-name-cs", "family": "Generic App Family", "networks_info": None, "app_context": app_context, "id": "app id", "shell_standard_version": None, "address": "app ip address", "shell_standard": None, "attributes": { "Password": "******", "User": "", "Public IP": "", }, "model": "Generic App Model", "type": "Resource", "fullname": "app-name-cs", "description": None, }) ] return ResourceRemoteCommandContext( connectivity_context, resource_context_details, reservation_context_details, remote_endpoints, )