def resource_command_context(self, resource_name: Optional[str] = None,
                              service_name: Optional[str] = None) -> ResourceCommandContext:
     """ Create ResourceCommandContext for the given resource/service. """
     self.attach_to_cloudshell_as(resource_name, service_name)
     reservation = script_helpers.get_reservation_context_details()
     resource = script_helpers.get_resource_context_details()
     connectivity = ConnectivityContext(self.session.host, '8029', '9000', self.session.token_id, '9.1',
                                        CloudShellSessionContext.DEFAULT_API_SCHEME)
     return ResourceCommandContext(connectivity, resource, reservation, [])
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, [])
        Destroy the driver session, this function is called every time a driver instance is destroyed
        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
Esempio n. 5
0
reservation_description = session.GetReservationDetails(
    reservation_context.id).ReservationDescription
services = reservation_description.Services
connectors = reservation_description.Connectors
context_connectors = [
    conn for conn in connectors
    if resource_context.name in [conn.Source, conn.Target]
]
context_connectors_reformatted = []
for conn in context_connectors:
    temp_connector = Connector(source=conn.Source,
                               target=conn.Target,
                               alias=conn.Alias,
                               attributes=conn.Attributes,
                               connection_type=conn.Type,
                               direction=conn.Direction,
                               targetFamily='',
                               targetAttributes='',
                               targetType='',
                               targetModel='')
    context_connectors_reformatted.append(temp_connector)

context = ResourceCommandContext(connectivity=connectivity_context,
                                 resource=sh.get_resource_context_details(),
                                 reservation=reservation_context,
                                 connectors=context_connectors_reformatted)

myclass = driver.UptimeEnforcerDriver()
myclass.check_uptime_status(context)
pass
    environment_name=reservation_context_details.environment_name,
    environment_path=reservation_context_details.environment_path,
    domain=reservation_context_details.domain,
    description=reservation_context_details.description,
    owner_user=reservation_context_details.owner_user,
    owner_email="*****@*****.**",
    reservation_id=reservation_context_details.id,
    saved_sandbox_name="",
    saved_sandbox_id="",
    running_user="")

connectivity_context_details = sh.get_connectivity_context_details()
cs_api_port = connectivity_context_details.cloudshell_api_port
connectivity_context = ConnectivityContext(server_address=CS_SERVER,
                                           cloudshell_api_port=cs_api_port,
                                           quali_api_port="9000",
                                           admin_auth_token=token,
                                           cloudshell_version="9.3",
                                           cloudshell_api_scheme="")

context = ResourceCommandContext(connectivity=connectivity_context,
                                 resource=resource_context_details,
                                 reservation=reservation_context,
                                 connectors=[])

debug_driver_instance = my_driver.ComputeDemoDriver()
# res = debug_driver_instance.send_custom_command(context, "ifconfig")
res = debug_driver_instance.get_all_ips(context)
print(res)
pass
    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
Esempio n. 8
0
def resource_context(connectivity_context, resource_context_details,
                     reservation_context_details):
    return ResourceCommandContext(connectivity_context,
                                  resource_context_details,
                                  reservation_context_details, [])
Esempio n. 9
0
from cloudshell.shell.core.driver_context import InitCommandContext, AutoLoadCommandContext, ResourceCommandContext, \
    AutoLoadAttribute, AutoLoadDetails, CancellationContext, ResourceRemoteCommandContext
from cloudshell.shell.core.resource_driver_interface import ResourceDriverInterface

# Debug Script

# with open(r'c:\temp\HWC_Debug_creds', 'r') as debug_file:
#     my_debug_file = debug_file.read()

dev_help.attach_to_cloudshell_as(
    user='******',
    password='******',
    domain='Global',
    reservation_id='c3f09270-58a6-4188-a11d-19239d73a0d8',
    server_address='192.168.85.15',
    resource_name='HWC')
driver_interface = ResourceDriverInterface

context = ResourceCommandContext(
    connectivity=script_help.get_connectivity_context_details(),
    reservation=script_help.get_reservation_context_details(),
    resource=script_help.get_resource_context_details(),
    connectors=None)
with open('request.json', 'r') as file:
    my_request = json.load(file)

my_hwc_driver = driver.HuaweicloudDriver()
my_hwc_driver.initialize(context)
my_hwc_driver.Deploy(context, request=my_request)
pass