nr_free_pages 40070
nr_alloc_batch 3189
nr_inactive_anon 190268
nr_active_anon 180508
nr_inactive_file 108286
nr_active_file 157912
nr_unevictable 0
nr_mlock 0
nr_anon_pages 254877
nr_mapped 31685
nr_file_pages 307858
nr_dirty 90
nr_writeback 0
nr_slab_reclaimable 94628
nr_slab_unreclaimable 52055
nr_page_table_pages 22340
nr_kernel_stack 8455
nr_unstable 0
nr_bounce 0
nr_vmscan_write 14531
nr_vmscan_immediate_reclaim 234
nr_writeback_temp 0
nr_isolated_anon 0
nr_isolated_file 0
nr_shmem 40766
nr_dirtied 824863
nr_written 804759
numa_hit 218402413
numa_miss 0
numa_foreign 0
numa_interleave 13305
numa_local 218402413
numa_other 0
workingset_refault 1799200
workingset_activate 847659
workingset_nodereclaim 0
nr_anon_transparent_hugepages 145
nr_free_cma 0
  "   lY>e8n2%1h߿h      usb-0000:00:01.2-2/input0
  :   lY>_)nZjbѿaY>e8Cp/e1h )    # Copyright (C) 2016 Canonical Ltd.
#
# Author: Wesley Wiedenmeier <wesley.wiedenmeier@canonical.com>
#
# This file is part of cloud-init. See LICENSE file for license information.

"""
LXD
---
**Summary:** configure lxd with ``lxd init`` and optionally lxd-bridge

This module configures lxd with user specified options using ``lxd init``.
If lxd is not present on the system but lxd configuration is provided, then
lxd will be installed. If the selected storage backend is zfs, then zfs will
be installed if missing. If network bridge configuration is provided, then
lxd-bridge will be configured accordingly.

**Internal name:** ``cc_lxd``

**Module frequency:** per instance

**Supported distros:** ubuntu

**Config keys**::

    lxd:
        init:
            network_address: <ip addr>
            network_port: <port>
            storage_backend: <zfs/dir>
            storage_create_device: <dev>
            storage_create_loop: <size>
            storage_pool: <name>
            trust_password: <password>
        bridge:
            mode: <new, existing or none>
            name: <name>
            ipv4_address: <ip addr>
            ipv4_netmask: <cidr>
            ipv4_dhcp_first: <ip addr>
            ipv4_dhcp_last: <ip addr>
            ipv4_dhcp_leases: <size>
            ipv4_nat: <bool>
            ipv6_address: <ip addr>
            ipv6_netmask: <cidr>
            ipv6_nat: <bool>
            domain: <domain>
"""

from cloudinit import log as logging
from cloudinit import util
import os

distros = ['ubuntu']

LOG = logging.getLogger(__name__)

_DEFAULT_NETWORK_NAME = "lxdbr0"


def handle(name, cfg, cloud, log, args):
    # Get config
    lxd_cfg = cfg.get('lxd')
    if not lxd_cfg:
        log.debug("Skipping module named %s, not present or disabled by cfg",
                  name)
        return
    if not isinstance(lxd_cfg, dict):
        log.warning("lxd config must be a dictionary. found a '%s'",
                    type(lxd_cfg))
        return

    # Grab the configuration
    init_cfg = lxd_cfg.get('init')
    if not isinstance(init_cfg, dict):
        log.warning("lxd/init config must be a dictionary. found a '%s'",
                    type(init_cfg))
        init_cfg = {}

    bridge_cfg = lxd_cfg.get('bridge', {})
    if not isinstance(bridge_cfg, dict):
        log.warning("lxd/bridge config must be a dictionary. found a '%s'",
                    type(bridge_cfg))
        bridge_cfg = {}

    # Install the needed packages
    packages = []
    if not util.which("lxd"):
        packages.append('lxd')

    if init_cfg.get("storage_backend") == "zfs" and not util.which('zfs'):
        packages.append('zfsutils-linux')

    if len(packages):
        try:
            cloud.distro.install_packages(packages)
        except util.ProcessExecutionError as exc:
            log.warning("failed to install packages %s: %s", packages, exc)
            return

    # Set up lxd if init config is given
    if init_cfg:
        init_keys = (
            'network_address', 'network_port', 'storage_backend',
            'storage_create_device', 'storage_create_loop',
            'storage_pool', 'trust_password')
        u