B
    ?F[?                 @   sp   d dl mZmZ d dlmZ G dd deZG dd deZG dd deZG d	d
 d
e	Z
G dd de	ZdS )    )	EC2ObjectTaggedEC2Object)BlockDeviceMappingc               @   s   e Zd Zdd Zdd ZdS )ProductCodesc             C   s   d S )N )selfnameattrs
connectionr   r   -lib/python3.7/site-packages/boto/ec2/image.pystartElement   s    zProductCodes.startElementc             C   s   |dkr|  | d S )NproductCode)append)r   r   valuer
   r   r   r   
endElement   s    zProductCodes.endElementN)__name__
__module____qualname__r   r   r   r   r   r   r      s   r   c               @   s   e Zd Zdd Zdd ZdS )BillingProductsc             C   s   d S )Nr   )r   r   r	   r
   r   r   r   r   %   s    zBillingProducts.startElementc             C   s   |dkr|  | d S )NZbillingProduct)r   )r   r   r   r
   r   r   r   r   (   s    zBillingProducts.endElementN)r   r   r   r   r   r   r   r   r   r   $   s   r   c                   s   e Zd ZdZd" fdd	Zdd Z fddZd	d
 Zdd Zd#ddZ	d$ddZ
d%ddZd&ddZd'ddZd(ddZd)ddZd*ddZd+d d!Z  ZS ),Imagez!
    Represents an EC2 Image
    Nc                s   t t| | d | _d | _d | _d | _d | _d | _d| _	d | _
