Timoney, Dan (dt5972) | 1262205 | 2018-09-12 10:53:10 -0400 | [diff] [blame] | 1 | ''' |
| 2 | /*- |
| 3 | * ============LICENSE_START======================================================= |
| 4 | * ONAP : APPC |
| 5 | * ================================================================================ |
| 6 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 7 | * ================================================================================ |
| 8 | * Copyright (C) 2017 Amdocs |
| 9 | * ============================================================================= |
| 10 | * 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. |
| 21 | * |
| 22 | * ECOMP is a trademark and service mark of AT&T Intellectual Property. |
| 23 | * ============LICENSE_END========================================================= |
| 24 | */ |
| 25 | ''' |
| 26 | |
| 27 | ============ |
| 28 | INSTALLATION: |
| 29 | ============ |
| 30 | |
| 31 | Python: |
| 32 | ------- |
| 33 | sudo apt-get install python2.7 |
| 34 | sudo apt-get install python-pip |
| 35 | pip install PyMySQL |
| 36 | pip install requests |
| 37 | |
| 38 | Ansible: |
| 39 | -------- |
| 40 | sudo apt-get install software-properties-common |
| 41 | sudo apt-add-repository ppa:ansible/ansible |
| 42 | sudo apt-get update |
| 43 | sudo apt-get install ansible |
| 44 | |
| 45 | SQL db: N/A for SDNC |
| 46 | ------- |
| 47 | |
| 48 | sudo apt-get install mysql-server |
| 49 | |
| 50 | Set root passwd during installation (i.e. password_4_mysql_user_id) |
| 51 | |
| 52 | sudo service mysql restart |
| 53 | |
| 54 | Setup mysql: N/A for SDNC |
| 55 | ------------ |
| 56 | |
| 57 | mysql -u [username]-p |
| 58 | mysql -uroot -p |
| 59 | |
| 60 | Create 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 | |
| 65 | Create 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 | |
| 78 | Load db: N/A for SDNC |
| 79 | -------- |
| 80 | |
| 81 | python LoadAnsibleMySql.py |
| 82 | |
| 83 | ============= |
| 84 | CODE TESTING: |
| 85 | ============= |
| 86 | 1. Start RestServer: python RestServer.py |
| 87 | |
| 88 | 2. Try curl commands (case no secured REST: http & no authentication): |
| 89 | |
| 90 | - Request to execute playbook: |
| 91 | curl -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 | |
| 93 | response: {"ExpectedDuration": "60sec", "StatusMessage": "PENDING", "StatusCode": 100} |
| 94 | |
| 95 | - Get results (blocked until test finished): |
| 96 | curl --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 | |
| 98 | response: {"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 |
| 101 | curl --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 | |
| 103 | response: {"StatusMessage": "PLAYBOOK EXECUTION RECORDS DELETED", "StatusCode": 200} |