Jakub Josef | 4cb727e | 2017-04-19 16:44:47 +0200 | [diff] [blame^] | 1 | /** |
| 2 | * |
| 3 | * Delete broken heat stacks pipeline (in CREATE_FAILED or DELETE_FAILED state) |
| 4 | * |
| 5 | * Expected parameters: |
| 6 | * OPENSTACK_API_URL OpenStack API address |
| 7 | * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API |
| 8 | * OPENSTACK_API_PROJECT OpenStack project to connect to |
| 9 | * OPENSTACK_API_CLIENT Versions of OpenStack python clients |
| 10 | * OPENSTACK_API_VERSION Version of the OpenStack API (2/3) |
| 11 | * |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | git = new com.mirantis.mk.Git() |
| 16 | openstack = new com.mirantis.mk.Openstack() |
| 17 | salt = new com.mirantis.mk.Salt() |
| 18 | |
| 19 | node { |
| 20 | |
| 21 | // connection objects |
| 22 | def openstackCloud |
| 23 | // value defaults |
| 24 | def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty' |
| 25 | def openstackEnv = "${env.WORKSPACE}/venv" |
| 26 | |
| 27 | stage('Install OpenStack env') { |
| 28 | openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion) |
| 29 | } |
| 30 | |
| 31 | stage('Connect to OpenStack cloud') { |
| 32 | openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT) |
| 33 | openstack.getKeystoneToken(openstackCloud, openstackEnv) |
| 34 | } |
| 35 | |
| 36 | stage('Delete broken Heat stacks') { |
| 37 | // get failed stacks |
| 38 | def brokenStacks = [] |
| 39 | brokenStacks.addAll(openstack.getStacksWithStatus(openstackCloud, "CREATE_FAILED", openstackEnv)) |
| 40 | brokenStacks.addAll(openstack.getStacksWithStatus(openstackCloud, "DELETE_FAILED", openstackEnv)) |
| 41 | for(int i=0;i<brokenStacks.size();i++){ |
| 42 | openstack.deleteHeatStack(openstackCloud, brokenStacks[i], openstackEnv) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | } |