blob: 001e6c0e9cbf60ddffd9f20bcb315a491a7edc0a [file] [log] [blame]
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +01001/**
2 *
Jakub Josef4cb727e2017-04-19 16:44:47 +02003 * Delete heat stack pipeline
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +01004 *
Tomáš Kukrál2eb60052017-05-29 11:01:58 +02005 * General
6 * STACK_NAME Heat stack name
7 * STACK_TYPE Type of the stack (heat, aws)
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +01008 *
Tomáš Kukrál2eb60052017-05-29 11:01:58 +02009 * Heat parameters:
Matthew Mosesohn59fc6482017-06-01 18:53:10 +030010 * 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ál2eb60052017-05-29 11:01:58 +020018 *
19 * AWS parameters:
20 * AWS_API_CREDENTIALS Credentials id AWS EC2 API
21 * AWS_DEFAULT_REGION EC2 region
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010022 */
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020023
Jakub Joseff68c52a2017-04-20 17:47:37 +020024common = new com.mirantis.mk.Common()
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010025git = new com.mirantis.mk.Git()
26openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020027aws = new com.mirantis.mk.Aws()
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010028salt = new com.mirantis.mk.Salt()
Jakub Josefa63f9862018-01-11 17:58:38 +010029timeout(time: 12, unit: 'HOURS') {
30 node {
Jakub Josef88aaf832018-01-18 16:18:28 +010031 def workspace = common.getWorkspace()
32 def venv_path = "${workspace}/venv"
Jakub Josefa63f9862018-01-11 17:58:38 +010033 def env_vars
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010034
Jakub Josefa63f9862018-01-11 17:58:38 +010035 // default STACK_TYPE is heat
36 if (!common.validInputParam('STACK_TYPE')) {
37 STACK_TYPE = 'heat'
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020038 }
39
Jakub Josefa63f9862018-01-11 17:58:38 +010040 stage('Install environment') {
41 if (STACK_TYPE == 'heat') {
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010042
Jakub Josefa63f9862018-01-11 17:58:38 +010043 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
44 openstack.setupOpenstackVirtualenv(venv_path, openstackVersion)
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020045
Jakub Josefa63f9862018-01-11 17:58:38 +010046 } else if (STACK_TYPE == 'aws') {
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020047
Jakub Josefa63f9862018-01-11 17:58:38 +010048 env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_DEFAULT_REGION)
49 aws.setupVirtualEnv(venv_path)
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020050
Jakub Josefa63f9862018-01-11 17:58:38 +010051 } else {
52 throw new Exception('Stack type is not supported')
53 }
54
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020055 }
56
Jakub Josefa63f9862018-01-11 17:58:38 +010057 stage('Delete stack') {
58 if (STACK_TYPE == 'heat') {
Jakub Josef88aaf832018-01-18 16:18:28 +010059 def openstackCloud = openstack.createOpenstackEnv(venv_path,
Jakub Josefa63f9862018-01-11 17:58:38 +010060 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álfc13aa32017-02-28 23:20:04 +010065
Jakub Josefa63f9862018-01-11 17:58:38 +010066 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álfc13aa32017-02-28 23:20:04 +010078}