@ -1,23 +1,22 @@
#!/usr/bin/python
# coding: utf-8 -*-
# coding: utf-8 -*-
#
# (c) 2016, Mathieu Bultel <mbultel@redhat.com>
# (c) 2016, Steve Baker <sbaker@redhat.com>
#
# This module is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# http://www.apache.org/licenses/LICENSE-2.0
#
# You should have received a copy of the GNU General Public License
# along with this software. If not, see <http://www.gnu.org/licenses/>.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from time import sleep
from distutils . version import StrictVersion
try :
import shade
@ -152,25 +151,27 @@ stack:
' updated_time ' : null } "
'''
def _create_stack ( module , stack , cloud ) :
try :
stack = cloud . create_stack ( module . params [ ' name ' ] ,
template_file = module . params [ ' template ' ] ,
environment_files = module . params [ ' environment ' ] ,
timeout = module . params [ ' timeout ' ] ,
wait = True ,
rollback = module . params [ ' rollback ' ] ,
* * module . params [ ' parameters ' ] )
template_file = module . params [ ' template ' ] ,
environment_files = module . params [ ' environment ' ] ,
timeout = module . params [ ' timeout ' ] ,
wait = True ,
rollback = module . params [ ' rollback ' ] ,
* * module . params [ ' parameters ' ] )
stack = cloud . get_stack ( stack . id , None )
if stack . stack_status == ' CREATE_COMPLETE ' :
return stack
else :
return False
module . fail_json ( msg = " Failure in creating stack: " . format ( stack ) )
module . fail_json ( msg = " Failure in creating stack: " . format ( stack ) )
except shade . OpenStackCloudException as e :
module . fail_json ( msg = str ( e ) )
def _update_stack ( module , stack , cloud ) :
try :
stack = cloud . update_stack (
@ -184,11 +185,12 @@ def _update_stack(module, stack, cloud):
if stack [ ' stack_status ' ] == ' UPDATE_COMPLETE ' :
return stack
else :
module . fail_json ( msg = " Failure in updating stack: %s " %
module . fail_json ( msg = " Failure in updating stack: %s " %
stack [ ' stack_status_reason ' ] )
except shade . OpenStackCloudException as e :
module . fail_json ( msg = str ( e ) )
def _system_state_change ( module , stack , cloud ) :
state = module . params [ ' state ' ]
if state == ' present ' :
@ -198,6 +200,7 @@ def _system_state_change(module, stack, cloud):
return True
return False
def main ( ) :
argument_spec = openstack_full_argument_spec (
@ -255,8 +258,9 @@ def main():
except shade . OpenStackCloudException as e :
module . fail_json ( msg = str ( e ) )
from ansible . module_utils . basic import *
from ansible . module_utils . openstack import *
if __name__ == ' __main__ ' :
main ( )