Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 1 | /** |
| 2 | * |
Jakub Josef | 4cb727e | 2017-04-19 16:44:47 +0200 | [diff] [blame] | 3 | * Delete heat stack pipeline |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 4 | * |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 5 | * General |
| 6 | * STACK_NAME Heat stack name |
| 7 | * STACK_TYPE Type of the stack (heat, aws) |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 8 | * |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 9 | * Heat parameters: |
Matthew Mosesohn | 59fc648 | 2017-06-01 18:53:10 +0300 | [diff] [blame] | 10 | * OPENSTACK_API_URL OpenStack API address |
| 11 | * OPENSTACK_API_CREDENTIALS Credentials to the OpenStack API |
| 12 | * OPENSTACK_API_PROJECT OpenStack project to connect to |
| 13 | * OPENSTACK_API_PROJECT_DOMAIN Domain for OpenStack project |
| 14 | * OPENSTACK_API_PROJECT_ID ID for OpenStack project |
| 15 | * OPENSTACK_API_USER_DOMAIN Domain for OpenStack user |
| 16 | * OPENSTACK_API_CLIENT Versions of OpenStack python clients |
| 17 | * OPENSTACK_API_VERSION Version of the OpenStack API (2/3) |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 18 | * |
| 19 | * AWS parameters: |
| 20 | * AWS_API_CREDENTIALS Credentials id AWS EC2 API |
| 21 | * AWS_DEFAULT_REGION EC2 region |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 22 | */ |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 23 | |
Jakub Josef | f68c52a | 2017-04-20 17:47:37 +0200 | [diff] [blame] | 24 | common = new com.mirantis.mk.Common() |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 25 | git = new com.mirantis.mk.Git() |
| 26 | openstack = new com.mirantis.mk.Openstack() |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 27 | aws = new com.mirantis.mk.Aws() |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 28 | salt = new com.mirantis.mk.Salt() |
| 29 | |
| 30 | node { |
| 31 | |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 32 | def venv_path = "${env.WORKSPACE}/venv" |
| 33 | def env_vars |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 34 | |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 35 | // default STACK_TYPE is heat |
Tomáš Kukrál | cfd581e | 2017-08-09 10:17:56 +0200 | [diff] [blame] | 36 | if (!common.validInputParam('STACK_TYPE')) { |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 37 | STACK_TYPE = 'heat' |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 40 | stage('Install environment') { |
| 41 | if (STACK_TYPE == 'heat') { |
| 42 | |
| 43 | def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty' |
| 44 | openstack.setupOpenstackVirtualenv(venv_path, openstackVersion) |
| 45 | |
| 46 | } else if (STACK_TYPE == 'aws') { |
| 47 | |
Tomáš Kukrál | fce9b91 | 2017-06-02 13:30:55 +0200 | [diff] [blame] | 48 | env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_DEFAULT_REGION) |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 49 | aws.setupVirtualEnv(venv_path) |
| 50 | |
| 51 | } else { |
| 52 | throw new Exception('Stack type is not supported') |
| 53 | } |
| 54 | |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 57 | stage('Delete stack') { |
| 58 | if (STACK_TYPE == 'heat') { |
Matthew Mosesohn | 59fc648 | 2017-06-01 18:53:10 +0300 | [diff] [blame] | 59 | def openstackCloud = openstack.createOpenstackEnv( |
| 60 | OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, |
| 61 | OPENSTACK_API_PROJECT,OPENSTACK_API_PROJECT_DOMAIN, |
| 62 | OPENSTACK_API_PROJECT_ID, OPENSTACK_API_USER_DOMAIN, |
| 63 | OPENSTACK_API_VERSION) |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 64 | openstack.getKeystoneToken(openstackCloud, venv_path) |
| 65 | |
| 66 | common.infoMsg("Deleting Heat Stack " + STACK_NAME) |
| 67 | openstack.deleteHeatStack(openstackCloud, STACK_NAME, venv_path) |
| 68 | } else if (STACK_TYPE == 'aws') { |
| 69 | |
Tomáš Kukrál | c24e328 | 2017-06-02 14:03:50 +0200 | [diff] [blame] | 70 | aws.deleteStack(venv_path, env_vars, STACK_NAME) |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 71 | |
| 72 | } else { |
| 73 | throw new Exception('Stack type is not supported') |
| 74 | } |
| 75 | |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | } |