Extending functionality of maasng:

* machine_power_state: Check power state of a node
* list_ipaddresses: get list of reserved IPs
* reserve_ipaddress: reserve ip address in specific subnet
* release_ipaddress: release specified ip address
* list_dnsresources: get list of dns records from maas
* sync_address_pool: sync address pool from pillar to maas

  Example:

    openstack_share_node02_deploy_address: deploy_network

  would be recognized as an ip address request from deploy_network
  maasng.reserve_ipaddress openstack_share_node02_deploy_address \
      deploy_network["cidr"]

  will happen.
  Maas reservation from CIDR would be used in ext_pillar to
  back populate and overwrite 'deploy_network' with an ip address.

    salt '*' pillar.get openstack_share_node02_deploy_address

  will return IP address instead of 'deploy_network'

Change-Id: Idac2849a82e30df683df2a83824544ca5f0265f2
diff --git a/_modules/maas-IPAM.py b/_modules/maas-IPAM.py
new file mode 100755
index 0000000..3e910b8
--- /dev/null
+++ b/_modules/maas-IPAM.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python2.7
+from argparse import ArgumentParser
+import json
+import yaml
+import logging
+
+from maas_client import MAASClient, MAASDispatcher, MAASOAuth
+from maasng import list_dnsresources
+
+parser = ArgumentParser()
+parser.add_argument('--address_pool', help='Path to address_pool \
+                    yaml file', required=True)
+parser.add_argument('--debug', action='store_true', default=False)
+
+def maas_IPAM():
+    args = parser.parse_args()
+
+    handler = logging.StreamHandler()
+
+    if args.debug:
+        log_level = logging.DEBUG
+    else:
+        log_level = logging.INFO
+
+    LOG = logging.getLogger()
+    LOG.setLevel(log_level)
+    LOG.addHandler(handler)
+
+    with open(args.address_pool, 'r') as f:
+        yaml_data = yaml.safe_load(f)
+
+    # TODO: (dstremkouski)
+    # schema validator for address pool
+    address_pool = yaml_data["parameters"]["address_pool"]
+    dnsresources = list_dnsresources()
+
+    for dnsres in dnsresources:
+        mapping_found = False
+        for net in address_pool:
+            if net == 'external':
+                continue
+            if mapping_found:
+                continue
+            for addr in address_pool[net]['pool']:
+                if dnsres["hostname"] == addr:
+                    address_pool[net]['pool'][addr] = dnsres["ip_addresses"][0]
+                    mapping_found = True
+                    break
+
+    return('{"address_pool": ' + json.dumps(address_pool) + '}')
+
+if __name__ == "__main__":
+    print maas_IPAM()