blob: 4b67213bbdb8851dd8ca96c66140bd745bee9e0a [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:
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_CLIENT Versions of OpenStack python clients
14 * OPENSTACK_API_VERSION Version of the OpenStack API (2/3)
15 *
16 * AWS parameters:
17 * AWS_API_CREDENTIALS Credentials id AWS EC2 API
18 * AWS_DEFAULT_REGION EC2 region
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010019 */
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020020
Jakub Joseff68c52a2017-04-20 17:47:37 +020021common = new com.mirantis.mk.Common()
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010022git = new com.mirantis.mk.Git()
23openstack = new com.mirantis.mk.Openstack()
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020024aws = new com.mirantis.mk.Aws()
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010025salt = new com.mirantis.mk.Salt()
26
27node {
28
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020029 def venv_path = "${env.WORKSPACE}/venv"
30 def env_vars
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010031
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020032 // default STACK_TYPE is heat
33 if (!env.getEnvironment().containsKey("STACK_TYPE") || STACK_TYPE == '') {
34 STACK_TYPE = 'heat'
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010035 }
36
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020037 stage('Install environment') {
38 if (STACK_TYPE == 'heat') {
39
40 def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
41 openstack.setupOpenstackVirtualenv(venv_path, openstackVersion)
42
43 } else if (STACK_TYPE == 'aws') {
44
45 env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
46 aws.setupVirtualEnv(venv_path)
47
48 } else {
49 throw new Exception('Stack type is not supported')
50 }
51
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010052 }
53
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020054 stage('Delete stack') {
55 if (STACK_TYPE == 'heat') {
56 def openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
57 openstack.getKeystoneToken(openstackCloud, venv_path)
58
59 common.infoMsg("Deleting Heat Stack " + STACK_NAME)
60 openstack.deleteHeatStack(openstackCloud, STACK_NAME, venv_path)
61 } else if (STACK_TYPE == 'aws') {
62
63 aws.deteteStack(venv_path, env_vars, STACK_NAME)
64 aws.waitForStatus(venv_path, evn_vars, STACK_NAME, 'DELETE_COMPLETE', ['DELETE_FAILED'])
65
66 } else {
67 throw new Exception('Stack type is not supported')
68 }
69
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010070 }
71
72}