From bfcc5244317e75e12c9b46cb16fe93f656d6e7f6 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Fri, 7 Nov 2014 16:25:51 -0700 Subject: [PATCH] Moved devstack VM from ainsible to chef Change-Id: If6fabf94a65081d7d8c7eeb0f3b886bb46a1c7c2 --- .gitignore | 3 +- Vagrantfile | 7 -- ansible_roles | 5 ++ cookbooks/devstack/README.md | 11 --- cookbooks/devstack/metadata.rb | 7 -- .../devstack/recipes/agent_plugin_config.rb | 40 ---------- cookbooks/devstack/recipes/default.rb | 1 - cookbooks/devstack/recipes/keystone.rb | 77 ------------------- cookbooks/devstack/recipes/mon-ui.rb | 32 -------- .../devstack/templates/default/my.cnf.erb | 3 - .../templates/default/rabbitmq.cnf.erb | 6 -- devstack.yml | 25 +++++- roles/Devstack.json | 20 ----- roles/monasca-devstack/README.md | 31 ++++++++ roles/monasca-devstack/defaults/main.yml | 8 ++ roles/monasca-devstack/handlers/main.yml | 3 + roles/monasca-devstack/meta/main.py | 21 +++++ roles/monasca-devstack/tasks/agent_mysql.yaml | 9 +++ .../tasks/agent_rabbitmq.yaml | 10 +++ roles/monasca-devstack/tasks/main.yml | 3 + roles/monasca-devstack/templates/my_cnf.j2 | 4 + .../templates/rabbitmq_cnf.j2 | 7 ++ roles/monasca-devstack/vars/main.yml | 3 + 23 files changed, 129 insertions(+), 207 deletions(-) delete mode 100644 cookbooks/devstack/README.md delete mode 100644 cookbooks/devstack/metadata.rb delete mode 100644 cookbooks/devstack/recipes/agent_plugin_config.rb delete mode 100644 cookbooks/devstack/recipes/default.rb delete mode 100644 cookbooks/devstack/recipes/keystone.rb delete mode 100644 cookbooks/devstack/recipes/mon-ui.rb delete mode 100644 cookbooks/devstack/templates/default/my.cnf.erb delete mode 100644 cookbooks/devstack/templates/default/rabbitmq.cnf.erb delete mode 100644 roles/Devstack.json create mode 100644 roles/monasca-devstack/README.md create mode 100644 roles/monasca-devstack/defaults/main.yml create mode 100644 roles/monasca-devstack/handlers/main.yml create mode 100644 roles/monasca-devstack/meta/main.py create mode 100644 roles/monasca-devstack/tasks/agent_mysql.yaml create mode 100644 roles/monasca-devstack/tasks/agent_rabbitmq.yaml create mode 100644 roles/monasca-devstack/tasks/main.yml create mode 100644 roles/monasca-devstack/templates/my_cnf.j2 create mode 100644 roles/monasca-devstack/templates/rabbitmq_cnf.j2 create mode 100644 roles/monasca-devstack/vars/main.yml diff --git a/.gitignore b/.gitignore index 5ced140..fc6baee 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ .settings *.deb *.pyc -roles +roles/tkuhlman.* +roles/stympy.influxdb diff --git a/Vagrantfile b/Vagrantfile index e5b56ce..b66ed9b 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -34,13 +34,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| vb.memory = 7168 vb.cpus = 4 end - ds.vm.provision :chef_solo do |chef| - chef.roles_path = "roles" - chef.cookbooks_path = "cookbooks" - chef.data_bags_path = "data_bags" - chef.add_role "Devstack" - chef.arguments = '--force-formatter' - end ds.vm.provision "ansible" do |ansible| ansible.playbook = "devstack.yml" end diff --git a/ansible_roles b/ansible_roles index 13c0cb3..7258f1b 100644 --- a/ansible_roles +++ b/ansible_roles @@ -1,12 +1,17 @@ +monasca-devstack + tkuhlman.kafka tkuhlman.monasca-agent tkuhlman.monasca-api +tkuhlman.monasca-keystone tkuhlman.monasca-notification tkuhlman.monasca-persister tkuhlman.monasca-schema tkuhlman.monasca-thresh +tkuhlman.monasca-ui tkuhlman.percona tkuhlman.storm tkuhlman.zookeeper + stympy.influxdb diff --git a/cookbooks/devstack/README.md b/cookbooks/devstack/README.md deleted file mode 100644 index 0bfda22..0000000 --- a/cookbooks/devstack/README.md +++ /dev/null @@ -1,11 +0,0 @@ -devstack cookbook -========================= -Various helper recipes for the devstack server setup. - -Requirements ------------- - -Recipes ---------- -- mon-ui - installs the Monitoring panel in the UI -- keystone - simple keystone installation diff --git a/cookbooks/devstack/metadata.rb b/cookbooks/devstack/metadata.rb deleted file mode 100644 index b5d653e..0000000 --- a/cookbooks/devstack/metadata.rb +++ /dev/null @@ -1,7 +0,0 @@ -name "devstack" -maintainer "Mon Team" -maintainer_email "hpcs-mon@hp.com" -license "All rights reserved" -description "Customizes devstack server for use with mini-mon" -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.0.6" diff --git a/cookbooks/devstack/recipes/agent_plugin_config.rb b/cookbooks/devstack/recipes/agent_plugin_config.rb deleted file mode 100644 index c0cea07..0000000 --- a/cookbooks/devstack/recipes/agent_plugin_config.rb +++ /dev/null @@ -1,40 +0,0 @@ -plugin_config = data_bag_item('devstack', 'agent_plugin_config') - -service "rabbitmq-server" do - action :nothing - supports :status => true, :start => true, :stop => true, :restart => true -end - -execute "enable-rabbitmq-web-mgmt" do - command "/usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management" - not_if "/usr/lib/rabbitmq/bin/rabbitmq-plugins list -e | grep rabbitmq_management" - not_if { ::File.file?('/root/.rabbitmq.cnf') } - notifies :restart, "service[rabbitmq-server]", :delayed -end - -template "/root/.rabbitmq.cnf" do - action :create - source "rabbitmq.cnf.erb" - owner 'root' - group 'root' - mode 0600 - not_if { ::File.file?('/root/.rabbitmq.cnf') } - variables( - :plugin_config => plugin_config - ) -end - -package 'python-mysqldb' do - action :install -end -template "/root/.my.cnf" do - action :create - source "my.cnf.erb" - owner 'root' - group 'root' - mode 0600 - not_if { ::File.directory?('/root/.my.cnf') } - variables( - :plugin_config => plugin_config - ) -end diff --git a/cookbooks/devstack/recipes/default.rb b/cookbooks/devstack/recipes/default.rb deleted file mode 100644 index 4e45d6b..0000000 --- a/cookbooks/devstack/recipes/default.rb +++ /dev/null @@ -1 +0,0 @@ -# Add any necessary customizations here diff --git a/cookbooks/devstack/recipes/keystone.rb b/cookbooks/devstack/recipes/keystone.rb deleted file mode 100644 index 6f23618..0000000 --- a/cookbooks/devstack/recipes/keystone.rb +++ /dev/null @@ -1,77 +0,0 @@ -# Sets up a user mini-mon username/password in keystone - -python 'make default keystone users' do - action :run - code <<-EOH -import keystoneclient -from keystoneclient.v2_0 import client - -def add_service_endpoint(key, service_name, endpoint_host): - """Add the Monasca service to the catalog with the specified endpoint, if it doesn't yet exist.""" - service_names = { service.name: service.id for service in key.services.list() } - if service_name in service_names.keys(): - service_id = service_names[service_name] - else: - service=key.services.create(name=service_name, service_type='monitoring', description='Monasca monitoring service') - service_id = service.id - - for endpoint in key.endpoints.list(): - if endpoint.service_id == service_id: - return - - key.endpoints.create(region="RegionOne", service_id=service_id, - publicurl="http://%s:8080/v2.0/" % endpoint_host, - adminurl="http://%s:8080/v2.0/" % endpoint_host, - internalurl="http://%s:8080/v2.0/" % endpoint_host) - -def create_user(user_name, password, email,tenant_id): - user_id = None - user_list = key.users.list() - - # Create the user if it doesn't exist - for user in user_list: - if user.name == user_name: - user_id = user.id - - if user_id is None: - user_id = key.users.create(name=user_name, password=password, email=email, tenant_id=tenant_id, enabled=True) - - return user_id - -def create_role(user_name, role_name, tenant_id): - role_id = None - for role in key.roles.list(): - if role.name == role_name: - role_id = role.id - - #create role it doesn't exist - if role_id is None: - role_id = key.roles.create(role_name) - key.roles.add_user_role(user_name, role_id, tenant_id) - -def create_tenant(tenant_name): - tenant_id = None - for tenant in key.tenants.list(): - if tenant.name == tenant_name: - tenant_id = tenant.id - - if tenant_id is None: - tenant_id = key.tenants.create(tenant_name).id - - return tenant_id - -try: - key = client.Client(token='ADMIN', endpoint='http://127.0.0.1:35357/v2.0/') -except keystoneclient.exceptions: - time.sleep(2) # Sometimes chef is too fast and the service is not yet up - key = client.Client(token='ADMIN', endpoint='http://127.0.0.1:35357/v2.0/') - -tenant_id = create_tenant('mini-mon') -create_user('mini-mon', 'password', 'mini@mon.com', tenant_id) -monasca_user_id = create_user('monasca-agent', 'password', 'monasca-agent@mon.com', tenant_id) - -create_role(monasca_user_id, 'monasca-agent', tenant_id) - -add_service_endpoint(key, 'monasca', '192.168.10.4') -EOH -end diff --git a/cookbooks/devstack/recipes/mon-ui.rb b/cookbooks/devstack/recipes/mon-ui.rb deleted file mode 100644 index ed8801e..0000000 --- a/cookbooks/devstack/recipes/mon-ui.rb +++ /dev/null @@ -1,32 +0,0 @@ -# Installs the mon-ui panel - -package 'python-pip' do - action :install -end - -# Grab the necessary packages -['monasca-ui','python-monascaclient'].each do |pkg| - execute "pip install #{pkg}" do - action :run - end -end - -# Set up symlinks -# Use 'execute' resource because chef does not support symlinking directories -if !::File.exists?("/opt/stack/horizon/monitoring") - execute "ln -sfv /usr/local/lib/python2.7/dist-packages/monitoring/enabled/* /opt/stack/horizon/openstack_dashboard/local/enabled/" - execute "ln -sv /usr/local/lib/python2.7/dist-packages/monitoring /opt/stack/horizon/monitoring" -end - -# install grafana and integrate with horizon -if !::File.exists?("/usr/local/lib/python2.7/dist-packages/monitoring/static/grafana") - execute "git clone https://github.com/hpcloud-mon/grafana.git /opt/stack/grafana" - execute "cp /opt/stack/grafana/src/config.monasca.js /opt/stack/grafana/src/config.js" - execute "ln -sv /opt/stack/grafana/src /usr/local/lib/python2.7/dist-packages/monitoring/static/grafana" -end - -# Bounce the webserver -service "apache2" do - action :restart -end - diff --git a/cookbooks/devstack/templates/default/my.cnf.erb b/cookbooks/devstack/templates/default/my.cnf.erb deleted file mode 100644 index eb37e39..0000000 --- a/cookbooks/devstack/templates/default/my.cnf.erb +++ /dev/null @@ -1,3 +0,0 @@ -[client] -user=<%= @plugin_config['mysql']['user'] %> -password=<%= @plugin_config['mysql']['password'] %> diff --git a/cookbooks/devstack/templates/default/rabbitmq.cnf.erb b/cookbooks/devstack/templates/default/rabbitmq.cnf.erb deleted file mode 100644 index ede02ec..0000000 --- a/cookbooks/devstack/templates/default/rabbitmq.cnf.erb +++ /dev/null @@ -1,6 +0,0 @@ -[client] -user=<%= @plugin_config['rabbitmq']['user'] %> -password=<%= @plugin_config['rabbitmq']['password'] %> -nodes=<%= @plugin_config['rabbitmq']['nodes'] %> -queues=<%= @plugin_config['rabbitmq']['queues'] %> -exchanges=<%= @plugin_config['rabbitmq']['exchanges'] %> diff --git a/devstack.yml b/devstack.yml index 5765cf0..6c4d29e 100644 --- a/devstack.yml +++ b/devstack.yml @@ -1,13 +1,16 @@ - hosts: devstack sudo: yes vars: - keystone_url: http://192.168.10.5:35357/v3 + monasca_api_host: 192.168.10.4 monasca_agent: user: monasca-agent password: password project: mini-mon service: monitoring - monasca_api_url: http://192.168.10.4:8080/v2.0 + minimon: + user: mini-mon + password: password + monasca_api_url: http://{{ monasca_api_host }}:8080/v2.0 monasca_checks: host_alive: init_config: @@ -19,5 +22,23 @@ name: mini-mon host_name: 192.168.10.4 alive_test: ssh + keystone_url: http://192.168.10.5:35357/v2.0 + keystone_admin_token: ADMIN + keystone_users: + mini-mon: + tenant: mini-mon + password: password + monasca-agent: + password: password + tenant: mini-mon + role: monasca-agent + keystone_endpoint: + name: monasca + host: "{{ monasca_api_host }}" + roles: + - {role: tkuhlman.monasca-ui, tags: [ui]} + - {role: tkuhlman.monasca-keystone, tags: [devstack, keystone]} + - {role: monasca-devstack, tags: [devstack]} - {role: tkuhlman.monasca-agent, tags: [agent]} + diff --git a/roles/Devstack.json b/roles/Devstack.json deleted file mode 100644 index cda3b6f..0000000 --- a/roles/Devstack.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "Devstack", - "description": "Sets up a devstack server for keystone and UI", - "json_class": "Chef::Role", - "default_attributes": { - "apt": { - "periodic_update_min_delay": 60 - } - }, - "override_attributes": { - }, - "chef_type": "role", - "run_list": [ - "recipe[devstack::mon-ui]", - "recipe[devstack::keystone]", - "recipe[devstack::agent_plugin_config]" - ], - "env_run_lists": { - } -} diff --git a/roles/monasca-devstack/README.md b/roles/monasca-devstack/README.md new file mode 100644 index 0000000..c8d7f81 --- /dev/null +++ b/roles/monasca-devstack/README.md @@ -0,0 +1,31 @@ +#Devstack +Configures certain Monasca Agent plugins to work on a Devstak VM + +Plugins configured: +- MySQL +- RabbitMQ + +Usernames and passwords may need to be changed from defaults to reflect the +devstack environment: +- MySQL + - mysql_user + - mysql_pass +- RabbitMQ + - rmq_user + - rmq_pass + - rmq_nodes + - rmq_queues + - rmq_exchanges + +##Requirements +- tkuhlman.monasca-agent + +##Optional + +##License +Apache + +##Author Information +David Schroeder + +Monasca Team email monasca@lists.launchpad.net diff --git a/roles/monasca-devstack/defaults/main.yml b/roles/monasca-devstack/defaults/main.yml new file mode 100644 index 0000000..9a748c0 --- /dev/null +++ b/roles/monasca-devstack/defaults/main.yml @@ -0,0 +1,8 @@ +--- +mysql_user: root +mysql_pass: pass +rmq_user: guest +rmq_pass: pass +rmq_nodes: rabbit@devstack +rmq_queues: conductor +rmq_exchanges: nova,cinder,ceilometer,glance,keystone,neutron,heat,ironic,openstack diff --git a/roles/monasca-devstack/handlers/main.yml b/roles/monasca-devstack/handlers/main.yml new file mode 100644 index 0000000..42e8555 --- /dev/null +++ b/roles/monasca-devstack/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart rabbitmq + service: name=rabbitmq-server state=restarted enabled=yes diff --git a/roles/monasca-devstack/meta/main.py b/roles/monasca-devstack/meta/main.py new file mode 100644 index 0000000..cbf8552 --- /dev/null +++ b/roles/monasca-devstack/meta/main.py @@ -0,0 +1,21 @@ +--- +galaxy_info: + author: David Schroeder + description: Configures a devstack instance to work with the Monasca project. + company: HP + license: Apache + min_ansible_version: 1.2 + platforms: + - name: Ubuntu + versions: + - all + categories: + - monitoring +dependencies: + - tkuhlman.monasca-agent + # List your role dependencies here, one per line. Only + # dependencies available via galaxy should be listed here. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + + diff --git a/roles/monasca-devstack/tasks/agent_mysql.yaml b/roles/monasca-devstack/tasks/agent_mysql.yaml new file mode 100644 index 0000000..2c478b8 --- /dev/null +++ b/roles/monasca-devstack/tasks/agent_mysql.yaml @@ -0,0 +1,9 @@ +--- +- name: install python-mysqldb package + apt: name=python-mysqldb state=present + +- name: create/update mysql config + template: dest={{ mysql_cnf_file }} owner=root group=root mode=0600 src=my_cnf.j2 + notify: + - run monasca-setup + diff --git a/roles/monasca-devstack/tasks/agent_rabbitmq.yaml b/roles/monasca-devstack/tasks/agent_rabbitmq.yaml new file mode 100644 index 0000000..a823cd2 --- /dev/null +++ b/roles/monasca-devstack/tasks/agent_rabbitmq.yaml @@ -0,0 +1,10 @@ +--- +- name: Agent RabbitMQ Plugin - Activate management plugin + rabbitmq_plugin: names=rabbitmq_management state=enabled new_only=no + +- name: Agent RabbitMQ Plugin - Create/update rabbitmq config + template: dest={{ rabbitmq_cnf_file }} owner=root group=root mode=0600 src=rabbitmq_cnf.j2 + notify: + - restart rabbitmq + - run monasca-setup + diff --git a/roles/monasca-devstack/tasks/main.yml b/roles/monasca-devstack/tasks/main.yml new file mode 100644 index 0000000..23e3095 --- /dev/null +++ b/roles/monasca-devstack/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- include: agent_rabbitmq.yaml tags=devstack_rabbitmq +- include: agent_mysql.yaml tags=devstack_mysql diff --git a/roles/monasca-devstack/templates/my_cnf.j2 b/roles/monasca-devstack/templates/my_cnf.j2 new file mode 100644 index 0000000..1534f64 --- /dev/null +++ b/roles/monasca-devstack/templates/my_cnf.j2 @@ -0,0 +1,4 @@ +[client] +user={{ mysql_user }} +password={{ mysql_pass }} + diff --git a/roles/monasca-devstack/templates/rabbitmq_cnf.j2 b/roles/monasca-devstack/templates/rabbitmq_cnf.j2 new file mode 100644 index 0000000..41a676d --- /dev/null +++ b/roles/monasca-devstack/templates/rabbitmq_cnf.j2 @@ -0,0 +1,7 @@ +[client] +user={{ rmq_user }} +password={{ rmq_pass }} +nodes={{ rmq_nodes }} +queues={{ rmq_queues }} +exchanges={{ rmq_exchanges }} + diff --git a/roles/monasca-devstack/vars/main.yml b/roles/monasca-devstack/vars/main.yml new file mode 100644 index 0000000..dace4ea --- /dev/null +++ b/roles/monasca-devstack/vars/main.yml @@ -0,0 +1,3 @@ +--- +rabbitmq_cnf_file: /root/.rabbitmq.cnf +mysql_cnf_file: /root/.my.cnf