当前位置: 首页>>代码示例>>Python>>正文


Python sshClient.SshClient类代码示例

本文整理汇总了Python中marvin.sshClient.SshClient的典型用法代码示例。如果您正苦于以下问题:Python SshClient类的具体用法?Python SshClient怎么用?Python SshClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SshClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_process_status

def get_process_status(hostip, port, username, password, linklocalip, process, hypervisor=None):
    """Double hop and returns a process status"""

    #SSH to the machine
    ssh = SshClient(hostip, port, username, password)
    if (str(hypervisor).lower() == 'vmware'
		or str(hypervisor).lower() == 'hyperv'):
        ssh_command = "ssh -i /var/cloudstack/management/.ssh/id_rsa -ostricthostkeychecking=no "
    else:
        ssh_command = "ssh -i ~/.ssh/id_rsa.cloud -ostricthostkeychecking=no "

    ssh_command = ssh_command +\
                  "-oUserKnownHostsFile=/dev/null -p 3922 %s %s" % (
                      linklocalip,
                      process)

    # Double hop into router
    if str(hypervisor).lower() == 'hyperv':
        timeout = 12
    else:
        timeout = 5
    # Ensure the SSH login is successful
    while True:
        res = ssh.execute(ssh_command)
        if "Connection refused".lower() in res[0].lower():
            pass
        elif res[0] != "Host key verification failed.":
            break
        elif timeout == 0:
            break

        time.sleep(5)
        timeout = timeout - 1
    return res
开发者ID:Tosta-Mixta,项目名称:cloudstack,代码行数:34,代码来源:utils.py

示例2: download_systemplates_sec_storage

def download_systemplates_sec_storage(server, services):
    """Download System templates on sec storage"""

    try:
        # Login to management server
        ssh = SshClient(server["ipaddress"], server["port"], server["username"], server["password"])
    except Exception:
        raise Exception("SSH access failed for server with IP address: %s" % server["ipaddess"])
    # Mount Secondary Storage on Management Server
    cmds = [
        "mkdir -p %s" % services["mnt_dir"],
        "mount -t nfs %s:/%s %s" % (services["sec_storage"], services["path"], services["mnt_dir"]),
        "%s -m %s -u %s -h %s -F"
        % (services["command"], services["mnt_dir"], services["download_url"], services["hypervisor"]),
    ]
    for c in cmds:
        result = ssh.execute(c)

    res = str(result)

    # Unmount the Secondary storage
    ssh.execute("umount %s" % (services["mnt_dir"]))

    if res.count("Successfully installed system VM template") == 1:
        return
    else:
        raise Exception("Failed to download System Templates on Sec Storage")
    return
开发者ID:rafaelthedevops,项目名称:cloudstack,代码行数:28,代码来源:common.py

示例3: setUp

    def setUp(self):
        self.apiclient = self.testClient.getApiClient()
        self.dbclient = self.testClient.getDbConnection()
        self.mgtSvrDetails = self.config.__dict__["mgtSvr"][0].__dict__
        self.cleanup = []
        self.testdata = {
            "account": {
                "email": "[email protected]",
                "firstname": "Marvin",
                "lastname": "TestUser",
                "username": "staticrole_acctest-",
                "password": "password",
            }
        }

        feature_enabled = self.apiclient.listCapabilities(listCapabilities.listCapabilitiesCmd()).dynamicrolesenabled
        if feature_enabled:
            self.skipTest("Dynamic role-based API checker is enabled, skipping tests for static role-base API checker")

        commandsProperties = []
        try:
            sshClient = SshClient(
                self.mgtSvrDetails["mgtSvrIp"],
                22,
                self.mgtSvrDetails["user"],
                self.mgtSvrDetails["passwd"],
                retries=1,
                log_lvl=logging.INFO
            )
            result = sshClient.runCommand("cat /etc/cloudstack/management/commands.properties")
            if 'status' in result and result['status'] == 'SUCCESS' and 'stdout' in result and len(result['stdout']) > 0:
                commandsProperties = result['stdout']
        except Exception:
            self.debug("Failed to ssh into mgmt server host and grab commands.properties file")
            testDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
            localFileName = os.path.abspath(testDir + "/../../../client/tomcatconf/commands.properties.in")
            if os.path.isfile(localFileName):
                self.info("Detected that we're running in developer mode with maven, using file at:" + localFileName)
                with open(localFileName) as f:
                    commandsProperties = f.readlines()

        if len(commandsProperties) < 1:
            self.skipTest("Unable to find commands.properties, skipping this test")

        apiMap = {}
        for line in commandsProperties:
            if not line or line == '' or line == '\n' or line.startswith('#'):
                continue
            name, value = line.split('=')
            apiMap[name.strip()] = value.strip()

        self.roleApiMap = {} # role to list of apis allowed
        octetKey = {'Admin':1, 'DomainAdmin':4, 'User':8}
        for role in octetKey.keys():
            for api in sorted(apiMap.keys()):
                if (octetKey[role] & int(apiMap[api])) > 0:
                    if role not in self.roleApiMap:
                        self.roleApiMap[role] = []
                    self.roleApiMap[role].append(api)