d | _d | _d | _d | _d | _d | _t | _t | _d | _d | _d | _d | _d | _d | _d | _d S )NF)superr   __init__idlocationstateownerIdowner_idowner_alias	is_publicarchitectureplatformtype	kernel_id
ramdisk_idr   descriptionr   product_codesr   billing_productsblock_device_mappingroot_device_typeroot_device_namevirtualization_type
hypervisorinstance_lifecyclesriov_net_support)r   r
   )	__class__r   r   r   2   s0    zImage.__init__c             C   s
   d| j  S )NzImage:%s)r   )r   r   r   r   __repr__L   s    zImage.__repr__c                sZ   t t| |||}|d k	r |S |dkr6t | _| jS |dkrD| jS |dkrR| jS d S d S )NblockDeviceMappingZproductCodesZbillingProducts)r   r   r   r   r'   r%   r&   )r   r   r	   r
   Zretval)r.   r   r   r   O   s    zImage.startElementc             C   s  |dkr|| _ nr|dkr$|| _n`|dkr6|| _nN|dkrN|| _|| _n6|dkr|dkrfd| _n"|dkrvd	| _ntd
|| j f n|dkr|| _n|dkr|| _n|dkr|| _	n|dkr|| _
n|dkr|| _n|dkr|| _n|dkr|| _n|dkr|| _nx|dkr|| _nf|dkr0|| _nT|dkrB|| _nB|dkrT|| _n0|dkrf|| _n|dkrx|| _nt| || d S )NimageIdZimageLocationZ
imageStateZimageOwnerIdZisPublicZfalseFtrueTz,Unexpected value of isPublic %s for image %sr   Z	imageTypeZkernelIdZ	ramdiskIdZimageOwnerAliasr    r   r$   ZrootDeviceTypeZrootDeviceNameZvirtualizationTyper+   ZinstanceLifecycleZsriovNetSupport)r   r   r   r   r   r   	Exceptionr   r!   r"   r#   r   r    r   r$   r(   r)   r*   r+   r,   r-   setattr)r   r   r   r
   r   r   r   r   ]   s^    










zImage.endElementc             C   s   | j |j  d S )N)__dict__update)r   updatedr   r   r   _update   s    zImage._updateFc             C   sX   | j j| jg|d}t|dkr@|d }|j| jkrR| | n|rRtd| j | jS )a  
        Update the image's state information by making a call to fetch
        the current image attributes from the service.

        :type validate: bool
        :param validate: By default, if EC2 returns no data about the
                         image the update method returns quietly.  If
                         the validate param is True, however, it will
                         raise a ValueError exception if no data is
                         returned from EC2.
        )dry_runr   z%s is not a valid Image ID)r
   Zget_all_imagesr   lenr8   
ValueErrorr   )r   Zvalidater9   ZrsZimgr   r   r   r6      s    zImage.update   m1.smallc             C   s>   | j j| j|||||||||	|
|||||||||||||dS )aZ  
        Runs this instance.

        :type min_count: int
        :param min_count: The minimum number of instances to start

        :type max_count: int
        :param max_count: The maximum number of instances to start

        :type key_name: string
        :param key_name: The name of the key pair with which to
            launch instances.

        :type security_groups: list of strings
        :param security_groups: The names of the security groups with which to
            associate instances.

        :type user_data: string
        :param user_data: The Base64-encoded MIME user data to be made
            available to the instance(s) in this reservation.

        :type instance_type: string
        :param instance_type: The type of instance to run:

            * t1.micro
            * m1.small
            * m1.medium
            * m1.large
            * m1.xlarge
            * m3.medium
            * m3.large
            * m3.xlarge
            * m3.2xlarge
            * c1.medium
            * c1.xlarge
            * m2.xlarge
            * m2.2xlarge
            * m2.4xlarge
            * cr1.8xlarge
            * hi1.4xlarge
            * hs1.8xlarge
            * cc1.4xlarge
            * cg1.4xlarge
            * cc2.8xlarge
            * g2.2xlarge
            * c3.large
            * c3.xlarge
            * c3.2xlarge
            * c3.4xlarge
            * c3.8xlarge
            * c4.large
            * c4.xlarge
            * c4.2xlarge
            * c4.4xlarge
            * c4.8xlarge
            * i2.xlarge
            * i2.2xlarge
            * i2.4xlarge
            * i2.8xlarge
            * t2.micro
            * t2.small
            * t2.medium

        :type placement: string
        :param placement: The Availability Zone to launch the instance into.

        :type kernel_id: string
        :param kernel_id: The ID of the kernel with which to launch the
            instances.

        :type ramdisk_id: string
        :param ramdisk_id: The ID of the RAM disk with which to launch the
            instances.

        :type monitoring_enabled: bool
        :param monitoring_enabled: Enable CloudWatch monitoring on
            the instance.

         :type subnet_id: string
        :param subnet_id: The subnet ID within which to launch the instances
            for VPC.

        :type private_ip_address: string
        :param private_ip_address: If you're using VPC, you can
            optionally use this parameter to assign the instance a
            specific available IP address from the subnet (e.g.,
            10.0.0.25).

        :type block_device_map: :class:`boto.ec2.blockdevicemapping.BlockDeviceMapping`
        :param block_device_map: A BlockDeviceMapping data structure
            describing the EBS volumes associated with the Image.

        :type disable_api_termination: bool
        :param disable_api_termination: If True, the instances will be locked
            and will not be able to be terminated via the API.

        :type instance_initiated_shutdown_behavior: string
        :param instance_initiated_shutdown_behavior: Specifies whether the
            instance stops or terminates on instance-initiated shutdown.
            Valid values are:

            * stop
            * terminate

        :type placement_group: string
        :param placement_group: If specified, this is the name of the placement
            group in which the instance(s) will be launched.

        :type additional_info: string
        :param additional_info: Specifies additional information to make
            available to the instance(s).

        :type security_group_ids: list of strings
        :param security_group_ids: The ID of the VPC security groups with
            which to associate instances.

        :type instance_profile_name: string
        :param instance_profile_name: The name of
            the IAM Instance Profile (IIP) to associate with the instances.

        :type instance_profile_arn: string
        :param instance_profile_arn: The Amazon resource name (ARN) of
            the IAM Instance Profile (IIP) to associate with the instances.

        :type tenancy: string
        :param tenancy: The tenancy of the instance you want to
            launch. An instance with a tenancy of 'dedicated' runs on
            single-tenant hardware and can only be launched into a
            VPC. Valid values are:"default" or "dedicated".
            NOTE: To use dedicated tenancy you MUST specify a VPC
            subnet-ID as well.

        :rtype: Reservation
        :return: The :class:`boto.ec2.instance.Reservation` associated with
                 the request for machines

        )security_group_idsadditional_infoinstance_profile_nameinstance_profile_arntenancyr9   )r
   Zrun_instancesr   )r   Z	min_countZ	max_countZkey_nameZsecurity_groupsZ	user_dataZaddressing_typeZinstance_typeZ	placementr"   r#   Zmonitoring_enabledZ	subnet_idZblock_device_mapZdisable_api_terminationZ$instance_initiated_shutdown_behaviorZprivate_ip_addressZplacement_groupr>   r?   r@   rA   rB   r9   r   r   r   run   s     z	Image.runc             C   s   | j j| j||dS )N)r9   )r
   Zderegister_imager   )r   Zdelete_snapshotr9   r   r   r   
deregisterP  s    zImage.deregisterc             C   s   | j j| jd|d}|jS )NlaunchPermission)r9   )r
   get_image_attributer   r	   )r   r9   	img_attrsr   r   r   get_launch_permissionsW  s
    zImage.get_launch_permissionsc             C   s   | j j| jdd|||dS )NrE   add)r9   )r
   modify_image_attributer   )r   user_idsgroup_namesr9   r   r   r   set_launch_permissions_  s    
zImage.set_launch_permissionsc             C   s   | j j| jdd|||dS )NrE   remove)r9   )r
   rJ   r   )r   rK   rL   r9   r   r   r   remove_launch_permissionsh  s    
zImage.remove_launch_permissionsc             C   s   | j j| jd|dS )NrE   )r9   )r
   Zreset_image_attributer   )r   r9   r   r   r   reset_launch_attributesq  s    zImage.reset_launch_attributesc             C   s   | j j| jd|d}|jS )Nkernel)r9   )r
   rF   r   rQ   )r   r9   rG   r   r   r   
get_kernelx  s
    zImage.get_kernelc             C   s   | j j| jd|d}|jS )Nramdisk)r9   )r
   rF   r   rS   )r   r9   rG   r   r   r   get_ramdisk  s
    zImage.get_ramdisk)N)FF)r<   r<   NNNNr=   NNNFNNFNNNNNNNNF)FF)F)NNF)NNF)F)F)F)r   r   r   __doc__r   r/   r   r   r8   r6   rC   rD   rH   rM   rO   rP   rR   rT   __classcell__r   r   )r.   r   r   -   s:   5
           
 

 
 


r   c               @   s&   e Zd ZdddZdd Zdd ZdS )	ImageAttributeNc             C   s   d | _ d | _d | _i | _d S )N)r   rQ   rS   r	   )r   parentr   r   r   r     s    zImageAttribute.__init__c             C   s&   |dkrt  | jd< | jd S d S d S )Nr0   r'   )r   r	   )r   r   r	   r
   r   r   r   r     s    
zImageAttribute.startElementc             C   s   |dkrd| _ n|dkrBd| jkr4| jd | q|g| jd< n|dkrtd| jkrf| jd | q|g| jd< nn|dkrd| jkr| jd | q|g| jd< n<|d	kr|| _n,|d
kr|| _n|dkr|| _nt| || d S )NrE   Zlaunch_permissiongroupgroupsZuserIdrK   r   r%   r1   rQ   rS   )r   r	   r   image_idrQ   rS   r4   )r   r   r   r
   r   r   r   r     s*    


zImageAttribute.endElement)N)r   r   r   r   r   r   r   r   r   r   rW     s   
rW   c               @   s&   e Zd ZdddZdd Zdd ZdS )		CopyImageNc             C   s   || _ d | _d S )N)Z_parentr[   )r   rX   r   r   r   r     s    zCopyImage.__init__c             C   s   d S )Nr   )r   r   r	   r
   r   r   r   r     s    zCopyImage.startElementc             C   s   |dkr|| _ d S )Nr1   )r[   )r   r   r   r
   r   r   r   r     s    zCopyImage.endElement)N)r   r   r   r   r   r   r   r   r   r   r\     s   
r\   N)Zboto.ec2.ec2objectr   r   Zboto.ec2.blockdevicemappingr   listr   r   r   objectrW   r\   r   r   r   r   <module>   s   		  ^*