Summary: add ssh params to host groups
Description: - ansible needs to be told to use the kolla account and the kolla keys. This adds that to the inventory.
This commit is contained in:
parent
11019a987b
commit
f0a5c0be7a
|
@ -31,6 +31,9 @@ from kollacli.sshutils import ssh_uninstall_host
|
|||
|
||||
from kollacli.exceptions import CommandError
|
||||
|
||||
ANSIBLE_KEY_FILE = 'ansible_ssh_private_key_file'
|
||||
ANSIBLE_SSH_USER = 'ansible_ssh_user'
|
||||
|
||||
INVENTORY_PATH = 'ansible/inventory/inventory.json'
|
||||
|
||||
COMPUTE_GRP_NAME = 'compute'
|
||||
|
@ -92,6 +95,9 @@ class Host(object):
|
|||
def get_vars(self):
|
||||
return self.vars.copy()
|
||||
|
||||
def set_var(self, name, value):
|
||||
self.vars[name] = value
|
||||
|
||||
def upgrade(self):
|
||||
pass
|
||||
|
||||
|
@ -197,6 +203,12 @@ class Group(object):
|
|||
if host.name in self._hosts:
|
||||
del self._hosts[host.name]
|
||||
|
||||
def add_group(self, groupname):
|
||||
group = Group(groupname)
|
||||
if group not in self.children:
|
||||
self.children.append(group)
|
||||
return group
|
||||
|
||||
def get_hosts(self):
|
||||
return self._hosts.values()
|
||||
|
||||
|
@ -212,6 +224,9 @@ class Group(object):
|
|||
def get_vars(self):
|
||||
return self.vars.copy()
|
||||
|
||||
def set_var(self, name, value):
|
||||
self.vars[name] = value
|
||||
|
||||
|
||||
class Inventory(object):
|
||||
class_version = 1
|
||||
|
@ -283,14 +298,13 @@ class Inventory(object):
|
|||
|
||||
def _create_default_inventory(self):
|
||||
for (deploy_name, service_names) in DEFAULT_HIERARCHY.items():
|
||||
deploy_group = Group(deploy_name)
|
||||
deploy_group = self.add_group(deploy_name)
|
||||
|
||||
# add service groups
|
||||
for service_name in service_names:
|
||||
service_group = Group(service_name)
|
||||
deploy_group.children.append(service_group)
|
||||
service_group = deploy_group.add_group(service_name)
|
||||
for container_name in SERVICE_GROUPS[service_name]:
|
||||
container_group = Group(container_name)
|
||||
service_group.children.append(container_group)
|
||||
service_group.add_group(container_name)
|
||||
self._groups[deploy_name] = deploy_group
|
||||
|
||||
def get_hosts(self):
|
||||
|
@ -364,6 +378,14 @@ class Inventory(object):
|
|||
if groupname not in self._groups:
|
||||
self._groups[groupname] = Group(groupname)
|
||||
|
||||
group = self._groups[groupname]
|
||||
|
||||
# set the ssh info for all the servers in the group
|
||||
group.set_var(ANSIBLE_KEY_FILE, utils.get_pk_file())
|
||||
group.set_var(ANSIBLE_SSH_USER, utils.get_admin_user())
|
||||
|
||||
return group
|
||||
|
||||
def remove_group(self, groupname):
|
||||
if groupname in self._groups:
|
||||
del self._groups[groupname]
|
||||
|
|
|
@ -42,7 +42,7 @@ def get_pk_file():
|
|||
|
||||
def get_pk_password():
|
||||
# TODO(bmace) what to do here? pull from a file?
|
||||
return ""
|
||||
return None
|
||||
|
||||
|
||||
def get_pk_bits():
|
||||
|
|
|
@ -41,16 +41,21 @@ class TestFunctional(KollaCliTest):
|
|||
'Services': [],
|
||||
'Hosts': [],
|
||||
}
|
||||
groups = [group1, group2, group3]
|
||||
group4 = {
|
||||
'Group': 'storage',
|
||||
'Services': ['cinder'],
|
||||
'Hosts': [],
|
||||
}
|
||||
groups = [group1, group2, group3, group4]
|
||||
|
||||
def test_group_add_remove(self):
|
||||
group4 = {
|
||||
'Group': 'test_group4',
|
||||
group_t1 = {
|
||||
'Group': 'test_group_t1',
|
||||
'Services': [],
|
||||
'Hosts': [],
|
||||
}
|
||||
group5 = {
|
||||
'Group': 'test_group5',
|
||||
group_t2 = {
|
||||
'Group': 'test_group_t2',
|
||||
'Services': [],
|
||||
'Hosts': [],
|
||||
}
|
||||
|
@ -60,20 +65,20 @@ class TestFunctional(KollaCliTest):
|
|||
# check default group list
|
||||
self.check_group(groups)
|
||||
|
||||
groups.append(group4)
|
||||
self.run_client_cmd('group add %s' % group4['Group'])
|
||||
groups.append(group_t1)
|
||||
self.run_client_cmd('group add %s' % group_t1['Group'])
|
||||
self.check_group(groups)
|
||||
|
||||
groups.append(group5)
|
||||
self.run_client_cmd('group add %s' % group5['Group'])
|
||||
groups.append(group_t2)
|
||||
self.run_client_cmd('group add %s' % group_t2['Group'])
|
||||
self.check_group(groups)
|
||||
|
||||
self.run_client_cmd('group remove %s' % group5['Group'])
|
||||
groups.remove(group5)
|
||||
self.run_client_cmd('group remove %s' % group_t2['Group'])
|
||||
groups.remove(group_t2)
|
||||
self.check_group(groups)
|
||||
|
||||
self.run_client_cmd('group remove %s' % group4['Group'])
|
||||
groups.remove(group4)
|
||||
self.run_client_cmd('group remove %s' % group_t1['Group'])
|
||||
groups.remove(group_t1)
|
||||
self.check_group(groups)
|
||||
|
||||
def test_group_add_host(self):
|
||||
|
|
Loading…
Reference in New Issue