%PDF- %PDF-
Direktori : /lib/python2.7/site-packages/salt/states/ |
Current File : //lib/python2.7/site-packages/salt/states/boto_secgroup.pyo |
� ���^c @@ sZ d Z d d l m Z m Z m Z d d l Z d d l Z d d l j j Z d d l m Z d d l m Z e j e � Z d � Z d d d d e e d d d d d d � Z d d d d d d d � Z d � Z d � Z d � Z e d d d d d d d � Z e d d d d d d d � Z d d d d d d d � Z d d d d d d d � Z d S( uR Manage Security Groups ====================== .. versionadded:: 2014.7.0 Create and destroy Security Groups. Be aware that this interacts with Amazon's services, and so may incur charges. This module uses ``boto``, which can be installed via package, or pip. This module accepts explicit EC2 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 `here <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 file or in the minion's config file: .. code-block:: yaml secgroup.keyid: GKTADJGHEIQSXMKKRBJ08H secgroup.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs It's also possible to specify ``key``, ``keyid`` and ``region`` via a profile, either passed in as a dict, or as a string to pull from pillars or minion config: .. code-block:: yaml myprofile: keyid: GKTADJGHEIQSXMKKRBJ08H key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs region: us-east-1 .. code-block:: yaml Ensure mysecgroup exists: boto_secgroup.present: - name: mysecgroup - description: My security group - vpc_name: myvpc - rules: - ip_protocol: tcp from_port: 80 to_port: 80 cidr_ip: - 10.0.0.0/8 - 192.168.0.0/16 - ip_protocol: tcp from_port: 8080 to_port: 8090 cidr_ip: - 10.0.0.0/8 - 192.168.0.0/16 - ip_protocol: icmp from_port: -1 to_port: -1 source_group_name: mysecgroup - ip_protocol: tcp from_port: 8080 to_port: 8080 source_group_name: MyOtherSecGroup source_group_name_vpc: MyPeeredVPC - rules_egress: - ip_protocol: all from_port: -1 to_port: -1 cidr_ip: - 10.0.0.0/8 - 192.168.0.0/16 - tags: SomeTag: 'My Tag Value' SomeOtherTag: 'Other Tag Value' - region: us-east-1 - keyid: GKTADJGHEIQSXMKKRBJ08H - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs # Using a profile from pillars Ensure mysecgroup exists: boto_secgroup.present: - name: mysecgroup - description: My security group - profile: myprofile # Passing in a profile Ensure mysecgroup exists: boto_secgroup.present: - name: mysecgroup - description: My security group - profile: keyid: GKTADJGHEIQSXMKKRBJ08H key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs region: us-east-1 .. note:: When using the ``profile`` parameter and ``region`` is set outside of the profile group, region is ignored and a default region will be used. If ``region`` is missing from the ``profile`` data set, ``us-east-1`` will be used as the default region. i ( t absolute_importt print_functiont unicode_literalsN( t SaltInvocationError( t sixc C@ s d t k r d St S( u) Only load if boto is available. u boto_secgroup.existsu boto_secgroup( t __salt__t False( ( ( s= /usr/lib/python2.7/site-packages/salt/states/boto_secgroup.pyt __virtual__x s c C@ s� i | d 6t d 6d d 6i d 6} t | | d | d | d | d | d | d | �} | d | d <d j | d | d g � | d <| d s� | d | d <| d t k r� | S| d d k r� | Sn | d k rft | | | d | d | d | d | d | d | �} t j | d | d � | d <d j | d | d g � | d <| d sf| d | d <qfn | d k rt | | | d | d | d | d | d | d | �} t j | d | d � | d <d j | d | d g � | d <| d s| d | d <qn t d | d | d | d | d | d | d | d | � } t j | d | d � | d <d j | d | d g � | d <| d s�| d | d <n | S( u� Ensure the security group exists with the specified rules. name Name of the security group. description A description of this security group. vpc_id The ID of the VPC to create the security group in, if any. Exclusive with vpc_name. vpc_name The name of the VPC to create the security group in, if any. Exclusive with vpc_id. .. versionadded:: 2016.3.0 .. versionadded:: 2015.8.2 rules A list of ingress rule dicts. If not specified, ``rules=None``, the ingress rules will be unmanaged. If set to an empty list, ``[]``, then all ingress rules will be removed. rules_egress A list of egress rule dicts. If not specified, ``rules_egress=None``, the egress rules will be unmanaged. If set to an empty list, ``[]``, then all egress rules will be removed. delete_ingress_rules Some tools (EMR comes to mind) insist on adding rules on-the-fly, which salt will happily remove on the next run. Set this param to False to avoid deleting rules which were added outside of salt. delete_egress_rules Some tools (EMR comes to mind) insist on adding rules on-the-fly, which salt will happily remove on the next run. Set this param to False to avoid deleting rules which were added outside of salt. region Region to connect to. key Secret key to be used. keyid Access key to be used. profile A dict with region, key and keyid, or a pillar key (string) that contains a dict with region, key, and keyid. tags List of key:value pairs of tags to set on the security group .. versionadded:: 2016.3.0 u nameu resultu u commentu changest vpc_idt vpc_namet regiont keyt keyidt profileu t namet tagsN( t Truet _security_group_presentt joinR t Nonet _rules_presentt dictupdatet updatet _rules_egress_presentt _tags_present( R t descriptionR R t rulest rules_egresst delete_ingress_rulest delete_egress_rulesR R R R R t rett _ret( ( s= /usr/lib/python2.7/site-packages/salt/states/boto_secgroup.pyt present sJ G"! ! ! ! c C@ se i t d 6d d 6i d 6} t d | | | | | | | � } | sNt d rn d j | � | d <d | d <| St d d | d | d | d | d | d | d | d | � } | r.i d d 6| d d <t d d | d d d | d | d | d | d | d | � } i | d 6| d d <d j | � | d <qat | d <d j | � | d <n d j | � | d <| S( u� given a group name or a group name and vpc id (or vpc name): 1. determine if the group exists 2. if the group does not exist, creates the group 3. return the group's configuration and any changes made u resultu u commentu changesu boto_secgroup.existsu testu( Security group {0} is set to be created.u boto_secgroup.createR R R R R R R R u secgroupu oldu boto_secgroup.get_configt group_idu newu Security group {0} created.u$ Failed to create {0} security group.u Security group {0} present.N( R R t __opts__t formatR R ( R R R R R R R R R t existst createdt sg( ( s= /usr/lib/python2.7/site-packages/salt/states/boto_secgroup.pyR � s. " c C@ sE g } x8| D]0} | j d � } | j d � } | j d � } | r� t | t j � r� x� | D]) } | j � } | | d <| j | � q` Wq | r� t | t j � r� x� | D]) } | j � } | | d <| j | � q� Wq | r0t | t j � r0xA | D]) } | j � } | | d <| j | � q Wq | j | � q W| S( u Split rules with lists into individual rules. We accept some attributes as lists or strings. The data we get back from the execution module lists rules as individual rules. We need to split the provided rules into individual rules to compare them. u cidr_ipu source_group_nameu source_group_group_id( t gett isinstanceR t string_typest copyt append( R t splitt rulet cidr_ipt group_nameR! t ipt _ruleR t _id( ( s= /usr/lib/python2.7/site-packages/salt/states/boto_secgroup.pyt _split_rules s, c C@ sc | j d � d k r"