Alex Monk has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374897 )
Change subject: [WIP] shinkengen for all projects ...................................................................... [WIP] shinkengen for all projects Untested! Cleans up some now-unused config and heira etc. Bug: T166845 Change-Id: Idcf1e283c0dfdd8546cd46c76155b836b7c7677c --- M hieradata/labs.yaml M modules/shinken/files/shinkengen M modules/shinken/templates/shinkengen.yaml.erb 3 files changed, 24 insertions(+), 26 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/puppet refs/changes/97/374897/1 diff --git a/hieradata/labs.yaml b/hieradata/labs.yaml index d085d2e..e5b9569 100644 --- a/hieradata/labs.yaml +++ b/hieradata/labs.yaml @@ -86,7 +86,6 @@ puppetmaster: "labs-puppetmaster.wikimedia.org" saltmaster: "labcontrol1001.wikimedia.org" mysql::server::use_apparmor: false # The images we have for debian don't support it -keystone_public_port: '5000' # All labs instances have internet connectivity, so do not bother with proxies profile::base::use_apt_proxy: false diff --git a/modules/shinken/files/shinkengen b/modules/shinken/files/shinkengen index 619f172..40b0539 100755 --- a/modules/shinken/files/shinkengen +++ b/modules/shinken/files/shinkengen @@ -40,6 +40,7 @@ from keystoneclient.session import Session as KeystoneSession from keystoneclient.auth.identity.v3 import Password as KeystonePassword +from keystoneclient.v3 import Client as KeystoneClient from novaclient import client as novaclient @@ -61,21 +62,18 @@ for key, value in self.properties.iteritems()) return 'define %s {\n%s}\n' % (self.type, config_str) +def get_keystone_session(project, observer_config): + return KeystoneSession(auth=KeystonePassword( + auth_url=observer_config['OS_AUTH_URL'], + username=observer_config['OS_USERNAME'], + password=observer_config['OS_PASSWORD'], + project_name=project, + user_domain_name='default', + project_domain_name='default' + )) -def get_instances(project, observer_pass, keystone_host, keystone_port): - client = novaclient.Client( - "2.0", - session=KeystoneSession(auth=KeystonePassword( - auth_url="http://{host}:{port}/v3".format(host=keystone_host, - port=keystone_port), - username="novaobserver", - password=observer_pass, - project_name=project, - user_domain_name='default', - project_domain_name='default' - )) - ) - +def get_instances(project, keystone_session): + client = novaclient.Client("2.0", session=keystone_session) hosts = [] for instance in client.servers.list(): hosts.append({ @@ -112,10 +110,14 @@ nova_observer = yaml.safe_load(n) observer_pass = nova_observer['OS_PASSWORD'] - for project in config['projects']: - instances = get_instances(project, observer_pass, - config['keystone_host'], - config['keystone_port']) + client = KeystoneClient( + session=get_keystone_session('bastion', nova_observer), + endpoint=nova_observer['OS_AUTH_URL'], + interface='public' + ) + + for project in client.projects.list(): + instances = get_instances(project.name, get_keystone_session(project.name, nova_observer)) host_configs = [] for instance in instances: co = ConfigObject('host') @@ -127,7 +129,7 @@ # particular roles with checks. role::labs::instance is # implicitly applied to all instances via # manifests/site.pp, so we need to add it here explicitly. - hostgroups = [project, 'role::labs::instance'] + hostgroups = [project.name, 'role::labs::instance'] hostgroups += get_instance_roles(instance['project'], instance['fqdn'], config['puppet_enc_host']) @@ -135,13 +137,13 @@ # For each project added to monitoring we expect a contactgroup with the same # name added. # FIXME: Implement access mechanism more fine grained than per-project - co.properties['contact_groups'] = project + co.properties['contact_groups'] = project.name # Used to auto derive metric paths in graphite, which is of the form # <projectname>.<instancename>.<metric-path>. - co.properties['notes'] = project # Used for auto deriving graphite path + co.properties['notes'] = project.name # Used for auto deriving graphite path host_configs.append(co) hosts_config_path = '%s/%s.cfg' % ( - config['output_path'], project + config['output_path'], project.name ) file_content = ''.join([str(hc) for hc in host_configs]) if args.test_if_up_to_date: diff --git a/modules/shinken/templates/shinkengen.yaml.erb b/modules/shinken/templates/shinkengen.yaml.erb index c26a1c2..18ef0fa 100644 --- a/modules/shinken/templates/shinkengen.yaml.erb +++ b/modules/shinken/templates/shinkengen.yaml.erb @@ -1,6 +1,3 @@ -projects: [ 'tools', 'deployment-prep', 'extdist', 'analytics', 'integration', 'shinken', 'cvn', 'wdq-mm', 'wmt' ] output_path: '/etc/shinken/generated' site: <%= scope.lookupvar("::site") %> -keystone_host: <%= scope.function_hiera(['labs_keystone_host']) %> -keystone_port: <%= scope.function_hiera(['keystone_public_port']) %> puppet_enc_host: <%= scope.function_hiera(['labs_puppet_master']) %> -- To view, visit https://gerrit.wikimedia.org/r/374897 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idcf1e283c0dfdd8546cd46c76155b836b7c7677c Gerrit-PatchSet: 1 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Alex Monk <kren...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits