blob: a2949ebc1e576148a982350515dd633b3eeab893 [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()
29
30node {
31
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020032 def venv_path = "${env.WORKSPACE}/venv"
33 def env_vars
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010034
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020035 // default STACK_TYPE is heat
36 if (!env.getEnvironment().containsKey("STACK_TYPE") || STACK_TYPE == '') {
37 STACK_TYPE = 'heat'
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010038 }
39
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020040 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
48 env_vars = aws.getEnvVars(AWS_API_CREDENTIALS, AWS_STACK_REGION)
49 aws.setupVirtualEnv(venv_path)
50
51 } else {
52 throw new Exception('Stack type is not supported')
53 }
54
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010055 }
56
Tomáš Kukrál2eb60052017-05-29 11:01:58 +020057 stage('Delete stack') {
58 if (STACK_TYPE == 'heat') {
Matthew Mosesohn59fc6482017-06-01 18:53:10 +030059 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ál2eb60052017-05-29 11:01:58 +020064 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
70 aws.deteteStack(venv_path, env_vars, STACK_NAME)
71 aws.waitForStatus(venv_path, evn_vars, STACK_NAME, 'DELETE_COMPLETE', ['DELETE_FAILED'])
72
73 } else {
74 throw new Exception('Stack type is not supported')
75 }
76
Tomáš Kukrálfc13aa32017-02-28 23:20:04 +010077 }
78
79}