3 \me9 @sUdZddlZddlmZddlmZddlmZddlm Z m Z m Z ddl m Z ddlmZdd lmZmZdd lmZd Zd Zd dddddiZdZdgZdddeeedededgedgdZeeeZejeZeee eddddZ d d!Z!dS)"z&install and configure landscape clientN)chain)dedent) ConfigObj)subp type_utilsutil)Cloud)Config) MetaSchema get_meta_doc) PER_INSTANCEz/etc/landscape/client.confz/etc/default/landscape-clientclientinfoz.https://landscape.canonical.com/message-systemz#http://landscape.canonical.com/pingz/var/lib/landscape/client)Z log_levelZurlZping_urlZ data_pathaThis module installs and configures ``landscape-client``. The landscape client will only be installed if the key ``landscape`` is present in config. Landscape client configuration is given under the ``client`` key under the main ``landscape`` config key. The config parameters are not interpreted by cloud-init, but rather are converted into a ConfigObj formatted file and written out to the `[client]` section in ``/etc/landscape/client.conf``. The following default client config is provided, but can be overridden:: landscape: client: log_level: "info" url: "https://landscape.canonical.com/message-system" ping_url: "http://landscape.canoncial.com/ping" data_path: "/var/lib/landscape/client" .. note:: see landscape documentation for client config keys .. note:: if ``tags`` is defined, its contents should be a string delimited with ``,`` rather than a list ZubuntuZ cc_landscapeZ Landscapez&Install and configure landscape clienta # To discover additional supported client keys, run # man landscape-config. landscape: client: url: "https://landscape.canonical.com/message-system" ping_url: "http://landscape.canonical.com/ping" data_path: "/var/lib/landscape/client" http_proxy: "http://my.proxy.com/foobar" https_proxy: "https://my.proxy.com/foobar" tags: "server,cloud" computer_title: "footitle" registration_key: "fookey" account_name: "fooaccount" z # Minimum viable config requires account_name and computer_title landscape: client: computer_title: kiosk 1 account_name: Joe's Biz aW # To install landscape-client from a PPA, specify apt.sources apt: sources: trunk-testing-ppa: source: ppa:landscape/self-hosted-beta landscape: client: account_name: myaccount computer_title: himom landscape)idnametitle descriptiondistrosZexamplesZ frequencyZactivate_by_schema_keys)rcfgcloudargsreturncCs|jdi}t|ts,tdjtj|d|s4dS|jjdgt t |g}t t ddt t|djD}tjd d g|tjtd dS) z Basically turn a top level 'landscape' entry with a 'client' dict and render it to ConfigObj format under '[client]' section in /etc/landscape/client.conf rzR'landscape' key existed in config, but not a dictionary type, is a {_type} instead)Z_typeNzlandscape-clientcSs&g|]\}}d|jdd|gqS)z--_-)replace).0kvr"/usr/lib/python3.6/cc_landscape.py szhandle..r zlandscape-configz--silentzRUN=1 )get isinstancedict RuntimeErrorformatrZobj_nameZdistroZinstall_packagesLSC_BUILTIN_CFGLSC_CLIENT_CFG_FILElistrsortedmerge_togetheritemsrrZ write_fileLS_DEFAULT_FILE)rrrrZ ls_cloudcfgZ merge_dataZ cmd_paramsrrr handleus$  r.cCsDti}x6|D].}|sqt|tr.|j|q|jt|qW|S)zu merge together ConfigObj objects or things that ConfigObj() will take in later entries override earlier )rr#merge)Zobjsrobjrrr r+s   r+)"__doc__Zlogging itertoolsrtextwraprZ configobjrZ cloudinitrrrZcloudinit.cloudrZcloudinit.configr Zcloudinit.config.schemar r Zcloudinit.settingsr r(r-r'ZMODULE_DESCRIPTIONrmetaZ getLogger__name__ZLOGstrr)r.r+rrrr  sF         )