Current File : //usr/lib/python2.7/site-packages/cloudinit/sources/helpers/digitalocean.pyo
�
oB�]c@s�ddlZddlZddlmZddlmZddlmZddlmZidd6dd	6Z	ej
e�Zdd
�Zd�Zdd�Zd
�Zdddd�Zd�ZdS(i����N(tlog(tnet(t
url_helper(tutilteth0tpublicteth1tprivatecCs!|s"t�}tjd|�n|s7td��ndjtjdd�tjdd��}dd	d
|d|g}ddd
d|dg}tjd�s�td��nyAtj	|�tjd||�tj	|�tjd|�Wn*t
k
rtjtd||��nX|S(s�Bring up NIC using an address using link-local (ip4LL) IPs. On
       DigitalOcean, the link-local domain is per-droplet routed, so there
       is no risk of collisions. However, to be more safe, the ip4LL
       address is random.
    s,selected interface '%s' for reading metadatasPunable to find interfaces to access themeta-data server. This droplet is broken.s169.254.{0}.{1}/16ii�ii�tiptaddrtaddtdevtlinktsettups4No 'ip' command available to configure ip4LL addresss#assigned ip4LL address '%s' to '%s'sbrought device '%s' upsRip4LL address assignment of '%s' to '%s' failed. Droplet networking will be broken(tget_link_local_nictLOGtdebugtRuntimeErrortformattrandomtrandintRtwhichtsubpt	Exceptiontlogexc(tnicR	tip_addr_cmdtip_link_cmd((sJ/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/digitalocean.pytassign_ipv4_link_locals*	



cCsKgtj�D]}tj|�r
|^q
}|s8dSt|dd��S(NtkeycSstj|d�S(Ntifindex(tcloudnettread_sys_net_int(td((sJ/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/digitalocean.pyt<lambda><s(R tget_devicelisttis_physicaltNonetmin(tftnics((sJ/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/digitalocean.pyR8s.cCs�|stjd�dStjd�dddd|g}y!tj|�tjd|�Wn)tk
r�}tjtd	||�nXdS(
szRemove the ip4LL address. While this is not necessary, the ip4LL
       address is extraneous and confusing to users.
    sLno link_local address interface defined, skipping link local address cleanupNscleaning up ipv4LL addressRR	tflushRsremoved ip4LL addresses from %ss)failed to remove ip4LL address from '%s'.(RRRRRR(RRte((sJ/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/digitalocean.pytdel_ipv4_link_local?s


cCs�d�}g}tj�}tjd|�x�|D]�}||d}tjd|�|jd�}||kr�td||f��n|j|�}|jdd�}	tj|	|�}
|
|kr�tjd	|	|||
�nd
}tj|||�idd6|d6|
d
6}g}
xgdD]_}|j|d�}|sJq&n||�}|	dksnd|krx|d=n|
j|�q&W|
|d<|j|�tjd|
|�q2W|r�tjd|�|jidd6|d6�nidd6|d6S(s�Convert the DigitalOcean Network description into Cloud-init's netconfig
       format.

       Example JSON:
        {'public': [
              {'mac': '04:01:58:27:7f:01',
               'ipv4': {'gateway': '45.55.32.1',
                        'netmask': '255.255.224.0',
                        'ip_address': '45.55.50.93'},
               'anchor_ipv4': {
                        'gateway': '10.17.0.1',
                        'netmask': '255.255.0.0',
                        'ip_address': '10.17.0.9'},
               'type': 'public',
               'ipv6': {'gateway': '....',
                        'ip_address': '....',
                        'cidr': 64}}
           ],
          'private': [
              {'mac': '04:01:58:27:7f:02',
               'ipv4': {'gateway': '10.132.0.1',
                        'netmask': '255.255.0.0',
                        'ip_address': '10.132.75.35'},
               'type': 'private'}
           ]
        }
    cSs�idd6dd6|jd�d6|jd�d6}d|jd�krtd	j|jd�|jd
��|d<n|jd�|d<|S(Ntstaticttypetautotcontrolt
ip_addresstaddresstgatewayt:s{0}/{1}tcidrtnetmask(tgetR(tpcfgtsubpart((sJ/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/digitalocean.pyt_get_subnet_partqs
snic mapping: %sisconsidering %stmacsVDid not find network interface on system with mac '%s'. Cannot apply configuration: %sR.tunknowns6Found %s interface '%s' on '%s', assigned name of '%s'sfFound interface '%s' on '%s', which is not a public or private interface. Using default system naming.tphysicaltmac_addresstnametipv4tipv6tanchor_ipv4tanchor_ipv6RtanchorR3tsubnetssnic '%s' configuration: %ssadded dns servers: %st
nameserverR2itversiontconfig(R@RARBRCN(	R tget_interfaces_by_macRRR7RtNIC_MAPR&tappend(RHtdns_serversR:tnic_configstmacs_to_nicstnRR>t
sysfs_nametnic_typetif_nametmsgtncfgREtnetdeft
raw_subnettsub_part((sJ/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/digitalocean.pytconvert_network_configurationTsL	
	





iicCsVtj|d|d|d|�}|j�s@td|��ntj|jj��S(Nttimeouttsec_betweentretriessunable to read metadata at %s(RtreadurltokRtjsontloadstcontentstdecode(turlRYRZR[tresponse((sJ/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/digitalocean.pyt
read_metadata�s
cCsvtjd�}|dkr%tdfStjd�}|rMtjd|�nd}tj|�t|��t|fS(Nssystem-manufacturertDigitalOceanssystem-serial-numbers8system identified via SMBIOS as DigitalOcean Droplet: %ss�system identified via SMBIOS as a DigitalOcean Droplet, but did not provide an ID. Please file a support ticket at: https://cloud.digitalocean.com/support/tickets/new(	Rt
read_dmi_datatFalseR&RRtcriticalRtTrue(tvendor_namet
droplet_idRS((sJ/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/digitalocean.pytread_sysinfo�s
	

(R^Rt	cloudinitRtloggingRR RRRJt	getLoggert__name__RR&RRR,RXRdRl(((sJ/usr/lib/python2.7/site-packages/cloudinit/sources/helpers/digitalocean.pyt<module>s&		`