Exemple #1
0
def resource_context_details():
    return 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=SHELL_NAME,
        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",
        },
    )
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
def get_resource_context_details():
    """
    Get the resource details dictionary for this execution
    These details are automatically passed to the driver by CloudShell

    :rtype: ResourceContextDetails
    """
    res_dict = get_resource_context_details_dict()
    res_details = ResourceContextDetails(name=res_dict['name'],
                                         address=res_dict['address'],
                                         model=res_dict['model'],
                                         family=res_dict['family'],
                                         description=res_dict['description'],
                                         fullname=res_dict['fullname'],
                                         attributes=res_dict['attributes'],
                                         id='',
                                         type='',
                                         app_context=None,
                                         networks_info='',
                                         shell_standard='',
                                         shell_standard_version='')
    return res_details
        This is a good place to close any open sessions, finish writing to log files, etc.
        """
        pass


if __name__ == "__main__":
    import mock
    from cloudshell.shell.core.driver_context import ResourceCommandContext, ResourceContextDetails, ReservationContextDetails

    address = "192.168.26.24"
    user = "******"
    password = "******"
    port = 5240

    context = ResourceCommandContext(*(None, ) * 4)
    context.resource = ResourceContextDetails(*(None, ) * 13)
    context.resource.name = "MAAS"
    context.resource.fullname = "Canonical MAAS"
    context.resource.address = address
    context.resource.family = "CS_CloudProvider"
    context.reservation = ReservationContextDetails(*(None, ) * 7)
    context.reservation.reservation_id = '0cc17f8c-75ba-495f-aeb5-df5f0f9a0e97'
    context.resource.attributes = {}

    for attr, value in [
        ("User", user),
        ("Password", password),
        ("Scheme", "http"),
            # ("Managed Allocation", "True"),
        ("Port", port)
    ]:
    def prepare_context(address="192.168.85.14", user="******", password="******", port=6666):
        """
        :return:
        """
        """Return initialized driver instance"""
        context = ResourceCommandContext(*(None,) * 4)
        context.resource = ResourceContextDetails(*(None,) * 13)
        context.resource.name = "CGS COS Loadbalancer Shell 2G"
        context.resource.fullname = "CGS COS Loadbalancer Shell 2G"
        context.resource.address = address
        context.resource.family = "CS_LoadBalancer"
        context.reservation = ReservationContextDetails(*(None,) * 7)
        context.reservation.reservation_id = '0cc17f8c-75ba-495f-aeb5-df5f0f9a0e97'
        context.resource.attributes = {}

        for attr, value in [("User", user),
                            ("Sessions Concurrency Limit", 1),
                            ("CLI Connection Type", "SSH"),
                            ("Password", password),
                            ("Enable Password", password),
                            ("CLI TCP Port", port),

                            # Backup location attributes for the "Save" command
                            ("Backup Location", ""),
                            ("Backup Type", "File System"),
                            ("Backup User", "backup_user"),
                            ("Backup Password", "backup_pass"),

                            # SNMP v2 Read-only
                            ("SNMP Version", "2"),
                            ("Enable SNMP", "True"),
                            ("Disable SNMP", "True"),
                            ("SNMP Read Community", "public_testing_2"),
                            # End SNMP v2 Read-only

                            # SNMP v2 Read-Write
                            # ("SNMP Version", "2"),
                            # ("Enable SNMP", "True"),
                            # ("Disable SNMP", "False"),
                            # ("SNMP Write Community", "public_33"),
                            # End SNMP v2 Read-Write

                            # SNMP v3
                            # ("SNMP Version", "3"),
                            # ("Enable SNMP", "True"),
                            # ("Disable SNMP", "True"),
                            # ("SNMP V3 User", "quali_NEW_NEW2"),
                            # ("SNMP V3 Password", "qualipass"),
                            # ("SNMP V3 Private Key", "qualipass2"),
                            # ("SNMP V3 Authentication Protocol", "No Authentication Protocol"),
                            # "No Authentication Protocol", "MD5", "SHA"
                            ("SNMP V3 Privacy Protocol", "No Privacy Protocol"),
                            # "No Privacy Protocol", "DES", "3DES-EDE", "AES-128", "AES-192", "AES-256"
                            # End SNMP v3
                            ]:

            context.resource.attributes["{}.{}".format(CgsCosLoadbalancerShell2GDriver.SHELL_NAME, attr)] = value
            context.connectivity = mock.MagicMock()
            context.connectivity.server_address = "192.168.85.10"

        return context
CS_SERVER = "localhost"

# ==== Setting resource attributes ===
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(
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"
Exemple #10
0
from cloudshell.shell.core.driver_context import AutoLoadCommandContext, ResourceContextDetails, ConnectivityContext
from cloudshell.networking.juniper.junos.resource_driver.junos_resource_driver import JunosResourceDriver
from examples.juniper.autoload.autoload_debug_data import G_DATA

resource = ResourceContextDetails("Junos", "", 'Resource', '192.168.28.150',
                                  '', '', '', {}, '', '')
connectivity = ConnectivityContext('10.5.1.2', '', '', 'fdsfdsfdsfsd')
resource.attributes['SNMP Version'] = '2'
resource.attributes['SNMP User'] = ''
resource.attributes['SNMP Password'] = ''
resource.attributes['SNMP Read Community'] = 'public'
resource.attributes['SNMP Private Key'] = ''

context = AutoLoadCommandContext(connectivity, resource)

driver = JunosResourceDriver()
print(driver.get_inventory(context))

# print(G_DATA['jnxContentsTable'])
    def prepare_context():
        """

        :return:
        """
        """Return initialized driver instance"""
        address = '192.168.105.30'
        user = '******'
        password = '******'
        port = 443
        auth_key = 'h8WRxvHoWkmH8rLQz+Z/pg=='
        api_port = 8029

        context = ResourceCommandContext(*(None,) * 4)
        context.resource = ResourceContextDetails(*(None,) * 13)
        context.resource.name = "Cumulus Linux Switch"
        context.resource.fullname = "Cumulus Linux Switch"
        context.resource.address = address
        context.resource.family = "CS_Switch"
        context.reservation = ReservationContextDetails(*(None,) * 7)
        context.reservation.reservation_id = '0cc17f8c-75ba-495f-aeb5-df5f0f9a0e97'
        context.resource.attributes = {}

        for attr, value in [("User", user),
                            ("Sessions Concurrency Limit", 1),

                            # Backup location attributes for the "Save" command
                            ("Backup Location", "/home/cumulus/backups"),
                            ("Backup Type", "File System"),
                            ("Backup User", "backup_user"),
                            ("Backup Password", "backup_pass"),

                            # Backup location attributes for the "Save" command
                            # ("Backup Location", "192.168.85.13/home/quali/"),
                            # ("Backup Type", "scp"),
                            # ("Backup User", "quali"),
                            # ("Backup Password", "quali"),


                            # SNMP v2 Read-only
                            # ("SNMP Version", "2"),
                            # ("Enable SNMP", "True"),
                            # ("Disable SNMP", "True"),
                            # ("SNMP Read Community", "mynotsosecretpassword"),
                            # End SNMP v2 Read-only

                            # SNMP v2 Read-Write
                            # ("SNMP Version", "2"),
                            # ("Enable SNMP", "True"),
                            # ("Disable SNMP", "False"),
                            # ("SNMP Write Community", "public"),
                            # End SNMP v2 Read-Write

                            # SNMP v3
                            ("SNMP Version", "3"),
                            ("Enable SNMP", "True"),
                            ("Disable SNMP", "True"),
                            ("SNMP V3 User", "quali"),
                            ("SNMP V3 Password", "qualipass"),
                            ("SNMP V3 Private Key", "qualipass2"),
                            ("SNMP V3 Authentication Protocol", "No Authentication Protocol"),
                            # "No Authentication Protocol", "MD5", "SHA"
                            ("SNMP V3 Privacy Protocol", "No Privacy Protocol"),
                            # "No Privacy Protocol", "DES", "3DES-EDE", "AES-128", "AES-192", "AES-256"
                            # End SNMP v3

                            ("Sessions Concurrency Limit", 1),
                            ("CLI Connection Type", "SSH"),
                            ("Password", password),
                            ("Enable Password", password)]:

            context.resource.attributes["{}.{}".format(CumulusLinuxSwitchShell2GDriver.SHELL_NAME, attr)] = value
            context.connectivity = mock.MagicMock()
            context.connectivity.server_address = "192.168.85.10"

        return context
Exemple #12
0
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,
    )