本文整理汇总了Python中ovs.lib.helpers.toolbox.Toolbox.ask_validate_password方法的典型用法代码示例。如果您正苦于以下问题:Python Toolbox.ask_validate_password方法的具体用法?Python Toolbox.ask_validate_password怎么用?Python Toolbox.ask_validate_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovs.lib.helpers.toolbox.Toolbox
的用法示例。
在下文中一共展示了Toolbox.ask_validate_password方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: promote_or_demote_node
# 需要导入模块: from ovs.lib.helpers.toolbox import Toolbox [as 别名]
# 或者: from ovs.lib.helpers.toolbox.Toolbox import ask_validate_password [as 别名]
def promote_or_demote_node(node_action, cluster_ip=None, execute_rollback=False):
"""
Promotes or demotes the local node
:param node_action: Demote or promote
:type node_action: str
:param cluster_ip: IP of node to promote or demote
:type cluster_ip: str
:param execute_rollback: In case of failure revert the changes made
:type execute_rollback: bool
:return: None
"""
if node_action not in ('promote', 'demote'):
raise ValueError('Nodes can only be promoted or demoted')
Toolbox.log(logger=NodeTypeController._logger, messages='Open vStorage Setup - {0}'.format(node_action.capitalize()), boxed=True)
try:
Toolbox.log(logger=NodeTypeController._logger, messages='Collecting information', title=True)
machine_id = System.get_my_machine_id()
if Configuration.get('/ovs/framework/hosts/{0}/setupcompleted'.format(machine_id)) is False:
raise RuntimeError('No local OVS setup found.')
if cluster_ip and not re.match(Toolbox.regex_ip, cluster_ip):
raise RuntimeError('Incorrect IP provided ({0})'.format(cluster_ip))
if cluster_ip:
client = SSHClient(endpoint=cluster_ip)
machine_id = System.get_my_machine_id(client)
node_type = Configuration.get('/ovs/framework/hosts/{0}/type'.format(machine_id))
if node_action == 'promote' and node_type == 'MASTER':
raise RuntimeError('This node is already master.')
elif node_action == 'demote' and node_type == 'EXTRA':
raise RuntimeError('This node should be a master.')
elif node_type not in ['MASTER', 'EXTRA']:
raise RuntimeError('This node is not correctly configured.')
master_ip = None
offline_nodes = []
online = True
target_client = None
if node_action == 'demote' and cluster_ip: # Demote an offline node
from ovs.dal.lists.storagerouterlist import StorageRouterList
from ovs.lib.storagedriver import StorageDriverController
ip = cluster_ip
unique_id = None
ip_client_map = {}
for storage_router in StorageRouterList.get_storagerouters():
try:
client = SSHClient(storage_router.ip, username='root')
if storage_router.node_type == 'MASTER':
master_ip = storage_router.ip
ip_client_map[storage_router.ip] = client
except UnableToConnectException:
if storage_router.ip == cluster_ip:
online = False
unique_id = storage_router.machine_id
StorageDriverController.mark_offline(storagerouter_guid=storage_router.guid)
offline_nodes.append(storage_router)
if online is True:
raise RuntimeError("If the node is online, please use 'ovs setup demote' executed on the node you wish to demote")
if master_ip is None:
raise RuntimeError('Failed to retrieve another responsive MASTER node')
else:
target_password = Toolbox.ask_validate_password(ip='127.0.0.1', logger=NodeTypeController._logger)
target_client = SSHClient('127.0.0.1', username='root', password=target_password)
unique_id = System.get_my_machine_id(target_client)
ip = Configuration.get('/ovs/framework/hosts/{0}/ip'.format(unique_id))
storagerouter_info = NodeTypeController.retrieve_storagerouter_info_via_host(ip=target_client.ip, password=target_password)
node_ips = [sr_info['ip'] for sr_info in storagerouter_info.itervalues()]
master_node_ips = [sr_info['ip'] for sr_info in storagerouter_info.itervalues() if sr_info['type'] == 'master' and sr_info['ip'] != ip]
if len(master_node_ips) == 0:
if node_action == 'promote':
raise RuntimeError('No master node could be found')
else:
raise RuntimeError('It is not possible to remove the only master')
master_ip = master_node_ips[0]
ip_client_map = dict((node_ip, SSHClient(node_ip, username='root')) for node_ip in node_ips)
if node_action == 'demote':
for cluster_name in Configuration.list('/ovs/arakoon'):
config = ArakoonClusterConfig(cluster_name, False)
config.load_config()
arakoon_client = ArakoonInstaller.build_client(config)
metadata = json.loads(arakoon_client.get(ArakoonInstaller.METADATA_KEY))
if len(config.nodes) == 1 and config.nodes[0].ip == ip and metadata.get('internal') is True:
raise RuntimeError('Demote is not supported when single node Arakoon cluster(s) are present on the node to be demoted.')
configure_rabbitmq = Toolbox.is_service_internally_managed(service='rabbitmq')
configure_memcached = Toolbox.is_service_internally_managed(service='memcached')
if node_action == 'promote':
try:
NodeTypeController.promote_node(cluster_ip=ip,
#.........这里部分代码省略.........