本文整理汇总了Python中fuelweb_test.helpers.ssh_manager.SSHManager.download_from_remote方法的典型用法代码示例。如果您正苦于以下问题:Python SSHManager.download_from_remote方法的具体用法?Python SSHManager.download_from_remote怎么用?Python SSHManager.download_from_remote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fuelweb_test.helpers.ssh_manager.SSHManager
的用法示例。
在下文中一共展示了SSHManager.download_from_remote方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: store_astute_yaml_for_one_node
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import download_from_remote [as 别名]
def store_astute_yaml_for_one_node(nailgun_node):
ssh_manager = SSHManager()
if 'roles' not in nailgun_node:
return None
errmsg = 'Downloading "{0}.yaml" from the {1} failed'
msg = 'File "{0}.yaml" was downloaded from the {1}'
nodename = nailgun_node['name']
ip = nailgun_node['ip']
for role in nailgun_node['roles']:
filename = '{0}/{1}-{2}-{3}.yaml'.format(settings.LOGS_DIR,
func_name,
nodename,
role)
if not ssh_manager.isfile_on_remote(ip,
'/etc/{0}.yaml'.format(role)):
role = 'primary-' + role
if ssh_manager.download_from_remote(ip,
'/etc/{0}.yaml'.format(role),
filename):
logger.info(msg.format(role, nodename))
else:
logger.error(errmsg.format(role, nodename))
if settings.DOWNLOAD_FACTS:
fact_filename = re.sub(r'-\w*\.', '-facts.', filename)
generate_facts(ip)
if ssh_manager.download_from_remote(ip,
'/tmp/facts.yaml',
fact_filename):
logger.info(msg.format('facts', nodename))
else:
logger.error(errmsg.format('facts', nodename))
示例2: get_nodes_tasks
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import download_from_remote [as 别名]
def get_nodes_tasks(node_id):
"""
:param node_id: an integer number of node id
:return: a set of deployment tasks for corresponding node
"""
tasks = set()
ssh = SSHManager()
result = ssh.execute_on_remote(ssh.admin_ip, "ls /var/log/astute")
filenames = [filename.strip() for filename in result['stdout']]
for filename in filenames:
ssh.download_from_remote(
ssh.admin_ip,
destination="/var/log/astute/{0}".format(filename),
target="/tmp/{0}".format(filename))
data = fileinput.FileInput(
files=["/tmp/{0}".format(filename) for filename in filenames],
openhook=fileinput.hook_compressed)
for line in data:
if "Task time summary" in line \
and "node {}".format(node_id) in line:
# FIXME: define an exact search of task
task_name = line.split("Task time summary: ")[1].split()[0]
check = any([excluded_task in task_name
for excluded_task in TASKS_BLACKLIST])
if check:
continue
tasks.add(task_name)
return tasks
示例3: BaseActions
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import download_from_remote [as 别名]
#.........这里部分代码省略.........
yaml_dict = yaml_dict[k]
yaml_dict[element[-1]] = value
with open(new_file, 'w') as f_new:
yaml.dump(origin_yaml, f_new, default_flow_style=False,
default_style='"')
def get_value_from_local_yaml(self, yaml_file, element):
"""Get a value of the element from the local yaml file
:param str yaml_file: a path to the yaml file
:param list element:
list with path to element to be read
for example: ['root_elem', 'first_elem', 'target_elem']
if there are a few elements with equal names use integer
to identify which element should be used
:return obj: value
"""
with open(yaml_file, 'r') as f_old:
yaml_dict = yaml.load(f_old)
for i, k in enumerate(element):
try:
yaml_dict = yaml_dict[k]
except IndexError:
raise IndexError("Element {0} not found in the file {1}"
.format(element[: i + 1], f_old))
except KeyError:
raise KeyError("Element {0} not found in the file {1}"
.format(element[: i + 1], f_old))
return yaml_dict
def change_remote_yaml(self, path_to_file, element, value):
"""Changes values in the yaml file stored
There is no need to copy file manually
:param path_to_file: absolute path to the file
:param element: list with path to the element be changed
:param value: new value for element
:return: Nothing
"""
old_file = '/tmp/temp_file_{0}.old.yaml'.format(str(os.getpid()))
new_file = '/tmp/temp_file_{0}.new.yaml'.format(str(os.getpid()))
self.ssh_manager.download_from_remote(
ip=self.admin_ip,
destination=path_to_file,
target=old_file
)
self.put_value_to_local_yaml(old_file, new_file, element, value)
self.ssh_manager.upload_to_remote(
ip=self.admin_ip,
source=new_file,
target=path_to_file
)
os.remove(old_file)
os.remove(new_file)
def get_value_from_remote_yaml(self, path_to_file, element):
"""Get a value from the yaml file stored
on the master node
:param str path_to_file: absolute path to the file
:param list element: list with path to the element
:return obj: value
"""
host_tmp_file = '/tmp/temp_file_{0}.yaml'.format(str(os.getpid()))
self.ssh_manager.download_from_remote(
ip=self.admin_ip,
destination=path_to_file,
target=host_tmp_file
)
value = self.get_value_from_local_yaml(host_tmp_file, element)
os.remove(host_tmp_file)
return value
def put_value_to_remote_yaml(self, path_to_file, element, value):
"""Put a value to the yaml file stored
on the master node
:param str path_to_file: absolute path to the file
:param list element: list with path to the element be changed
:param value: new value for element
:return: None
"""
host_tmp_file = '/tmp/temp_file_{0}.yaml'.format(str(os.getpid()))
self.ssh_manager.download_from_remote(
ip=self.admin_ip,
destination=path_to_file,
target=host_tmp_file
)
self.put_value_to_local_yaml(host_tmp_file, host_tmp_file,
element, value)
self.ssh_manager.upload_to_remote(
ip=self.admin_ip,
source=host_tmp_file,
target=path_to_file
)
os.remove(host_tmp_file)
示例4: BaseActions
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import download_from_remote [as 别名]
#.........这里部分代码省略.........
"""
with open(yaml_file, 'r') as f_old:
yaml_dict = yaml.load(f_old)
for i, k in enumerate(element):
try:
yaml_dict = yaml_dict[k]
except IndexError:
raise IndexError("Element {0} not found in the file {1}"
.format(element[: i + 1], f_old))
except KeyError:
raise KeyError("Element {0} not found in the file {1}"
.format(element[: i + 1], f_old))
return yaml_dict
def change_yaml_file_in_container(
self, path_to_file, element, value, container=None):
"""Changes values in the yaml file stored at container
There is no need to copy file manually
:param path_to_file: absolutely path to the file
:param element: list with path to the element be changed
:param value: new value for element
:param container: Container with file. By default it is nailgun
:return: Nothing
"""
if not container:
container = self.container
old_file = '/tmp/temp_file_{0}.old.yaml'.format(str(os.getpid()))
new_file = '/tmp/temp_file_{0}.new.yaml'.format(str(os.getpid()))
self.copy_between_node_and_container(
'{0}:{1}'.format(container, path_to_file), old_file)
self.ssh_manager.download_from_remote(
ip=self.admin_ip,
destination=old_file,
target=old_file
)
self.put_value_to_local_yaml(old_file, new_file, element, value)
self.ssh_manager.upload_to_remote(
ip=self.admin_ip,
source=new_file,
target=new_file
)
self.copy_between_node_and_container(
new_file, '{0}:{1}'.format(container, path_to_file))
os.remove(old_file)
os.remove(new_file)
def get_value_from_yaml(self, path_to_file, element):
"""Get a value from the yaml file stored in container
or on master node if self.container is None
:param str path_to_file: absolutely path to the file
:param list element: list with path to the element be changed
:return obj: value
"""
if self.container:
admin_tmp_file = '/tmp/temp_file_{0}.yaml'.format(str(os.getpid()))
self.copy_between_node_and_container(
'{0}:{1}'.format(self.container, path_to_file), admin_tmp_file)
else:
admin_tmp_file = path_to_file
host_tmp_file = '/tmp/temp_file_{0}.yaml'.format(str(os.getpid()))
示例5: BaseActions
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import download_from_remote [as 别名]
class BaseActions(object):
"""BaseActions.""" # TODO documentation
def __init__(self):
self.ssh_manager = SSHManager()
self.admin_ip = self.ssh_manager.admin_ip
def __repr__(self):
klass, obj_id = type(self), hex(id(self))
return "[{klass}({obj_id})]".format(
klass=klass,
obj_id=obj_id)
def restart_service(self, service):
result = self.ssh_manager.execute(
ip=self.admin_ip,
cmd="systemctl restart {0}".format(service))
return result['exit_code'] == 0
@staticmethod
def put_value_to_local_yaml(old_file, new_file, element, value):
"""Changes content in old_file at element is given to the new value
and creates new file with changed content
:param old_file: a path to the file content from to be changed
:param new_file: a path to the new file to ve created with new content
:param element: tuple with path to element to be changed
for example: ['root_elem', 'first_elem', 'target_elem']
if there are a few elements with equal names use integer
to identify which element should be used
:return: nothing
"""
with open(old_file, 'r') as f_old:
yaml_dict = yaml.load(f_old)
origin_yaml = yaml_dict
for k in element[:-1]:
yaml_dict = yaml_dict[k]
yaml_dict[element[-1]] = value
with open(new_file, 'w') as f_new:
yaml.dump(origin_yaml, f_new, default_flow_style=False,
default_style='"')
@staticmethod
def get_value_from_local_yaml(yaml_file, element):
"""Get a value of the element from the local yaml file
:param str yaml_file: a path to the yaml file
:param list element:
list with path to element to be read
for example: ['root_elem', 'first_elem', 'target_elem']
if there are a few elements with equal names use integer
to identify which element should be used
:return obj: value
"""
with open(yaml_file, 'r') as f_old:
yaml_dict = yaml.load(f_old)
for i, k in enumerate(element):
try:
yaml_dict = yaml_dict[k]
except IndexError:
raise IndexError("Element {0} not found in the file {1}"
.format(element[: i + 1], f_old))
except KeyError:
raise KeyError("Element {0} not found in the file {1}"
.format(element[: i + 1], f_old))
return yaml_dict
def change_remote_yaml(self, path_to_file, element, value):
"""Changes values in the yaml file stored
There is no need to copy file manually
:param path_to_file: absolute path to the file
:param element: list with path to the element be changed
:param value: new value for element
:return: Nothing
"""
old_file = '/tmp/temp_file_{0}.old.yaml'.format(str(os.getpid()))
new_file = '/tmp/temp_file_{0}.new.yaml'.format(str(os.getpid()))
self.ssh_manager.download_from_remote(
ip=self.admin_ip,
destination=path_to_file,
target=old_file
)
self.put_value_to_local_yaml(old_file, new_file, element, value)
self.ssh_manager.upload_to_remote(
ip=self.admin_ip,
source=new_file,
target=path_to_file
)
os.remove(old_file)
os.remove(new_file)
def get_value_from_remote_yaml(self, path_to_file, element):
"""Get a value from the yaml file stored
on the master node
:param str path_to_file: absolute path to the file
#.........这里部分代码省略.........