blob: c858361ea181cf996b794cc3477f9377d341305f [file] [log] [blame]
ecnoelc8bb28a2017-07-06 09:02:01 -05001'''
2/*-
3* ============LICENSE_START=======================================================
Patrick Brady10bba352017-07-19 12:09:28 -07004* ONAP : APPC
ecnoelc8bb28a2017-07-06 09:02:01 -05005* ================================================================================
6* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
7* ================================================================================
Patrick Brady10bba352017-07-19 12:09:28 -07008* Copyright (C) 2017 Amdocs
9* =============================================================================
ecnoelc8bb28a2017-07-06 09:02:01 -050010* Licensed under the Apache License, Version 2.0 (the "License");
11* you may not use this file except in compliance with the License.
12* You may obtain a copy of the License at
13*
14* http://www.apache.org/licenses/LICENSE-2.0
15*
16* Unless required by applicable law or agreed to in writing, software
17* distributed under the License is distributed on an "AS IS" BASIS,
18* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19* See the License for the specific language governing permissions and
20* limitations under the License.
Patrick Brady10bba352017-07-19 12:09:28 -070021*
ecnoelc8bb28a2017-07-06 09:02:01 -050022* ECOMP is a trademark and service mark of AT&T Intellectual Property.
Patrick Brady10bba352017-07-19 12:09:28 -070023* ============LICENSE_END=========================================================
ecnoelc8bb28a2017-07-06 09:02:01 -050024*/
25'''
26
27============
28INSTALLATION:
29============
30
31Python:
32-------
33sudo apt-get install python2.7
34sudo apt-get install python-pip
35pip install PyMySQL
36pip install requests
37
38Ansible:
39--------
40sudo apt-get install software-properties-common
41sudo apt-add-repository ppa:ansible/ansible
42sudo apt-get update
43sudo apt-get install ansible
44
45SQL db:
46-------
47
48sudo apt-get install mysql-server
49
50Set root passwd during installation (i.e. password_4_mysql_user_id)
51
52sudo service mysql restart
53
54Setup mysql:
55------------
56
57mysql -u [username]-p
58mysql -uroot -p
59
60Create user (i.e. id=mysql_user_id psswd=password_4_mysql_user_id)
61 CREATE USER 'appc'@'%' IDENTIFIED BY 'password_4_mysql_user_id';
62 GRANT ALL PRIVILEGES ON *.* TO 'mysql_user_id'@'%';
63 SET PASSWORD FOR 'mysql_user_id'@'%'=PASSWORD('password_4_mysql_user_id');
64
65Create schema
66 CREATE SCHEMA ansible;
67 show databases;
68 use ansible;
69 CREATE TABLE playbook (name VARCHAR(45) NOT NULL, value BLOB, type VARCHAR(60), version VARCHAR(60), PRIMARY KEY (name));
70 show tables;
71 CREATE TABLE inventory (hostname VARCHAR(45) NOT NULL, hostgroup VARCHAR(45), credentials VARCHAR(500), PRIMARY KEY (hostname));
72 SHOW COLUMNS FROM playbook;
73 SHOW COLUMNS FROM inventory;
74 GRANT ALL PRIVILEGES ON *.* TO 'mysql_user_id'@'%' IDENTIFIED BY 'password_4_mysql_user_id' WITH GRANT OPTION;
75 GRANT ALL PRIVILEGES ON *.* TO 'ansible'@'%' IDENTIFIED BY 'ansible_agent' WITH GRANT OPTION;
76 FLUSH PRIVILEGES;
77
78Load db:
79--------
80
81python LoadAnsibleMySql.py
82
83=============
84CODE TESTING:
85=============
861. Start RestServer: python RestServer.py
87
882. Try curl commands (case no secured REST: http & no authentication):
89
90- Request to execute playbook:
91curl -H "Content-type: application/json" -X POST -d '{"Id": "10", "PlaybookName": "ansible_sleep", "NodeList": ["host"], "Timeout": "60", "EnvParameters": {"Sleep": "10"}}' http://0.0.0.0:8000/Dispatch
92
93response: {"ExpectedDuration": "60sec", "StatusMessage": "PENDING", "StatusCode": 100}
94
95- Get results (blocked until test finished):
96curl --cacert ~/SshKey/fusion_eric-vm_cert.pem --user "appc:abc123" -H "Content-type: application/json" -X GET "http://0.0.0.0:8000/Dispatch/?Id=10&Type=GetResult"
97
98response: {"Results": {"localhost": {"GroupName": "host", "StatusMessage": "SUCCESS", "StatusCode": 200}}, "PlaybookName": "ansible_sleep", "Version": "0.00", "Duration": "11.261794", "StatusMessage": "FINISHED", "StatusCode": 200}
99
100- Delete playbook execution information
101curl --cacert ~/SshKey/fusion_eric-vm_cert.pem --user "appc:abc123" -H "Content-type: application/json" -X DELETE http://0.0.0.0:8000/Dispatch/?Id=10
102
103response: {"StatusMessage": "PLAYBOOK EXECUTION RECORDS DELETED", "StatusCode": 200}