%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlmZddl	m
Z
ddljj
Z
ddlZeje�ZyGddlZddlZddlZejd�jej�eZWnek
r�eZnXd�Zddddd�Zddddd	�Zdddddd
�Z ddddd�Z!dddddd�Z"ddddd
�Z#ddddd�Z$ddddd�Z%dddddd�Z&dddddd�Z'dddddd�Z(dddddddd�Z)ddddd�Z*ddddd�Z+ddddddddddddddddddddd�Z,eddddd�Z-ddddd�Z.ddddd�Z/ddddd�Z0ddddd�Z1dS(u
Connection module for Amazon Elasticache

.. versionadded:: 2014.7.0

:configuration: This module accepts explicit elasticache credentials but can
    also utilize IAM roles assigned to the instance through Instance Profiles.
    Dynamic credentials are then automatically obtained from AWS API and no
    further configuration is necessary. More Information available at:

    .. code-block:: text

        http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

    If IAM roles are not used you need to specify them either in a pillar or
    in the minion's config file:

    .. code-block:: yaml

        elasticache.keyid: GKTADJGHEIQSXMKKRBJ08H
        elasticache.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

    A region may also be specified in the configuration:

    .. code-block:: yaml

        elasticache.region: us-east-1

    If a region is not specified, the default is us-east-1.

    It's also possible to specify key, keyid and region via a profile, either
    as a passed in dict, or as a string to pull from pillars or minion config:

    .. code-block:: yaml

        myprofile:
            keyid: GKTADJGHEIQSXMKKRBJ08H
            key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
            region: us-east-1

:depends: boto
i(tabsolute_importtprint_functiontunicode_literalsN(tsix(tSaltInvocationErrorubotocC@sBtjjjdt�}|tkr>tdtddt�n|S(u,
    Only load if boto libraries exist.
    tcheck_boto3uboto.assign_funcsuelasticachetpack(	tsalttutilstversionstcheck_boto_reqstFalsetTruet	__utils__t__name__t__salt__(t
has_boto_reqs((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyt__virtual__Js
	c	C@sdtd|d|d|d|�}y|j|�tSWn'tjjk
r_}tj|�tSXdS(u�
    Check to see if a cache cluster exists.

    CLI example::

        salt myminion boto_elasticache.exists myelasticache
    tregiontkeytkeyidtprofileN(	t	_get_conntdescribe_cache_clustersRtbotot	exceptiontBotoServerErrortlogtdebugR(tnameRRRRtconnte((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pytexistsWs!

c	C@sdtd|d|d|d|�}y|j|�tSWn'tjjk
r_}tj|�tSXdS(u�
    Check to see if a replication group exists.

    CLI example::

        salt myminion boto_elasticache.group_exists myelasticache
    RRRRN(	Rtdescribe_replication_groupsRRRRRRR(RRRRRRR((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pytgroup_existsis!

c
	C@s�td|d|d|d|�}|s+d
Sy�|j|||�}	|s]tjd|�tSxMtr�tjd�t|||||�}
|
s�tS|
ddkr`tSq`WWnCt	j
jk
r�}d	j|�}tj
|�tj|�iSXd
S(u�
    Create replication group.

    CLI example::

        salt myminion boto_elasticache.create_replication_group myelasticache myprimarycluster description
    RRRRuCreated cache cluster %s.iustatusu	availableu'Failed to create replication group {0}.N(RtNonetcreate_replication_groupRtinfoRttimetsleeptdescribe_replication_groupRRRtformatterrorR(
Rtprimary_cluster_idtreplication_group_descriptiontwaitRRRRRtcctconfigRtmsg((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyR${s*
!		


c	C@s�td|d|d|d|�}|s+tSy1|j|�dj|�}tj|�tSWnCtjj	k
r�}tj
|�dj|�}tj|�tSXdS(u�
    Delete an ElastiCache replication group.

    CLI example::

        salt myminion boto_elasticache.delete_replication_group my-replication-group                 region=us-east-1
    RRRRu*Deleted ElastiCache replication group {0}.u2Failed to delete ElastiCache replication group {0}N(RRtdelete_replication_groupR)RR%RRRRRR*(RRRRRRR0R((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyR1�s	!



c	C@std|d|d|d|�}|s+dSy|j|�}WnCtjjk
r�}dj|�}	tj|	�tj	|�iSXt
j�}
|dd}|dd	}d
ddd
ddddg}x7tj
|�D]&\}}tjj|�}
|
d
kr$|r||
|
<q$d|
|
<n|
dkrP|rC||
|
<qPd|
|
<n|
dkr||ro||
|
<q|d|
|
<n|
d
kr�|r�||
|
<q�d|
|
<n|
dkr�|r�||
|
<q�d|
|
<n|
dkr�|r�||
|
<qd|
|
<q�q�W|
S(u�
    Get replication group information.

    CLI example::

        salt myminion boto_elasticache.describe_replication_group mygroup
    RRRRu+Failed to get config for cache cluster {0}.u!DescribeReplicationGroupsResponseuDescribeReplicationGroupsResultuReplicationGroupsiustatusudescriptionuprimary_endpointumember_clustersureplication_group_idupending_modified_valuesuprimary_cluster_idunode_groupsN(RR#R!RRRR)RR*RtodicttOrderedDictRt	iteritemsRtpythonize_name(RRRRRt	parameterRR.RR0trettattrstvalt_key((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyR(�sX	!

		










cC@sgtd|d|d|d|�}|s+d$Sy|j|dt�}WnCtjjk
r�}dj|�}tj	|�tj
|�iSX|dd}|d	d
}tj�}	ddd
ddddddddddddddg}
xut
j|�D]d\}}tjj|�}||
kr+q�n|dkr[|rN|d|	|<q_d$|	|<q�|dkr�|r�g|D]}
|
^qt|	|<q_g|	|<q�|dkr�|r�g|D]}
|
d^q�|	|<q_g|	|<q�|dkr%|r|d|	d<|d |	d!<q_d$|	d<d$|	d!<q�|dkrU|rH|d"|	d#<q_d$|	d#<q�||	|<q�W|	S(%u�
    Get the configuration for a cache cluster.

    CLI example::

        salt myminion boto_elasticache.get_config myelasticache
    RRRRtshow_cache_node_infou+Failed to get config for cache cluster {0}.uDescribeCacheClustersResponseuDescribeCacheClustersResultu
