本文整理汇总了Python中ovs.extensions.generic.sshclient.SSHClient.dir_list方法的典型用法代码示例。如果您正苦于以下问题:Python SSHClient.dir_list方法的具体用法?Python SSHClient.dir_list怎么用?Python SSHClient.dir_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovs.extensions.generic.sshclient.SSHClient
的用法示例。
在下文中一共展示了SSHClient.dir_list方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: archive_existing_arakoon_data
# 需要导入模块: from ovs.extensions.generic.sshclient import SSHClient [as 别名]
# 或者: from ovs.extensions.generic.sshclient.SSHClient import dir_list [as 别名]
def archive_existing_arakoon_data(ip, directory, top_dir, cluster_name):
"""
Copy existing arakoon data, when setting up a new arakoon cluster, to the side
:param ip: IP on which to check for existing data
:param directory: Directory to check for existence
:param top_dir: Top directory
:param cluster_name: Name of arakoon cluster
:return: None
"""
new_client = SSHClient(ip)
logger.debug('archive - check if {0} exists'.format(directory))
if new_client.dir_exists(directory):
logger.debug('archive - from {0}'.format(directory))
archive_dir = '/'.join([top_dir, 'archive', cluster_name])
if new_client.dir_exists(archive_dir + '/' + os.path.basename(directory)):
logger.debug('archive - from existing archive {0}'.format(archive_dir))
timestamp = time.strftime('%Y%m%d%H%M%S', time.gmtime())
new_archive_dir = archive_dir + '-' + timestamp
new_client.dir_create(new_archive_dir)
new_client.run('mv {0} {1}'.format(archive_dir, new_archive_dir))
logger.debug('archive - to new {0}'.format(new_archive_dir))
logger.debug('create archive dir: {0}'.format(archive_dir))
new_client.dir_create(archive_dir)
logger.debug('archive from {0} to {1}'.format(directory, archive_dir))
if cluster_name == os.path.basename(directory) and new_client.dir_list(directory):
new_client.run('mv {0}/* {1}'.format(directory, archive_dir))
else:
new_client.run('mv {0} {1}'.format(directory, archive_dir))
示例2: migrate
# 需要导入模块: from ovs.extensions.generic.sshclient import SSHClient [as 别名]
# 或者: from ovs.extensions.generic.sshclient.SSHClient import dir_list [as 别名]
def migrate(previous_version, master_ips=None, extra_ips=None):
"""
Migrates from any version to any version, running all migrations required
If previous_version is for example 0 and this script is at
verison 3 it will execute two steps:
- 1 > 2
- 2 > 3
:param previous_version: The previous version from which to start the migration.
:param master_ips: IP addresses of the MASTER nodes
:param extra_ips: IP addresses of the EXTRA nodes
"""
working_version = previous_version
# Version 1 introduced:
# - Flexible SSD layout
if working_version < 1:
from ovs.extensions.generic.configuration import Configuration
if Configuration.exists('ovs.arakoon'):
Configuration.delete('ovs.arakoon', remove_root=True)
Configuration.set('ovs.core.ovsdb', '/opt/OpenvStorage/db')
working_version = 1
# Version 2 introduced:
# - Registration
if working_version < 2:
import time
from ovs.extensions.generic.configuration import Configuration
if not Configuration.exists('ovs.core.registered'):
Configuration.set('ovs.core.registered', False)
Configuration.set('ovs.core.install_time', time.time())
working_version = 2
# Version 3 introduced:
# - New arakoon clients
if working_version < 3:
from ovs.extensions.db.arakoon import ArakoonInstaller
reload(ArakoonInstaller)
from ovs.extensions.db.arakoon import ArakoonInstaller
from ovs.extensions.generic.sshclient import SSHClient
from ovs.extensions.generic.configuration import Configuration
if master_ips is not None:
for ip in master_ips:
client = SSHClient(ip)
if client.dir_exists(ArakoonInstaller.ArakoonInstaller.ARAKOON_CONFIG_DIR):
for cluster_name in client.dir_list(ArakoonInstaller.ArakoonInstaller.ARAKOON_CONFIG_DIR):
try:
ArakoonInstaller.ArakoonInstaller.deploy_cluster(cluster_name, ip)
except:
pass
if Configuration.exists('ovs.core.storage.persistent'):
Configuration.set('ovs.core.storage.persistent', 'pyrakoon')
working_version = 3
return working_version
示例3: sync_with_reality
# 需要导入模块: from ovs.extensions.generic.sshclient import SSHClient [as 别名]
# 或者: from ovs.extensions.generic.sshclient.SSHClient import dir_list [as 别名]
def sync_with_reality(storagerouter_guid):
"""
Syncs the Disks from all StorageRouters with the reality.
CHANGES MADE TO THIS CODE SHOULD BE REFLECTED IN THE ASD-MANAGER list_disks CALL TOO!!!!!!!!!!!!!!!!!!!!
:param storagerouter_guid: Guid of the Storage Router to synchronize
:type storagerouter_guid: str
:return: None
"""
storagerouter = StorageRouter(storagerouter_guid)
try:
client = SSHClient(storagerouter, username='root')
except UnableToConnectException:
DiskController._logger.exception('Could not connect to StorageRouter {0}'.format(storagerouter.ip))
raise
# Retrieve all symlinks for all devices
# Example of name_alias_mapping:
# {'/dev/md0': ['/dev/disk/by-id/md-uuid-ad2de634:26d97253:5eda0a23:96986b76', '/dev/disk/by-id/md-name-OVS-1:0'],
# '/dev/sda': ['/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c295fe2ff771-lun-0'],
# '/dev/sda1': ['/dev/disk/by-uuid/e3e0bc62-4edc-4c6b-a6ce-1f39e8f27e41', '/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c295fe2ff771-lun-0-part1']}
name_alias_mapping = {}
alias_name_mapping = {}
for path_type in client.dir_list(directory='/dev/disk'):
if path_type in ['by-uuid', 'by-partuuid']: # UUIDs can change after creating a filesystem on a partition
continue
directory = '/dev/disk/{0}'.format(path_type)
for symlink in client.dir_list(directory=directory):
symlink_path = '{0}/{1}'.format(directory, symlink)
link = client.file_read_link(symlink_path)
if link not in name_alias_mapping:
name_alias_mapping[link] = []
name_alias_mapping[link].append(symlink_path)
alias_name_mapping[symlink_path] = link
# Parse 'lsblk' output
# --exclude 1 for RAM devices, 2 for floppy devices, 11 for CD-ROM devices (See https://www.kernel.org/doc/Documentation/devices.txt)
command = ['lsblk', '--pairs', '--bytes', '--noheadings', '--exclude', '1,2,11']
output = '--output=KNAME,SIZE,MODEL,STATE,MAJ:MIN,FSTYPE,TYPE,ROTA,MOUNTPOINT,LOG-SEC{0}'
regex = '^KNAME="(?P<name>.*)" SIZE="(?P<size>\d*)" MODEL="(?P<model>.*)" STATE="(?P<state>.*)" MAJ:MIN="(?P<dev_nr>.*)" FSTYPE="(?P<fstype>.*)" TYPE="(?P<type>.*)" ROTA="(?P<rota>[0,1])" MOUNTPOINT="(?P<mtpt>.*)" LOG-SEC="(?P<sector_size>\d*)"( SERIAL="(?P<serial>.*)")?$'
try:
devices = client.run(command + [output.format(',SERIAL')]).splitlines()
except:
devices = client.run(command + [output.format('')]).splitlines()
device_regex = re.compile(regex)
configuration = {}
parsed_devices = []
for device in devices:
match = re.match(device_regex, device)
if match is None:
DiskController._logger.error('Device regex did not match for {0}. Please investigate'.format(device))
raise Exception('Failed to parse \'lsblk\' output')
groupdict = match.groupdict()
name = groupdict['name'].strip()
size = groupdict['size'].strip()
model = groupdict['model'].strip()
state = groupdict['state'].strip()
dev_nr = groupdict['dev_nr'].strip()
serial = (groupdict['serial'] or '').strip()
fs_type = groupdict['fstype'].strip()
dev_type = groupdict['type'].strip()
rotational = groupdict['rota'].strip()
mount_point = groupdict['mtpt'].strip()
sector_size = groupdict['sector_size'].strip()
if dev_type == 'rom':
continue
link = client.file_read_link('/sys/block/{0}'.format(name))
device_state = None
friendly_path = '/dev/{0}'.format(name)
system_aliases = name_alias_mapping.get(friendly_path, [friendly_path])
device_is_also_partition = False
if link is not None: # If this returns, it means its a device and not a partition
device_is_also_partition = mount_point != '' # LVM, RAID1, ... have the tendency to be a device with a partition on it, but the partition is not reported by 'lsblk'
device_state = Disk.STATES.OK if state == 'running' or dev_nr.split(':')[0] != '8' else Disk.STATES.FAILURE
parsed_devices.append({'name': name,
'state': device_state})
configuration[name] = {'name': name,
'size': int(size),
'model': model if model != '' else None,
'serial': serial if serial != '' else None,
'state': device_state,
'is_ssd': rotational == '0',
'aliases': system_aliases,
'partitions': {}}
if link is None or device_is_also_partition is True:
current_device = None
current_device_state = None
if device_is_also_partition is True:
offset = 0
current_device = name
current_device_state = device_state
else:
offset = 0
for device_info in reversed(parsed_devices):
try:
current_device = device_info['name']
#.........这里部分代码省略.........
示例4: migrate
# 需要导入模块: from ovs.extensions.generic.sshclient import SSHClient [as 别名]
# 或者: from ovs.extensions.generic.sshclient.SSHClient import dir_list [as 别名]
def migrate(previous_version, master_ips=None, extra_ips=None):
"""
Migrates from any version to any version, running all migrations required
If previous_version is for example 0 and this script is at
verison 3 it will execute two steps:
- 1 > 2
- 2 > 3
:param previous_version: The previous version from which to start the migration.
:param master_ips: IP addresses of the MASTER nodes
:param extra_ips: IP addresses of the EXTRA nodes
"""
working_version = previous_version
# Version 1 introduced:
# - Flexible SSD layout
if working_version < 1:
try:
from ovs.extensions.generic.configuration import Configuration
if Configuration.exists('ovs.arakoon'):
Configuration.delete('ovs.arakoon', remove_root=True)
Configuration.set('ovs.core.ovsdb', '/opt/OpenvStorage/db')
except:
logger.exception('Error migrating to version 1')
working_version = 1
# Version 2 introduced:
# - Registration
if working_version < 2:
try:
import time
from ovs.extensions.generic.configuration import Configuration
if not Configuration.exists('ovs.core.registered'):
Configuration.set('ovs.core.registered', False)
Configuration.set('ovs.core.install_time', time.time())
except:
logger.exception('Error migrating to version 2')
working_version = 2
# Version 3 introduced:
# - New arakoon clients
if working_version < 3:
try:
from ovs.extensions.db.arakoon import ArakoonInstaller
reload(ArakoonInstaller)
from ovs.extensions.db.arakoon.ArakoonInstaller import ArakoonInstaller
from ovs.extensions.generic.sshclient import SSHClient
from ovs.extensions.generic.configuration import Configuration
if master_ips is not None:
for ip in master_ips:
client = SSHClient(ip)
if client.dir_exists(ArakoonInstaller.ARAKOON_CONFIG_DIR):
for cluster_name in client.dir_list(ArakoonInstaller.ARAKOON_CONFIG_DIR):
try:
ArakoonInstaller.deploy_cluster(cluster_name, ip)
except:
pass
if Configuration.exists('ovs.core.storage.persistent'):
Configuration.set('ovs.core.storage.persistent', 'pyrakoon')
except:
logger.exception('Error migrating to version 3')
working_version = 3
# Version 4 introduced:
# - Etcd
if working_version < 4:
try:
import os
import json
from ConfigParser import RawConfigParser
from ovs.extensions.db.etcd import installer
reload(installer)
from ovs.extensions.db.etcd.installer import EtcdInstaller
from ovs.extensions.db.etcd.configuration import EtcdConfiguration
from ovs.extensions.generic.system import System
host_id = System.get_my_machine_id()
etcd_migrate = False
if EtcdInstaller.has_cluster('127.0.0.1', 'config'):
etcd_migrate = True
else:
if master_ips is not None and extra_ips is not None:
cluster_ip = None
for ip in master_ips + extra_ips:
if EtcdInstaller.has_cluster(ip, 'config'):
cluster_ip = ip
break
node_ip = None
path = '/opt/OpenvStorage/config/ovs.json'
if os.path.exists(path):
with open(path) as config_file:
config = json.load(config_file)
node_ip = config['grid']['ip']
if node_ip is not None:
if cluster_ip is None:
EtcdInstaller.create_cluster('config', node_ip)
EtcdConfiguration.initialize()
EtcdConfiguration.initialize_host(host_id)
#.........这里部分代码省略.........
示例5: migrate
# 需要导入模块: from ovs.extensions.generic.sshclient import SSHClient [as 别名]
# 或者: from ovs.extensions.generic.sshclient.SSHClient import dir_list [as 别名]
#.........这里部分代码省略.........
unique_key = 'ovs_unique_{0}_{{0}}_'.format(classname)
uniques = []
# noinspection PyProtectedMember
for prop in cls._properties:
if prop.unique is True and len([k for k in client.prefix(unique_key.format(prop.name))]) == 0:
uniques.append(prop.name)
if len(uniques) > 0:
prefix = 'ovs_data_{0}_'.format(classname)
for key in client.prefix(prefix):
data = client.get(key)
for property_name in uniques:
ukey = '{0}{1}'.format(unique_key.format(property_name), hashlib.sha1(str(data[property_name])).hexdigest())
client.set(ukey, key)
# Complete rework of the way we detect devices to assign roles or use as ASD
# Allow loop-, raid-, nvme-, ??-devices and logical volumes as ASD (https://github.com/openvstorage/framework/issues/792)
from ovs.dal.lists.storagerouterlist import StorageRouterList
from ovs.extensions.generic.sshclient import SSHClient, UnableToConnectException
from ovs.lib.disk import DiskController
for storagerouter in StorageRouterList.get_storagerouters():
try:
client = SSHClient(storagerouter, username='root')
except UnableToConnectException:
raise
# Retrieve all symlinks for all devices
# Example of name_alias_mapping:
# {'/dev/md0': ['/dev/disk/by-id/md-uuid-ad2de634:26d97253:5eda0a23:96986b76', '/dev/disk/by-id/md-name-OVS-1:0'],
# '/dev/sda': ['/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c295fe2ff771-lun-0'],
# '/dev/sda1': ['/dev/disk/by-uuid/e3e0bc62-4edc-4c6b-a6ce-1f39e8f27e41', '/dev/disk/by-path/pci-0000:03:00.0-sas-0x5000c295fe2ff771-lun-0-part1']}
name_alias_mapping = {}
alias_name_mapping = {}
for path_type in client.dir_list(directory='/dev/disk'):
if path_type in ['by-uuid', 'by-partuuid']: # UUIDs can change after creating a filesystem on a partition
continue
directory = '/dev/disk/{0}'.format(path_type)
for symlink in client.dir_list(directory=directory):
symlink_path = '{0}/{1}'.format(directory, symlink)
link = client.file_read_link(symlink_path)
if link not in name_alias_mapping:
name_alias_mapping[link] = []
name_alias_mapping[link].append(symlink_path)
alias_name_mapping[symlink_path] = link
for disk in storagerouter.disks:
if disk.aliases is None:
# noinspection PyProtectedMember
device_path = '/dev/{0}'.format(disk.name)
disk.aliases = name_alias_mapping.get(device_path, [device_path])
disk.save()
for partition in disk.partitions:
if partition.aliases is None:
# noinspection PyProtectedMember
partition_device = alias_name_mapping.get(partition._data.get('path'))
if partition_device is None:
partition.aliases = []
partition.save()
continue
partition.aliases = name_alias_mapping.get(partition_device, [])
partition.save()
DiskController.sync_with_reality(storagerouter_guid=storagerouter.guid)
# Only support ALBA backend type
from ovs.dal.lists.backendtypelist import BackendTypeList