U
    W+d?                     @   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   2/tmp/pip-unpacked-wheel-dlxw5sjy/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 r   r   r   r   r   r   r   %   s    zBillingProducts.startElementc                 C   s   |dkr|  | d S )NZbillingProductr   r   r   r   r   r   (   s    zBillingProducts.endElementNr   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   retvalr3   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isPublicfalseFtrueTz,Unexpected value of isPublic %s for image %sr$   Z	imageTypeZkernelIdZ	ramdiskIdZimageOwnerAliasr%   r
   r)   ZrootDeviceTypeZrootDeviceNameZvirtualizationTyper0   ZinstanceLifecycleZsriovNetSupport)r   r   r   r    r!   r#   	Exceptionr$   r&   r'   r(   r"   r%   r
   r)   r-   r.   r/   r0   r1   r2   setattrr   r   r   r   r   ]   sb    










zImage.endElementc                 C   s   | j |j  d S r   )__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   lenr@   
ValueErrorr   )r	   validaterB   rsimgr   r   r   r>      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tenancyrB   )r   Zrun_instancesr   )r	   Z	min_count	max_countZkey_nameZsecurity_groups	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_grouprJ   rK   rL   rM   rN   rB   r   r   r   run   s0             z	Image.runc                 C   s   | j j| j||dS )NrA   )r   Zderegister_imager   )r	   Zdelete_snapshotrB   r   r   r   
deregisterP  s
    zImage.deregisterc                 C   s   | j j| jd|d}|jS NlaunchPermissionrA   )r   get_image_attributer   r   r	   rB   Z	img_attrsr   r   r   get_launch_permissionsW  s    zImage.get_launch_permissionsc                 C   s   | j j| jdd|||dS )NrT   addrA   r   Zmodify_image_attributer   r	   user_idsZgroup_namesrB   r   r   r   set_launch_permissions_  s    
zImage.set_launch_permissionsc                 C   s   | j j| jdd|||dS )NrT   removerA   rY   rZ   r   r   r   remove_launch_permissionsh  s    
zImage.remove_launch_permissionsc                 C   s   | j j| jd|dS rS   )r   Zreset_image_attributer   )r	   rB   r   r   r   reset_launch_attributesq  s
    zImage.reset_launch_attributesc                 C   s   | j j| jd|d}|jS )NkernelrA   )r   rU   r   r`   rV   r   r   r   
get_kernelx  s    zImage.get_kernelc                 C   s   | j j| jd|d}|jS )NramdiskrA   )r   rU   r   rb   rV   r   r   r   get_ramdisk  s    zImage.get_ramdisk)N)FF)rH   rH   NNNNrI   NNNFNNFNNNNNNNNF)FF)F)NNF)NNF)F)F)F)r   r   r   __doc__r   r5   r   r   r@   r>   rQ   rR   rW   r\   r^   r_   ra   rc   __classcell__r   r   r3   r   r   -   sR   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 r   )r
   r`   rb   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 )Nr6   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 )NrT   Zlaunch_permissiongroupgroupsZuserIdr[   r   r*   r8   r`   rb   )r
   r   r   image_idr`   rb   r<   r   r   r   r   r     s*    


zImageAttribute.endElement)Nr   r   r   r   r   r   r   r   r   r   rf     s   
rf   c                   @   s&   e Zd ZdddZdd Zdd ZdS )		CopyImageNc                 C   s   || _ d | _d S r   )_parentrk   rg   r   r   r   r     s    zCopyImage.__init__c                 C   s   d S r   r   r   r   r   r   r     s    zCopyImage.startElementc                 C   s   |dkr|| _ d S )Nr8   )rk   r   r   r   r   r     s    zCopyImage.endElement)Nrl   r   r   r   r   rm     s   
rm   N)Zboto.ec2.ec2objectr   r   Zboto.ec2.blockdevicemappingr   listr   r   r   objectrf   rm   r   r   r   r   <module>   s   		  ^*