Fix: fuel CLI auth, fuel CLI for 9.0+
Change-Id: I1828c505fe6bf41a73d08f57b72af55c0182acab
This commit is contained in:
parent
410a5cb612
commit
e055f8b0cc
@ -15,3 +15,4 @@ Exit Codes
|
|||||||
* `109` - subprocess (one of the node execution processes) exited with a Python exception.
|
* `109` - subprocess (one of the node execution processes) exited with a Python exception.
|
||||||
* `110` - unable to create a directory.
|
* `110` - unable to create a directory.
|
||||||
* `111` - ip address must be defined for Node instance.
|
* `111` - ip address must be defined for Node instance.
|
||||||
|
* `112` - one of the two parameters **fuel_user** or **fuel_pass** specified without the other.
|
||||||
|
@ -216,6 +216,10 @@ def main(argv=None):
|
|||||||
conf['fuel_user'] = args.fuel_user
|
conf['fuel_user'] = args.fuel_user
|
||||||
if args.fuel_pass:
|
if args.fuel_pass:
|
||||||
conf['fuel_pass'] = args.fuel_pass
|
conf['fuel_pass'] = args.fuel_pass
|
||||||
|
if any([args.fuel_user and not args.fuel_pass,
|
||||||
|
args.fuel_pass and not args.fuel_user]):
|
||||||
|
logger.critical('You must specify both --fuel-user and --fuel-pass')
|
||||||
|
exit(112)
|
||||||
if args.fuel_token:
|
if args.fuel_token:
|
||||||
conf['fuel_api_token'] = args.fuel_token
|
conf['fuel_api_token'] = args.fuel_token
|
||||||
conf['fuelclient'] = False
|
conf['fuelclient'] = False
|
||||||
|
@ -560,7 +560,7 @@ class NodeManager(object):
|
|||||||
self.logger.info('Setup fuelclient instance')
|
self.logger.info('Setup fuelclient instance')
|
||||||
if FUEL_10:
|
if FUEL_10:
|
||||||
args = {'host': self.conf['fuel_ip'],
|
args = {'host': self.conf['fuel_ip'],
|
||||||
'port': self.conf['fuel_port']}
|
'port': self.conf['fuel_api_port']}
|
||||||
if self.conf['fuel_user']:
|
if self.conf['fuel_user']:
|
||||||
args['os_username'] = self.conf['fuel_user']
|
args['os_username'] = self.conf['fuel_user']
|
||||||
if self.conf['fuel_pass']:
|
if self.conf['fuel_pass']:
|
||||||
@ -590,6 +590,7 @@ class NodeManager(object):
|
|||||||
if (not self.get_nodes_fuelclient() and
|
if (not self.get_nodes_fuelclient() and
|
||||||
not self.get_nodes_api() and
|
not self.get_nodes_api() and
|
||||||
not self.get_nodes_cli()):
|
not self.get_nodes_cli()):
|
||||||
|
self.logger.critical('Failed to retrieve node information.')
|
||||||
sys.exit(105)
|
sys.exit(105)
|
||||||
self.nodes_init()
|
self.nodes_init()
|
||||||
self.nodes_check_access()
|
self.nodes_check_access()
|
||||||
@ -858,6 +859,7 @@ class NodeManager(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def get_nodes_api(self):
|
def get_nodes_api(self):
|
||||||
|
return False
|
||||||
self.logger.info('using API to get nodes json')
|
self.logger.info('using API to get nodes json')
|
||||||
nodes_json = self.get_api_request('nodes')
|
nodes_json = self.get_api_request('nodes')
|
||||||
if nodes_json:
|
if nodes_json:
|
||||||
@ -869,19 +871,37 @@ class NodeManager(object):
|
|||||||
def get_nodes_cli(self):
|
def get_nodes_cli(self):
|
||||||
self.logger.info('using CLI to get nodes json')
|
self.logger.info('using CLI to get nodes json')
|
||||||
fuelnode = self.nodes[self.conf['fuel_ip']]
|
fuelnode = self.nodes[self.conf['fuel_ip']]
|
||||||
fuel_node_cmd = ('fuel node list --json --user %s --password %s' %
|
o_auth = n_auth = ''
|
||||||
(self.conf['fuel_user'],
|
entropy = bool(self.conf['fuel_user']) + bool(self.conf['fuel_pass'])
|
||||||
self.conf['fuel_pass']))
|
if entropy == 2:
|
||||||
|
# auth for Fuel up to 8.0
|
||||||
|
o_auth = '--user %s --password %s' % (self.conf['fuel_user'],
|
||||||
|
self.conf['fuel_pass'])
|
||||||
|
# Fuel 9.0+
|
||||||
|
n_auth = 'OS_USERNAME=%s OS_PASSWORD=%s' % (self.conf['fuel_user'],
|
||||||
|
self.conf['fuel_pass'])
|
||||||
|
elif entropy == 1:
|
||||||
|
self.logger.warning('Must specify both fuel_user and fuel_pass')
|
||||||
|
cmd = 'bash -c "%s fuel node --json"' % n_auth
|
||||||
nodes_json, err, code = tools.ssh_node(ip=fuelnode.ip,
|
nodes_json, err, code = tools.ssh_node(ip=fuelnode.ip,
|
||||||
command=fuel_node_cmd,
|
command=cmd,
|
||||||
ssh_opts=fuelnode.ssh_opts,
|
ssh_opts=fuelnode.ssh_opts,
|
||||||
timeout=fuelnode.timeout,
|
timeout=fuelnode.timeout,
|
||||||
prefix=fuelnode.prefix)
|
prefix=fuelnode.prefix)
|
||||||
if code != 0:
|
if code != 0:
|
||||||
self.logger.warning(('NodeManager: cannot get '
|
self.logger.warning(('NodeManager: cannot get fuel node list from'
|
||||||
'fuel node list from CLI: %s') % err)
|
' CLI, will fallback. Error: %s') % err)
|
||||||
self.nodes_json = None
|
cmd = 'bash -c "fuel %s node --json"' % o_auth
|
||||||
return False
|
nodes_json, err, code = tools.ssh_node(ip=fuelnode.ip,
|
||||||
|
command=cmd,
|
||||||
|
ssh_opts=fuelnode.ssh_opts,
|
||||||
|
timeout=fuelnode.timeout,
|
||||||
|
prefix=fuelnode.prefix)
|
||||||
|
if code != 0:
|
||||||
|
self.logger.warning(('NodeManager: cannot get '
|
||||||
|
'fuel node list from CLI: %s') % err)
|
||||||
|
self.nodes_json = None
|
||||||
|
return False
|
||||||
self.nodes_json = json.loads(nodes_json)
|
self.nodes_json = json.loads(nodes_json)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user