o ckF[@s8dZddlZddlmZddlmZGdddeZdS)z Represents an EC2 Keypair N) EC2Object)BotoClientErrorcsJeZdZdfdd ZddZddZdd d Zd d Zdd dZZ S)KeyPairNcs&tt||d|_d|_d|_dSN)superr__init__name fingerprintmaterial)self connection __class__2/usr/lib/python3/dist-packages/boto/ec2/keypair.pyr!s zKeyPair.__init__cCs d|jS)Nz KeyPair:%s)r)r rrr__repr__'s zKeyPair.__repr__cCsF|dkr ||_dS|dkr||_dS|dkr||_dSt|||dS)NkeyNamekeyFingerprint keyMaterial)rr r setattr)r rvaluer rrr endElement*s   zKeyPair.endElementFcCs|jj|j|dS)zq Delete the KeyPair. :rtype: bool :return: True if successful, otherwise False. dry_run)r delete_key_pairr)r rrrrdelete4szKeyPair.deletecCst|jr6tj|}tj|d|j}tj|rtd|t|d}| |j| t |ddStd)a Save the material (the unencrypted PEM encoded RSA private key) of a newly created KeyPair to a local file. :type directory_path: string :param directory_path: The fully qualified path to the directory in which the keypair will be saved. The keypair file will be named using the name of the keypair as the base name and .pem for the file extension. If a file of that name already exists in the directory, an exception will be raised and the old file will not be overwritten. :rtype: bool :return: True if successful. z%s.pemz-%s already exists, it will not be overwrittenwbiTzKeyPair contains no material) r ospath expanduserjoinrexistsropenwriteclosechmod)r directory_path file_pathfprrrsave=s      z KeyPair.savecCsB|j|jkr td|j}|jdi|}|j|j|d}|S)a  Create a new key pair of the same new in another region. Note that the new key pair will use a different ssh cert than the this key pair. After doing the copy, you will need to save the material associated with the new key pair (use the save method) to a local file. :type region: :class:`boto.ec2.regioninfo.RegionInfo` :param region: The region to which this security group will be copied. :rtype: :class:`boto.ec2.keypair.KeyPair` :return: The new key pair z!Unable to copy to the same RegionrNr)rregionrr get_paramsconnectcreate_key_pair)r r*r conn_paramsrconnkprrrcopy_to_region\s  zKeyPair.copy_to_regionr)F) __name__ __module__ __qualname__rrrrr)r1 __classcell__rrr rrs  r)__doc__rboto.ec2.ec2objectrboto.exceptionrrrrrrs