CacheClustersiuengineucache_parameter_groupucache_cluster_iducache_security_groupsureplication_group_iduauto_minor_version_upgradeunum_cache_nodesupreferred_availability_zoneusecurity_groupsucache_subnet_group_nameuengine_versionucache_node_typeunotification_configurationupreferred_maintenance_windowuconfiguration_endpointucache_cluster_statusucache_nodesuCacheParameterGroupNameuCacheSecurityGroupNameuPortuportuAddressuaddressuTopicArnunotification_topic_arnN(RR#RRRRRR)RR*RR2R3RR4RR5(RRRRRRR.RR0R7R8R9R:tk((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyt
get_config�sb!


		
 
$



c
	C@s�td|d|d|d|�}|s+dSy|j|dt�}WnCtjjk
r�}dj|�}tj	|�tj
|�iSX|dd}|d	d
dd
dd
}	|	S(u}
    Get hostname from cache node

    CLI example::

        salt myminion boto_elasticache.get_node_host myelasticache
    RRRRR;u+Failed to get config for cache cluster {0}.uDescribeCacheClustersResponseuDescribeCacheClustersResultu
CacheClustersiu
CacheNodesuEndpointuAddressN(RR#RRRRRR)RR*R(
RRRRRRR.RR0thost((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyt
get_node_host6s!


c
	C@s�td|d|d|d|�}|s+d
Sy|j|�}WnCtjjk
r�}dj|�}tj|�tj	|�iSX|dd}|dd	d
d	d}|d}	|	S(u�
    Get hostname from replication cache group

    CLI example::

        salt myminion boto_elasticache.get_group_host myelasticachegroup
    RRRRu+Failed to get config for cache cluster {0}.u!DescribeReplicationGroupsResponseuDescribeReplicationGroupsResultuReplicationGroupsiu
NodeGroupsuPrimaryEndpointuAddressN(
RR#R!RRRR)RR*R(
RRRRRRR.RR0R>((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pytget_group_hostPs!


c	C@s�td|d|d|d|�}y�d}g}xn|d
k	r�|jd|d|�}|jdi�jd	i�}	||	jd
g�7}|	jdd
�}q3W|s�tjd�n|SWn'tjjk
r�}
tj	|
�gSXd
S(u�
    Return a list of all cache subnet groups with details

    CLI example::

        salt myminion boto_elasticache.get_all_subnet_groups region=us-east-1
    RRRRutcache_subnet_group_nametmarkeru!DescribeCacheSubnetGroupsResponseuDescribeCacheSubnetGroupsResultuCacheSubnetGroupsuMarkeru#No ElastiCache subnet groups found.N(
RR#tdescribe_cache_subnet_groupstgetRRRRRR*(RRRRRRRBtgroupsR7ttrimmedR((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pytget_all_cache_subnet_groupsjs"	!		
cC@s-gt|||||�D]}|d^qS(u�
    Return a list of all cache subnet group names

    CLI example::

        salt myminion boto_elasticache.list_subnet_groups region=us-east-1
    uCacheSubnetGroupName(RG(RRRRRtg((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pytlist_cache_subnet_groups�s	c
	C@s�td|d|d|d|�}|s+tSy@|jd|�}|sfdj|�}tj|�tStSWn'tjj	k
r�}	tj|	�tSXdS(u�
    Check to see if an ElastiCache subnet group exists.

    CLI example::

        salt myminion boto_elasticache.subnet_group_exists my-param-group                 region=us-east-1
    RRRRRAu5ElastiCache subnet group does not exist in region {0}N(
RRRCR)RRRRRR(
RttagsRRRRRtecR0R((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pytsubnet_group_exists�s	!

c	C@s�t||f�s!td��ntd|d|d|d|�}	|	sLtSt||||||�rktS|r�g}xm|D]b}
tdd|
d|d|d|d|�}d|kr�tjd	t	�tS||dg7}q~WnyS|	j
|||�}|s%d
j|�}
tj|
�tStjd|�tSWnCt
jjk
r}tj|�d
j|�}
tj|
�tSXdS(
u
    Create an ElastiCache subnet group

    CLI example to create an ElastiCache subnet group::

        salt myminion boto_elasticache.create_subnet_group my-subnet-group             "group description" subnet_ids='[subnet-12345678, subnet-87654321]'             region=us-east-1
    uFExactly one of either 'subnet_ids' or 'subnet_names' must be provided.RRRRuboto_vpc.get_resource_idusubnetuidu)Couldn't resolve subnet name %s to an ID.u-Failed to create ElastiCache subnet group {0}u#Created ElastiCache subnet group %sN(t_exactly_oneRRRRLRRRR*tsubnet_nametcreate_cache_subnet_groupR)R%RRRR(Rtdescriptiont
