Merge pull request #11818 from Java1Guy/module_utils_ec2_for_ecs

change ec2 util to create only requested objects
pull/12302/head
Benno Joy 9 years ago
commit 6de13c3062

@ -25,6 +25,7 @@
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os, boto3
try: try:
from distutils.version import LooseVersion from distutils.version import LooseVersion
@ -37,14 +38,15 @@ def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None
if conn_type not in ['both', 'resource', 'client']: if conn_type not in ['both', 'resource', 'client']:
module.fail_json(msg='There is an issue in the code of the module. You must specify either both, resource or client to the conn_type parameter in the boto3_conn function call') module.fail_json(msg='There is an issue in the code of the module. You must specify either both, resource or client to the conn_type parameter in the boto3_conn function call')
resource = boto3.session.Session().resource(resource, region_name=region, endpoint_url=endpoint, **params)
client = resource.meta.client
if conn_type == 'resource': if conn_type == 'resource':
resource = boto3.session.Session().resource(resource, region_name=region, endpoint_url=endpoint, **params)
return resource return resource
elif conn_type == 'client': elif conn_type == 'client':
client = boto3.session.Session().client(resource, region_name=region, endpoint_url=endpoint, **params)
return client return client
else: else:
resource = boto3.session.Session().resource(resource, region_name=region, endpoint_url=endpoint, **params)
client = boto3.session.Session().client(resource, region_name=region, endpoint_url=endpoint, **params)
return client, resource return client, resource
def aws_common_argument_spec(): def aws_common_argument_spec():

Loading…
Cancel
Save