本文整理汇总了Python中ovs.extensions.generic.sshclient.SSHClient类的典型用法代码示例。如果您正苦于以下问题:Python SSHClient类的具体用法?Python SSHClient怎么用?Python SSHClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SSHClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_extra_node
def add_extra_node(**kwargs):
ip = kwargs['cluster_ip']
license_contents = []
for lic in LicenseList.get_licenses():
license_contents.append(lic.hash)
client = SSHClient(ip)
client.file_write('/opt/OpenvStorage/config/licenses', '{0}\n'.format('\n'.join(license_contents)))
示例2: system_services_check_test
def system_services_check_test():
"""
Verify some system services
"""
services_to_commands = {
"nginx": """ps -efx|grep nginx|grep -v grep""",
"rabbitmq-server": """ps -ef|grep rabbitmq-|grep -v grep""",
"memcached": """ps -ef|grep memcached|grep -v grep""",
"ovs-arakoon-ovsdb": """initctl list| grep ovsdb""",
"ovs-snmp": """initctl list| grep ovs-snmp""",
"ovs-support-agent": """initctl list| grep support""",
"ovs-volumerouter-consumer": """initctl list| grep volumerou""",
"ovs-watcher-framework": """initctl list| grep watcher-fr"""
}
errors = ''
services_checked = 'Following services found running:\n'
grid_ip = General.get_config().get('main', 'grid_ip')
ssh_pass = General.get_config().get('mgmtcenter', 'password')
client = SSHClient(grid_ip, username='root', password=ssh_pass)
for service_to_check in services_to_commands.iterkeys():
out, err = client.run(services_to_commands[service_to_check], debug=True)
if len(err):
errors += "Error when trying to run {0}:\n{1}".format(services_to_commands[service_to_check], err)
else:
if len(out):
services_checked += "{0}\n".format(service_to_check)
else:
errors += "Couldn't find {0} running process\n".format(service_to_check)
print services_checked
assert len(errors) == 0, "Found the following errors while checking for the system services:{0}\n".format(errors)
示例3: setup
def setup():
"""
Setup for Arakoon package, will be executed when any test in this package is being executed
Make necessary changes before being able to run the tests
:return: None
"""
autotest_config = General.get_config()
backend_name = autotest_config.get('backend', 'name')
assert backend_name, 'Please fill out a backend name in the autotest.cfg file'
backend = GeneralBackend.get_by_name(backend_name)
if backend is not None:
GeneralAlba.remove_alba_backend(backend.alba_backend)
for storagerouter in GeneralStorageRouter.get_masters():
root_client = SSHClient(storagerouter, username='root')
if GeneralService.get_service_status(name='ovs-scheduled-tasks',
client=root_client) is True:
GeneralService.stop_service(name='ovs-scheduled-tasks',
client=root_client)
storagerouters = GeneralStorageRouter.get_storage_routers()
for sr in storagerouters:
root_client = SSHClient(sr, username='root')
GeneralDisk.add_db_role(sr)
for location in TEST_CLEANUP:
root_client.run('rm -rf {0}'.format(location))
GeneralAlba.add_alba_backend(backend_name)
GeneralArakoon.voldrv_arakoon_checkup()
示例4: create_cluster
def create_cluster(cluster_name, ip, exclude_ports, base_dir, plugins=None):
"""
Creates a cluster
"""
logger.debug("Creating cluster {0} on {1}".format(cluster_name, ip))
client = SSHClient(ip)
base_dir = base_dir.rstrip("/")
port_range = client.config_read("ovs.ports.arakoon")
ports = System.get_free_ports(port_range, exclude_ports, 2, client)
node_name = System.get_my_machine_id(client)
config = ArakoonClusterConfig(cluster_name, plugins)
if not [node.name for node in config.nodes if node.name == node_name]:
config.nodes.append(
ArakoonNodeConfig(
name=node_name,
ip=ip,
client_port=ports[0],
messaging_port=ports[1],
log_dir=ArakoonInstaller.ARAKOON_LOG_DIR.format(cluster_name),
home=ArakoonInstaller.ARAKOON_HOME_DIR.format(base_dir, cluster_name),
tlog_dir=ArakoonInstaller.ARAKOON_TLOG_DIR.format(base_dir, cluster_name),
)
)
ArakoonInstaller._deploy(config)
logger.debug("Creating cluster {0} on {1} completed".format(cluster_name, ip))
return {"client_port": ports[0], "messaging_port": ports[1]}
示例5: system_services_check_test
def system_services_check_test():
"""
Verify some system services
"""
services_to_commands = {
"nginx": """ps -efx|grep nginx|grep -v grep""",
"rabbitmq-server": """ps -ef|grep rabbitmq-|grep -v grep""",
"memcached": """ps -ef|grep memcached|grep -v grep""",
}
errors = ''
services_checked = 'Following services found running:\n'
grid_ip = General.get_config().get('main', 'grid_ip')
ssh_pass = General.get_config().get('mgmtcenter', 'password')
client = SSHClient(grid_ip, username='root', password=ssh_pass)
for service_to_check in services_to_commands.iterkeys():
out, err = client.run(services_to_commands[service_to_check], debug=True, allow_insecure=True,
return_stderr=True)
if len(err):
errors += "Error when trying to run {0}:\n{1}".format(services_to_commands[service_to_check], err)
else:
if len(out):
services_checked += "{0}\n".format(service_to_check)
else:
errors += "Couldn't find {0} running process\n".format(service_to_check)
for non_running_service in GeneralSystem.list_non_running_ovs_services(grid_ip):
errors += str(non_running_service)
assert len(errors) == 0,\
"Found the following errors while checking for the system services:{0}\n".format(errors)
示例6: shrink_cluster
def shrink_cluster(remaining_node_ip, ip_to_remove, cluster_name, offline_node_ips=None):
"""
Removes a node from a cluster, the old node will become a slave
:param cluster_name: The name of the cluster to shrink
:param ip_to_remove: The ip of the node that should be removed from the cluster
:param remaining_node_ip: The ip of a remaining node in the cluster
:param offline_node_ips: IPs of offline nodes
"""
logger.debug('Shrinking cluster "{0}" from {1}'.format(cluster_name, ip_to_remove))
current_client = SSHClient(remaining_node_ip, username='root')
if not EtcdInstaller._is_healty(cluster_name, current_client):
raise RuntimeError('Cluster "{0}" unhealthy, aborting shrink'.format(cluster_name))
node_id = None
for item in current_client.run('etcdctl member list').splitlines():
info = re.search(EtcdInstaller.MEMBER_REGEX, item).groupdict()
if EtcdInstaller.CLIENT_URL.format(ip_to_remove) == info['client']:
node_id = info['id']
if node_id is not None:
current_client.run('etcdctl member remove {0}'.format(node_id))
if ip_to_remove not in offline_node_ips:
EtcdInstaller.deploy_to_slave(remaining_node_ip, ip_to_remove, cluster_name, force=True)
EtcdInstaller.wait_for_cluster(cluster_name, current_client)
logger.debug('Shrinking cluster "{0}" from {1} completed'.format(cluster_name, ip_to_remove))
示例7: test_single_node
def test_single_node(self):
node = sorted(TestArakoonInstaller.nodes.keys())[0]
result = ArakoonInstaller.create_cluster(TestArakoonInstaller.cluster_name, node, '/tmp/db')
contents = SSHClient(node).file_read(TestArakoonInstaller.cluster_config_file)
expected = TestArakoonInstaller.expected_global.format(TestArakoonInstaller.nodes[node], TestArakoonInstaller.cluster_name)
expected += TestArakoonInstaller.expected_base.format(TestArakoonInstaller.nodes[node], result['client_port'], result['messaging_port'], TestArakoonInstaller.cluster_name, node)
self.assertEqual(contents.strip(), expected.strip())
示例8: write_to_volume
def write_to_volume(vdisk=None, vpool=None, location=None, count=1024, bs='1M', input_type='random',
root_client=None):
"""
Write some data to a file
:param vdisk: Virtual disk to write on
:param vpool: vPool which hosts the Virtual Disk
:param location: Absolute path to file
:param count: amount of blocks to write
:param bs: Size of the blocks to write
:param input_type: Type of input (null, zero, random)
:param root_client: SSHClient object
:return: None
"""
if location is None and (vdisk is None or vpool is None):
raise ValueError('vDisk and vPool must be provided if no location has been provided')
if location is None:
location = GeneralVDisk.get_filesystem_location(vpool=vpool,
vdisk_name=vdisk.name)
if root_client is None:
root_client = SSHClient('127.0.0.1', username='root')
if input_type not in ('null', 'zero', 'random'):
raise ValueError('Invalid input type provided')
if General.check_file_is_link(location, root_client.ip, root_client.username, root_client.password):
print "Writing to {0}".format(root_client.file_read_link(location))
else:
if not root_client.file_exists(location):
raise ValueError('File {0} does not exist on Storage Router {1}'.format(location, root_client.ip))
if not isinstance(count, int) or count < 1:
raise ValueError('Count must be an integer > 0')
root_client.run('dd conv=notrunc if=/dev/{0} of={1} bs={2} count={3}'.format(input_type, location, bs, count))
示例9: has_cluster
def has_cluster(ip, cluster_name):
logger.debug('Checking whether {0} has cluster "{1}" running'.format(ip, cluster_name))
client = SSHClient(ip, username='root')
try:
return client.run('etcdctl member list').strip() != ''
except CalledProcessError:
return False
示例10: collapse_arakoon
def collapse_arakoon():
"""
Collapse Arakoon's Tlogs
:return: None
"""
logger.info('Starting arakoon collapse')
arakoon_clusters = {}
for service in ServiceList.get_services():
if service.type.name in ('Arakoon', 'NamespaceManager', 'AlbaManager'):
arakoon_clusters[service.name.replace('arakoon-', '')] = service.storagerouter
for cluster, storagerouter in arakoon_clusters.iteritems():
logger.info(' Collapsing cluster {0}'.format(cluster))
client = SSHClient(storagerouter)
parser = client.rawconfig_read(PyrakoonStore.ARAKOON_CONFIG_FILE.format(cluster))
nodes = {}
for node in parser.get('global', 'cluster').split(','):
node = node.strip()
nodes[node] = ([parser.get(node, 'ip')], parser.get(node, 'client_port'))
config = ArakoonClientConfig(str(cluster), nodes)
for node in nodes.keys():
logger.info(' Collapsing node: {0}'.format(node))
client = ArakoonAdminClient(node, config)
try:
client.collapse_tlogs(2)
except:
logger.exception('Error during collapsing cluster {0} node {1}'.format(cluster, node))
logger.info('Arakoon collapse finished')
示例11: teardown
def teardown():
"""
Teardown for Arakoon package, will be executed when all started tests in this package have ended
Removal actions of possible things left over after the test-run
:return: None
"""
autotest_config = General.get_config()
backend_name = autotest_config.get('backend', 'name')
backend = GeneralBackend.get_by_name(backend_name)
if backend is not None:
GeneralAlba.remove_alba_backend(backend.alba_backend)
for storagerouter in GeneralStorageRouter.get_masters():
root_client = SSHClient(storagerouter, username='root')
if GeneralService.get_service_status(name='ovs-scheduled-tasks',
client=root_client) is False:
GeneralService.start_service(name='ovs-scheduled-tasks',
client=root_client)
for location in TEST_CLEANUP:
root_client.run('rm -rf {0}'.format(location))
for key in KEY_CLEANUP:
if EtcdConfiguration.exists('{0}/{1}'.format(GeneralArakoon.ETCD_CONFIG_ROOT, key), raw = True):
EtcdConfiguration.delete('{0}/{1}'.format(GeneralArakoon.ETCD_CONFIG_ROOT, key))
示例12: extend_cluster
def extend_cluster(master_ip, new_ip, cluster_name, exclude_ports, base_dir):
"""
Extends a cluster to a given new node
"""
logger.debug("Extending cluster {0} from {1} to {2}".format(cluster_name, master_ip, new_ip))
client = SSHClient(master_ip)
config = ArakoonClusterConfig(cluster_name)
config.load_config(client)
client = SSHClient(new_ip)
base_dir = base_dir.rstrip("/")
port_range = client.config_read("ovs.ports.arakoon")
ports = System.get_free_ports(port_range, exclude_ports, 2, client)
node_name = System.get_my_machine_id(client)
if not [node.name for node in config.nodes if node.name == node_name]:
config.nodes.append(
ArakoonNodeConfig(
name=node_name,
ip=new_ip,
client_port=ports[0],
messaging_port=ports[1],
log_dir=ArakoonInstaller.ARAKOON_LOG_DIR.format(cluster_name),
home=ArakoonInstaller.ARAKOON_HOME_DIR.format(base_dir, cluster_name),
tlog_dir=ArakoonInstaller.ARAKOON_TLOG_DIR.format(base_dir, cluster_name),
)
)
ArakoonInstaller._deploy(config)
logger.debug("Extending cluster {0} from {1} to {2} completed".format(cluster_name, master_ip, new_ip))
return {"client_port": ports[0], "messaging_port": ports[1]}
示例13: config_files_check_test
def config_files_check_test():
"""
Verify some configuration files
"""
issues_found = ''
config_keys = {
"/ovs/framework/memcache",
"/ovs/arakoon/ovsdb/config"
}
for key_to_check in config_keys:
if not Configuration.exists(key_to_check, raw=True):
issues_found += "Couldn't find {0}\n".format(key_to_check)
config_files = {
"rabbitmq.config": "/etc/rabbitmq/rabbitmq.config",
}
grid_ip = General.get_config().get('main', 'grid_ip')
ssh_pass = General.get_config().get('mgmtcenter', 'password')
client = SSHClient(grid_ip, username='root', password=ssh_pass)
for config_file_to_check in config_files.iterkeys():
if not client.file_exists(config_files[config_file_to_check]):
issues_found += "Couldn't find {0}\n".format(config_file_to_check)
assert issues_found == '',\
"Found the following issues while checking for the config files:{0}\n".format(issues_found)
示例14: unpartition_disk
def unpartition_disk(disk, partitions=None, wait=True):
"""
Return disk to RAW state
:param disk: Disk DAL object
:param partitions: Partitions DAL object list
:return: None
"""
if partitions is None:
partitions = disk.partitions
else:
for partition in partitions:
if partition not in disk.partitions:
raise RuntimeError('Partition {0} does not belong to disk {1}'.format(partition.mountpoint, disk.name))
if len(disk.partitions) == 0:
return
root_client = SSHClient(disk.storagerouter, username='root')
for partition in partitions:
General.unmount_partition(root_client, partition)
root_client.run(['parted', '-s', '/dev/' + disk.name, 'mklabel', 'gpt'])
GeneralStorageRouter.sync_with_reality(disk.storagerouter)
counter = 0
timeout = 60
while counter < timeout:
time.sleep(1)
disk = GeneralDisk.get_disk(guid=disk.guid)
if len(disk.partitions) == 0:
break
counter += 1
if counter == timeout:
raise RuntimeError('Removing partitions failed for disk:\n {0} '.format(disk.name))
示例15: deploy_to_slave
def deploy_to_slave(master_ip, slave_ip, cluster_name, client_port=DEFAULT_CLIENT_PORT):
"""
Deploys the configuration file to a slave
:param master_ip: IP of the node to deploy from
:type master_ip: str
:param slave_ip: IP of the slave to deploy to
:type slave_ip: str
:param cluster_name: Name of the cluster of which to deploy the configuration file
:type cluster_name: str
:param client_port: Port to be used by client
:type client_port: int
:return: None
"""
EtcdInstaller._logger.debug(' Setting up proxy "{0}" from {1} to {2}'.format(cluster_name, master_ip, slave_ip))
master_client = SSHClient(master_ip, username='root')
slave_client = SSHClient(slave_ip, username='root')
current_cluster = []
list_command = ['etcdctl', 'member', 'list']
if client_port != EtcdInstaller.DEFAULT_CLIENT_PORT:
list_command = ['etcdctl', '--peers={0}:{1}'.format(master_ip, client_port), 'member', 'list']
for item in master_client.run(list_command).splitlines():
info = re.search(EtcdInstaller.MEMBER_REGEX, item).groupdict()
current_cluster.append('{0}={1}'.format(info['name'], info['peer']))
EtcdInstaller._setup_proxy(','.join(current_cluster), slave_client, cluster_name, force=True)
EtcdInstaller._logger.debug(' Setting up proxy "{0}" from {1} to {2} completed'.format(cluster_name, master_ip, slave_ip))