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() |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 29 | timeout(time: 12, unit: 'HOURS') { |
| 30 | node { |
Jakub Josef | 88aaf83 | 2018-01-18 16:18:28 +0100 | [diff] [blame] | 31 | def workspace = common.getWorkspace() |
| 32 | def venv_path = "${workspace}/venv" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 33 | def env_vars |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 34 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 35 | // default STACK_TYPE is heat |
| 36 | if (!common.validInputParam('STACK_TYPE')) { |
| 37 | STACK_TYPE = 'heat' |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 40 | stage('Install environment') { |
| 41 | if (STACK_TYPE == 'heat') { |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 42 | |
Ivan Berezovskiy | 748620c | 2020-03-27 13:20:45 +0400 | [diff] [blame] | 43 | def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'latest' |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 44 | openstack.setupOpenstackVirtualenv(venv_path, openstackVersion) |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 45 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 46 | } else if (STACK_TYPE == 'aws') { |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 47 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 48 | env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_DEFAULT_REGION) |
| 49 | aws.setupVirtualEnv(venv_path) |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 50 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 51 | } else { |
| 52 | throw new Exception('Stack type is not supported') |
| 53 | } |
| 54 | |
Tomáš Kukrál | 2eb6005 | 2017-05-29 11:01:58 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 57 | stage('Delete stack') { |
| 58 | if (STACK_TYPE == 'heat') { |
Jakub Josef | 88aaf83 | 2018-01-18 16:18:28 +0100 | [diff] [blame] | 59 | def openstackCloud = openstack.createOpenstackEnv(venv_path, |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 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) |
| 64 | openstack.getKeystoneToken(openstackCloud, venv_path) |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 65 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 66 | common.infoMsg("Deleting Heat Stack " + STACK_NAME) |
| 67 | openstack.deleteHeatStack(openstackCloud, STACK_NAME, venv_path) |
| 68 | } else if (STACK_TYPE == 'aws') { |
| 69 | |
| 70 | aws.deleteStack(venv_path, env_vars, STACK_NAME) |
| 71 | |
| 72 | } else { |
| 73 | throw new Exception('Stack type is not supported') |
| 74 | } |
| 75 | |
| 76 | } |
| 77 | } |
Tomáš Kukrál | fc13aa3 | 2017-02-28 23:20:04 +0100 | [diff] [blame] | 78 | } |