开发者ID:CIETstudents,项目名称:cloudstack,代码行数:59,代码来源:test_staticroles.py

示例4: RestartServers

 def RestartServers(self):
     """ Restart management
     server and usage server """
     sshClient = SshClient(
         self.mgtSvrDetails["mgtSvrIp"], 22, self.mgtSvrDetails["user"], self.mgtSvrDetails["passwd"]
     )
     command = "service cloudstack-management restart"
     sshClient.execute(command)
     return
开发者ID:bheuvel,项目名称:cloudstack,代码行数:9,代码来源:test_vpc.py

示例5: checkHostUp

 def checkHostUp(self, fromHostIp, testHostIp):
     try:
         ssh = SshClient(fromHostIp, 22, "root", "password") 
         res = ssh.execute("ping -c 1 %s" % testHostIp)
         result = str(res)
         if result.count(" 0% packet loss") == 1:
             return True, 1
         else:
             return False, 1
     except Exception as e:
         self.logger.debug("Got exception %s" % e)
         return False, 1
开发者ID:PCextreme,项目名称:cloudstack,代码行数:12,代码来源:test_host.py

示例6: restartUsageServer

def restartUsageServer(self):
    #Restart usage server

    sshClient = SshClient(
        self.mgtSvrDetails["mgtSvrIp"],
        22,
        self.mgtSvrDetails["user"],
        self.mgtSvrDetails["passwd"]
    )
    command = "service cloudstack-usage restart"
    sshClient.execute(command)
    return
开发者ID:PCextreme,项目名称:cloudstack,代码行数:12,代码来源:test_ss_volume_usage.py

示例7: RestartServer

    def RestartServer(cls):
        """Restart management server"""

        sshClient = SshClient(
                cls.mgtSvrDetails["mgtSvrIp"],
                22,
                cls.mgtSvrDetails["user"],
                cls.mgtSvrDetails["passwd"]
                )
        command = "service cloudstack-management restart"
        sshClient.execute(command)

        return
开发者ID:rarotonga82,项目名称:cloudstack,代码行数:13,代码来源:testpath_same_vm_name.py

示例8: try_ssh

    def try_ssh(self, ip_addr, hostnames):
        try:
            self.debug("SSH into NAT Rule (Public IP: %s)" % ip_addr)

            # If Round Robin Algorithm is chosen,
            # each ssh command should alternate between VMs

            ssh_1 = SshClient(ip_addr, 22, self.services["natrule"]["username"], self.services["natrule"]["password"])
            hostnames.append(ssh_1.execute("hostname")[0])
            self.debug(hostnames)
        except Exception as e:
            self.fail("%s: SSH failed for VM with IP Address: %s" % (e, ip_addr))
        return hostnames
开发者ID:ktenzer,项目名称:cloudstack,代码行数:13,代码来源:test_haproxy.py

示例9: setUpClass

    def setUpClass(self):
        testClient = super(TestDeployvGPUenabledVM, self).getClsTestClient()
        self.apiclient = testClient.getApiClient()
        self.testdata = self.testClient.getParsedTestDataConfig()
        self._cleanup = []
        self.unsupportedHypervisor = False
        self.noSuitableHost = False
        # Need to add check whether zone containing the xen hypervisor or not
        # as well
        hosts = list_hosts(
            self.apiclient,
            hypervisor="XenServer"
        )
        if hosts is None:
             # GPU feature is supported only on XenServer.Check listhosts response
             self.unsupportedHypervisor = True
             return
        else:
            gpuhosts = 0
            for ghost in hosts:
                if ghost.hypervisorversion >= "6.2.0":
                    sshClient = SshClient(
                        host=ghost.ipaddress,
                        port=self.testdata['configurableData']['host']["publicport"],
                        user=self.testdata['configurableData']['host']["username"],
                        passwd=self.testdata['configurableData']['host']["password"])
                    if ghost.hypervisorversion == "6.2.0":
                        res = sshClient.execute(
                            "xe patch-list uuid=0850b186-4d47-11e3-a720-001b2151a503")
                        if len(res) == 0:
                            continue
                    res = sshClient.execute(
                        "xe vgpu-type-list model-name=\"GRID K120Q\"")
                    if len(res) != 0:
                        gpuhosts = gpuhosts + 1
                    else:
                        continue
        if gpuhosts == 0:
            # No XenServer available with GPU Drivers installed
            self.noSuitableHost = True
            return

        self.domain = get_domain(self.apiclient)
        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
        # Creating Account
        self.account = Account.create(
            self.apiclient,
            self.testdata["account"],
            domainid=self.domain.id
        )
        self._cleanup.append(self.account)
开发者ID:nvazquez,项目名称:cloudstack,代码行数:51,代码来源:test_deploy_vgpu_enabled_vm.py

示例10: test_es_1236_cloudstack_sccs

 def test_es_1236_cloudstack_sccs(self):
     """
     @Desc: Test whether cloudstack-sccs is available on management server
     @Steps:
     Step1: run cloudstack-sccs on management server
     Step2: It should return a commit hash
     """
     # Step1: run cloudstack-sccs on management server
     mgmt_ssh = SshClient(
         self.apiClient.connection.mgtSvr, 22, self.apiClient.connection.user, self.apiClient.connection.passwd
     )
     res = mgmt_ssh.execute("cloudstack-sccs")
     # Step2: It should return a commit hash
     return
开发者ID:maksimov,项目名称:cloudstack,代码行数:14,代码来源:test_bugs.py

示例11: test_multiple_mgmt_srvr_session_timeout

    def test_multiple_mgmt_srvr_session_timeout(self):
        """
        @Desc: Check whether mgmt server session times out with in 30s
        @Steps:
        Step1: run 'telnet localhot 8250' on the management server
        and see that it times out with in 30seconds
        """
        # Step1: run cloudstack-sccs on management server
        mgmt_ssh = SshClient(
            self.apiClient.connection.mgtSvr, 22, self.apiClient.connection.user, self.apiClient.connection.passwd
        )
        res = mgmt_ssh.execute("time telnet localhost 8250")

        # Step2: It should return a commit hash
        return
开发者ID:maksimov,项目名称:cloudstack,代码行数:15,代码来源:test_bugs.py

示例12: _execute_ssh_command

def _execute_ssh_command(hostip, port, username, password, ssh_command):
    #SSH to the machine
    ssh = SshClient(hostip, port, username, password)
    # Ensure the SSH login is successful
    while True:
        res = ssh.execute(ssh_command)
        if "Connection refused".lower() in res[0].lower():
            pass
        elif res[0] != "Host key verification failed.":
            break
        elif timeout == 0:
            break

        time.sleep(5)
        timeout = timeout - 1
    return res
开发者ID:DKrul,项目名称:cloudstack,代码行数:16,代码来源:utils.py

示例13: ssh_kvm_host

def ssh_kvm_host(password, ipaddr, instance_name):
    """Ssh into kvm host and get vm mem details"""
    mem = []
    sshClient = SshClient(
        ipaddr,
        22,
        "root",
        password
    )

    command = "virsh dominfo %s" % instance_name
    vm_detail = sshClient.execute(command)
    max = vm_detail[7].split()
    min = vm_detail[8].split()
    mem.append(int(max[2]))
    mem.append(int(min[2]))
    return mem
开发者ID:Accelerite,项目名称:cloudstack,代码行数:17,代码来源:test_overcommit.py

示例14: ssh_xen_host

def ssh_xen_host(password, ipaddr, instance_name):
    """Ssh into xen host and get vm mem details"""
    mem = []
    sshClient = SshClient(
        ipaddr,
        22,
        "root",
        password
    )
    command = "xe vm-list params=all name-label=%s" % instance_name
    vm_detail = sshClient.execute(command)
    max_str = vm_detail[17].split(":")
    min_str = vm_detail[20].split(":")
    max = int(max_str[1])
    min = int(min_str[1])
    mem.append(max)
    mem.append(min)
    return mem
开发者ID:Accelerite,项目名称:cloudstack,代码行数:18,代码来源:test_overcommit.py

示例15: restartServer

    def restartServer(cls):
        """Restart management server"""

        sshClient = SshClient(
                    cls.mgtSvrDetails["mgtSvrIp"],
            22,
            cls.mgtSvrDetails["user"],
            cls.mgtSvrDetails["passwd"]
        )
        command = "service cloudstack-management stop"
        sshClient.execute(command)

        command = "service cloudstack-management start"
        sshClient.execute(command)

        #time.sleep(cls.services["sleep"])
        time.sleep(300)

        return
开发者ID:krissterckx,项目名称:cloudstack,代码行数:19,代码来源:test_deploy_vm_root_resize.py


注:本文中的marvin.sshClient.SshClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。