subnet_idstsubnet_namesRJRRRRRtntrRKR0R((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pytcreate_subnet_group�s<!



c	C@s�td|d|d|d|�}y/|j|�}|d}|ddd}Wnytjjk
r�}d	j|�}tj|�tj|�t	St
ttfk
r�d
j|�}tj|�t	SXi}	x�t
j|�D]�\}}
|dkr|
|	d<q�|d
kr |
|	d<q�|dkr9|
|	d<q�|dkr�g|	d<xX|
D]C}i}|d|d<|dd}
|
|d<|	dj|�qVWq�|
|	|<q�W|	S(u�
    Get information about a cache subnet group.

    CLI example::

        salt myminion boto_elasticache.get_cache_subnet_group mycache_subnet_group
    RRRRu!DescribeCacheSubnetGroupsResponseuDescribeCacheSubnetGroupsResultuCacheSubnetGroupsiu%Failed to get cache subnet group {0}.u)Failed to get cache subnet group {0} (2).uCacheSubnetGroupNameucache_subnet_group_nameuCacheSubnetGroupDescriptionucache_subnet_group_descriptionuVpcIduvpc_iduSubnetsusubnetsuSubnetIdentifieru	subnet_iduSubnetAvailabilityZoneuNameusubnet_availability_zone(RRCRRRR)RR*RRt
