o
    ȷe?                     @   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                   @      e Zd Zdd Zdd ZdS )ProductCodesc                 C      d S N selfnameattrs
connectionr	   r	   E/var/www/ideatree/venv/lib/python3.10/site-packages/boto/ec2/image.pystartElement      zProductCodes.startElementc                 C      |dkr|  | d S d S )NproductCodeappendr   r   valuer   r	   r	   r   
endElement      zProductCodes.endElementN__name__
__module____qualname__r   r   r	   r	   r	   r   r          r   c                   @   r   )BillingProductsc                 C   r   r   r	   r
   r	   r	   r   r   %   r   zBillingProducts.startElementc                 C   r   )NbillingProductr   r   r	   r	   r   r   (   r   zBillingProducts.endElementNr   r	   r	   r	   r   r   $   r   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                    sV   t t| |||}|d ur|S |dkrt | _| jS |dkr"| jS |dkr)| jS d S )NblockDeviceMappingproductCodesbillingProducts)r"   r!   r   r   r3   r1   r2   )r   r   r   r   retvalr:   r	   r   r   O   s   zImage.startElementc                 C   s  |dkr	|| _ d S |dkr|| _d S |dkr|| _d S |dkr'|| _|| _d S |dkrF|dkr4d| _d S |dkr=d	| _d S td
|| j f |dkrO|| _d S |dkrX|| _d S |dkra|| _	d S |dkrj|| _
d S |dkrs|| _d S |dkr||| _d S |dkr|| _d S |dkr|| _d S |dkr|| _d S |dkr|| _d S |dkr|| _d S |dkr|| _d S |dkr|| _d S |dkr|| _d S t| || d S )NimageIdimageLocation
imageStateimageOwnerIdisPublicfalseFtrueTz,Unexpected value of isPublic %s for image %sr+   	imageTypekernelId	ramdiskIdimageOwnerAliasr,   r   r0   rootDeviceTyperootDeviceNamevirtualizationTyper7   instanceLifecyclesriovNetSupport)r$   r%   r&   r'   r(   r*   	Exceptionr+   r-   r.   r/   r)   r,   r   r0   r4   r5   r6   r7   r8   r9   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   s\   | j j| jg|d}t|dkr"|d }|j| jkr| | | jS |r+t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   get_all_imagesr$   lenrV   
ValueErrorr&   )r   validaterX   rsimgr	   r	   r   rT      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tenancyrX   )r   run_instancesr$   )r   	min_count	max_countkey_namesecurity_groups	user_dataaddressing_typeinstance_type	placementr.   r/   monitoring_enabled	subnet_idblock_device_mapdisable_api_termination$instance_initiated_shutdown_behaviorprivate_ip_addressplacement_groupra   rb   rc   rd   re   rX   r	   r	   r   run   s     z	Image.runc                 C   s   | j j| j||dS )NrW   )r   deregister_imager$   )r   delete_snapshotrX   r	   r	   r   
deregisterP  
   zImage.deregisterc                 C      | j j| jd|d}|jS NlaunchPermissionrW   )r   get_image_attributer$   r   r   rX   	img_attrsr	   r	   r   get_launch_permissionsW     zImage.get_launch_permissionsc                 C      | j j| jdd|||dS )Nr}   addrW   r   modify_image_attributer$   r   user_idsgroup_namesrX   r	   r	   r   set_launch_permissions_     
zImage.set_launch_permissionsc                 C   r   )Nr}   removerW   r   r   r	   r	   r   remove_launch_permissionsh  r   zImage.remove_launch_permissionsc                 C   s   | j j| jd|dS r|   )r   reset_image_attributer$   )r   rX   r	   r	   r   reset_launch_attributesq  rz   zImage.reset_launch_attributesc                 C   r{   )NkernelrW   )r   r~   r$   r   r   r	   r	   r   
get_kernelx  r   zImage.get_kernelc                 C   r{   )NramdiskrW   )r   r~   r$   r   r   r	   r	   r   get_ramdisk  r   zImage.get_ramdiskr   )FF)r_   r_   NNNNr`   NNNFNNFNNNNNNNNF)F)NNF)r   r   r   __doc__r#   r<   r   r   rV   rT   rv   ry   r   r   r   r   r   r   __classcell__r	   r	   r:   r   r!   -   sB    5

 
'

	

	
r!   c                   @   &   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   r   r   r   parentr	   r	   r   r#     s   
zImageAttribute.__init__c                 C   s"   |dkrt  | jd< | jd S d S )Nr=   r3   )r   r   r
   r	   r	   r   r     s   
zImageAttribute.startElementc                 C   s   |dkr	d| _ d S |dkr$d| jv r| jd | d S |g| jd< d S |dkr?d| jv r7| jd | d S |g| jd< d S |dkrZd| jv rR| jd | d S |g| jd< d S |d	krc|| _d S |d
krl|| _d S |dkru|| _d S t| || d S )Nr}   launch_permissiongroupgroupsuserIdr   r   r1   rA   r   r   )r   r   r   image_idr   r   rR   r   r	   r	   r   r     s*   






zImageAttribute.endElementr   r   r   r   r#   r   r   r	   r	   r	   r   r     s    
r   c                   @   r   )		CopyImageNc                 C   s   || _ d | _d S r   )_parentr   r   r	   r	   r   r#     s   
zCopyImage.__init__c                 C   r   r   r	   r
   r	   r	   r   r     r   zCopyImage.startElementc                 C   s   |dkr	|| _ d S d S )NrA   )r   r   r	   r	   r   r     s   
zCopyImage.endElementr   r   r	   r	   r	   r   r     s    
r   N)boto.ec2.ec2objectr   r   boto.ec2.blockdevicemappingr   listr   r   r!   objectr   r   r	   r	   r	   r   <module>   s   		  ^*