Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes necessary for ansible-installer #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#monasca-api
Installs the [monasca-api](https://github.com/stackforge/monasca-api) part of the [Monasca](https://wiki.openstack.org/wiki/Monasca) project.
There are two implementations of the API, one Java based and one Python based. This will install the Java based one by default. To install
the python implementation rather than the java implementation, set the variable `monasca_api_java` to False.

##Requirements
- api_region
Expand Down
31 changes: 28 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---
# ©Copyright 2015 Hewlett-Packard Development Company, L.P.

database_type: influxdb
influxdb_db: mon
cassandra_keyspace: mon
keystone_admin: admin
keystone_admin_tenant: admin
keystone_auth_method: password
keystone_admin_token:
keystone_port: 5000
Expand All @@ -11,19 +15,40 @@ monasca_admin_client_port: 8081
monasca_api_client_port: 8070
monasca_api_client_keystore:
monasca_api_client_keystore_password:
monasca_api_java: True
monasca_api_java_opts: -Xmx1g
monasca_api_log_file: monasca-api.log
monasca_api_truststore:
monasca_api_truststore_password:
monasca_api_keystore_password:
monasca_api_tarball_base_url: http://tarballs.openstack.org/ci/monasca-api
monasca_api_version: 1.1.0-SNAPSHOT
monasca_wait_for_period: 10
monasca_jar_dir: /opt/monasca
monasca_log_dir: /var/log/monasca
monasca_log_level: WARN
monasca_jar_dir: /opt/monasca
monasca_python_dir: /opt/monasca
monasca_virtualenv_dir: /opt/monasca
monasca_wait_for_period: 10
mysql_db: mon
database_type: influxdb

# API Roles
api_default_authorized_roles:
- user
- domainuser
- domainadmin
- monasca-user
api_agent_authorized_roles:
- monasca-agent
api_delegate_authorized_roles:
- admin

# Python API specific
api_gunicorn_version: 19.3.0
api_gunicorn_worker_connections: 2000
api_gunicorn_backlog: 1000
api_gunicorn_workers: 1

run_mode: Deploy
skip_install: False
verify: True
api_debug: False
55 changes: 10 additions & 45 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,9 @@
- name: setup group
group: name={{monasca_group}} system=yes

- name: Setup user
- name: setup user
user: name={{monasca_api_user}} system=yes group={{monasca_group}}

- name: create vertica dir
file: path={{monasca_jar_dir}}/vertica state=directory owner=root group=root mode=755
when: database_type == 'vertica'

- name: check if vertica jar exists
stat: path={{monasca_jar_dir}}/vertica/vertica_jdbc.jar
register: status
when: database_type == 'vertica'

- name: place vertica jdbc
command: cp {{vertica_jdbc_location}} {{monasca_jar_dir}}/vertica/vertica_jdbc.jar
when: database_type == 'vertica' and not status.stat.exists

- name: Ensure vertica jdbc permissions
file: path={{monasca_jar_dir}}/vertica/vertica_jdbc.jar mode=644
when: database_type == 'vertica'

- name: Detect if this is a systemd based system
command: cat /proc/1/comm
register: init
- set_fact: use_systemd=True
when: init.stdout == 'systemd'
- set_fact: use_systemd=False
when: init.stdout != 'systemd'

- name: create systemd config
template: dest={{api_systemd_service}} owner=root group=root mode=644 src=monasca-api.service.j2
notify:
- restart monasca-api
when: use_systemd

- command: systemctl daemon-reload
when: use_systemd

- name: create upstart script from template
template: dest=/etc/init/monasca-api.conf owner=root group=root mode=744 src=monasca-api.conf.j2
notify:
- restart monasca-api
when: not use_systemd

- name: create monasca log dir
file: path={{monasca_log_dir}} state=directory owner=root group={{monasca_group}} mode=775

Expand All @@ -56,10 +16,15 @@
- name: create conf_dir
file: path={{monasca_conf_dir}} state=directory owner=root group={{monasca_group}} mode=775

- name: create conf_file from template
template: dest={{api_conf_file}} owner={{monasca_api_user}} group={{monasca_group}} mode=640 src=api-config.yml.j2
notify:
- restart monasca-api
# select Java or Python

- include: java_configure.yml
when: monasca_api_java

- include: python_configure.yml
when: not (monasca_api_java | bool)

# --------

- name: Copy Truststore
copy: dest={{monasca_api_truststore}} src={{monasca_api_truststore_src}}
Expand Down
10 changes: 4 additions & 6 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
---
# ©Copyright 2015 Hewlett-Packard Development Company, L.P.

- name: create jar dir
file: path={{monasca_jar_dir}} state=directory owner=root group=root mode=755
- include: java_install.yml
when: monasca_api_java

- name: Fetch api jar
get_url: dest={{monasca_jar_dir}}/monasca-api.jar url="{{monasca_api_tarball_base_url}}/monasca-api-{{monasca_api_version}}-shaded.jar" force=yes
notify:
- restart monasca-api
- include: python_install.yml
when: not (monasca_api_java | bool)
48 changes: 48 additions & 0 deletions tasks/java_configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
# ©Copyright 2015 Hewlett-Packard Development Company, L.P.

- name: java | create vertica dir
file: path={{monasca_jar_dir}}/vertica state=directory owner=root group=root mode=755
when: database_type == 'vertica'

- name: java | check if vertica jar exists
stat: path={{monasca_jar_dir}}/vertica/vertica_jdbc.jar
register: status
when: database_type == 'vertica'

- name: java | place vertica jdbc
command: cp {{vertica_jdbc_location}} {{monasca_jar_dir}}/vertica/vertica_jdbc.jar
when: database_type == 'vertica' and not status.stat.exists

- name: java | Ensure vertica jdbc permissions
file: path={{monasca_jar_dir}}/vertica/vertica_jdbc.jar mode=644
when: database_type == 'vertica'

- name: java | Detect if this is a systemd based system
command: cat /proc/1/comm
register: init
- set_fact: use_systemd=True
when: init.stdout == 'systemd'
- set_fact: use_systemd=False
when: init.stdout != 'systemd'

- name: java | create systemd config
template: dest={{api_systemd_service}} owner=root group=root mode=644 src=monasca-api.service.j2
notify:
- restart monasca-api
when: use_systemd

- name: java | systemctl daemon-reload
command: systemctl daemon-reload
when: use_systemd

- name: java | create upstart script from template
template: dest=/etc/init/monasca-api.conf owner=root group=root mode=744 src=monasca-api.conf.j2
notify:
- restart monasca-api
when: not (use_systemd | bool)

- name: java | create conf_file from template
template: dest={{api_conf_file}} owner={{monasca_api_user}} group={{monasca_group}} mode=640 src=api-config.yml.j2
notify:
- restart monasca-api
10 changes: 10 additions & 0 deletions tasks/java_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# ©Copyright 2015 Hewlett-Packard Development Company, L.P.

- name: java | create jar dir
file: path={{monasca_jar_dir}} state=directory owner=root group=root mode=755

- name: java | fetch api jar
get_url: dest={{monasca_jar_dir}}/monasca-api.jar url="{{monasca_api_tarball_base_url}}/monasca-api-{{monasca_api_version}}-shaded.jar" force=yes
notify:
- restart monasca-api
2 changes: 2 additions & 0 deletions tasks/java_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# ©Copyright 2015 Hewlett-Packard Development Company, L.P.
8 changes: 7 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
---
# ©Copyright 2015 Hewlett-Packard Development Company, L.P.

- include: java_main.yml
when: monasca_api_java

- include: python_main.yml
when: not (monasca_api_java | bool)

- include: stop.yml
when: run_mode == 'Stop'

- include: install.yml
when: not skip_install and ( run_mode == 'Install' or run_mode == 'Deploy' )
when: not (skip_install | bool) and ( run_mode == 'Install' or run_mode == 'Deploy' )

- include: configure.yml
when: run_mode == 'Configure' or run_mode == 'Deploy'
Expand Down
48 changes: 48 additions & 0 deletions tasks/python_configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
# ©Copyright 2015 Hewlett-Packard Development Company, L.P.

- name: python | create api-config.conf from template
template: >
src=python.api-config.conf.j2
dest={{ monasca_conf_dir }}/api-config.conf
owner={{ monasca_api_user }}
group=root
mode=660
notify:
- restart monasca-api

- name: python | symlink api-config.conf
file: >
src={{ monasca_conf_dir }}/api-config.conf
dest=/etc/api-config.conf
owner=root
group=root
state=link

- name: python | create api-config.ini from template
template: >
src=python.api-config.ini.j2
dest={{ monasca_conf_dir }}/api-config.ini
owner={{ monasca_api_user }}
group=root
mode=660
notify:
- restart monasca-api

- name: python | symlink api-config.ini
file: >
src={{ monasca_conf_dir }}/api-config.ini
dest=/etc/api-config.ini
owner=root
group=root
state=link

- name: python | create upstart script from template
template: >
src=python.monasca-api.conf.j2
dest=/etc/init/monasca-api.conf
owner=root
group=root
mode=744
notify:
- restart monasca-api
77 changes: 77 additions & 0 deletions tasks/python_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
# ©Copyright 2015 Hewlett-Packard Development Company, L.P.

- name: python | update apt cache
apt: update_cache=yes cache_valid_time=3600

- name: Upgrade pip in virtualenv
pip: name=pip state=latest virtualenv="{{monasca_virtualenv_dir}}"

- name: python | install python packages
action: apt pkg={{ item }} state=latest
with_items:
- git
- python-dev
- libmysqlclient-dev

- name: create python base dir
file: path={{ monasca_python_dir }} state=directory owner=root group=root mode=755

- name: python | git clone monasca-api
git: >
repo=https://github.com/stackforge/monasca-api.git
dest={{ monasca_python_dir }}/monasca-api
notify:
- restart monasca-api
register: monasca_api_clone

# example patch section to merge in monasca-api changes that are pending review

#- name: python | create required patch for monasca-api
# shell: git fetch https://review.openstack.org/openstack/monasca-api refs/changes/18/240018/2 && git format-patch -1 --stdout FETCH_HEAD > 1.patch
# args:
# chdir: "{{ monasca_python_dir }}/monasca-api"
# when: (monasca_api_clone|changed)
#
#- name: python | apply required patch for monasca-api
# shell: git apply 1.patch
# args:
# chdir: "{{ monasca_python_dir }}/monasca-api"
# when: (monasca_api_clone|changed)

# ---- end of patch section

- name: python | create a source distribution
shell: python setup.py sdist
args:
chdir: "{{ monasca_python_dir }}/monasca-api"
creates: "{{ monasca_python_dir }}/monasca-api/dist"
register: monasca_api_sdist

- name: python | register source distribution
shell: ls -td {{ monasca_python_dir }}/monasca-api/dist/monasca-api-*.tar.gz
register: monasca_api_src_dist
when: (monasca_api_sdist|changed)

- name: python | pip install monasca-api
pip: >
name={{ monasca_api_src_dist.stdout }}
virtualenv={{ monasca_virtualenv_dir }}
extra_args='--pre --allow-all-external --allow-unverified simport'
notify:
- restart monasca-api
when: (monasca_api_sdist|changed)

- name: python | find monasca_api in virtualenv
shell: find $(pwd)/lib -name monasca_api
args:
chdir: "{{ monasca_virtualenv_dir }}"
register: venv_monasca_api

- name: python | symlink python API
file: >
src={{ venv_monasca_api.stdout }}
dest={{ monasca_python_dir }}/monasca_api
owner=root
group=root
state=link
6 changes: 6 additions & 0 deletions tasks/python_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# ©Copyright 2015 Hewlett-Packard Development Company, L.P.

- name: python | set API bind host if not specified
set_fact: monasca_api_bind_host="{{ monasca_api_host }}"
when: not (monasca_api_bind_host | default(False))
19 changes: 18 additions & 1 deletion templates/monasca-api.conf.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
#
# (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Startup script for the Monasca API

description "Monasca API java app"
description "Monasca API Java app"
start on runlevel [2345]

console log
Expand Down
Loading