IndexErrort	TypeErrortKeyErrorRR4tappend(RRRRRRtcsgRR0R7R9tsubnett_subnett_az((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pytget_cache_subnet_group�s@	!









c	C@s�td|d|d|d|�}|s+tSy1|j|�dj|�}tj|�tSWnCtjj	k
r�}tj
|�dj|�}tj|�tSXdS(u�
    Delete an ElastiCache subnet group.

    CLI example::

        salt myminion boto_elasticache.delete_subnet_group my-subnet-group                 region=us-east-1
    RRRRu%Deleted ElastiCache subnet group {0}.u-Failed to delete ElastiCache subnet group {0}N(RRtdelete_cache_subnet_groupR)RR%RRRRRR*(RRRRRRR0R((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pytdelete_subnet_groups	!



cC@s#td|d|d|d|�}y�|j||||||||||	|
|||
||�|sxtjd|�tSxMtr�tjd�t|||||�}|s�tS|ddkr{tSq{Wtjd|�WnCtj	j
k
r}d	j|�}tj|�tj
|�tSXd
S(u�
    Create a cache cluster.

    CLI example::

        salt myminion boto_elasticache.create myelasticache 1 redis cache.t1.micro
        cache_security_group_names='["myelasticachesg"]'
    RRRRuCreated cache cluster %s.iucache_cluster_statusu	availableu#Failed to create cache cluster {0}.N(Rtcreate_cache_clusterRR%RR&R'R=RRRR)R*RR(Rtnum_cache_nodestenginetcache_node_typetreplication_group_idtengine_versiontcache_parameter_group_nameRAtcache_security_group_namestsecurity_group_idst
snapshot_arnstpreferred_availability_zonetpreferred_maintenance_windowtporttnotification_topic_arntauto_minor_version_upgradeR-RRRRRR/RR0((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pytcreates2!				


c
	C@s�td|d|d|d|�}y�|j|�|sKtjd|�tSxMtr�t|||||�}|svtS|ddkr�tStjd�qNWtjd|�tSWnCtj	j
k
r�}d	j|�}	tj|	�tj
|�tSXd
S(uq
    Delete a cache cluster.

    CLI example::

        salt myminion boto_elasticache.delete myelasticache
    RRRRuDeleted cache cluster %s.ucache_cluster_statusudeletingiu#Failed to delete cache cluster {0}.N(Rtdelete_cache_clusterRR%RR=R&R'RRRR)R*RR(
RR-RRRRRR/RR0((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pytdeleteHs(!
	

c		C@sqtd|d|d|d|�}|j||�}|rMtjd|�tSdj|�}tj|�tSdS(u�
    Create a cache security group.

    CLI example::

        salt myminion boto_elasticache.create_cache_security_group myelasticachesg 'My Cache Security Group'
    RRRRu Created cache security group %s.u*Failed to create cache security group {0}.N(Rtcreate_cache_security_groupRR%RR)R*R(	RRPRRRRRtcreatedR0((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyRsgs	!
c	C@sntd|d|d|d|�}|j|�}|rJtjd|�tSdj|�}tj|�tSdS(u�
    Delete a cache security group.

    CLI example::

        salt myminion boto_elasticache.delete_cache_security_group myelasticachesg 'My Cache Security Group'
    RRRRu Deleted cache security group %s.u*Failed to delete cache security group {0}.N(Rtdelete_cache_security_groupRR%RR)R*R(RRRRRRtdeletedR0((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyRu|s	!
c	C@s�td|d|d|d|�}yq|j|||�}|rhd}	|	j||�}	tj|	�tSd}	|	j||�}	tj|	�tSWnLtj	j
k
r�}
tj|
�d}	|	j||�}	tj|	�tSXdS(u�
    Authorize network ingress from an ec2 security group to a cache security
    group.

    CLI example::

        salt myminion boto_elasticache.authorize_cache_security_group_ingress myelasticachesg myec2sg 879879
    RRRRu&Added {0} to cache security group {1}.u.Failed to add {0} to cache security group {1}.N(Rt&authorize_cache_security_group_ingressR)RR%RR*RRRtEC2ResponseErrorR(Rtec2_security_group_nametec2_security_group_owner_idRRRRRtaddedR0R((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyRw�s&!



c	C@s�td|d|d|d|�}yq|j|||�}|rhd}	|	j||�}	tj|	�tSd}	|	j||�}	tj|	�tSWnLtj	j
k
r�}
tj|
�d}	|	j||�}	tj|	�tSXdS(u�
    Revoke network ingress from an ec2 security group to a cache security
    group.

    CLI example::

        salt myminion boto_elasticache.revoke_cache_security_group_ingress myelasticachesg myec2sg 879879
    RRRRu*Removed {0} from cache security group {1}.u3Failed to remove {0} from cache security group {1}.N(Rt#revoke_cache_security_group_ingressR)RR%RR*RRRRxR(RRyRzRRRRRtremovedR0R((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyR|�s&!



(2t__doc__t
__future__RRRtloggingR&tsalt.extRtsalt.exceptionsRtsalt.utils.odictRR2tsalt.utils.versionsRt	getLoggerRRRtboto.elasticachet
boto.utilstsetLeveltCRITICALRtHAS_BOTOtImportErrorRRR#R R"R$R1R(R=R?R@RGRIRLRUR^R`RpRrRsRuRwR|(((sA/usr/lib/python2.7/site-packages/salt/modules/boto_elasticache.pyt<module>+sl


	
	 	>B			+	,	%		"	

Zerion Mini Shell 1.0