# Author: Milan Kubik

import logging


log = logging.getLogger(__name__)

def create(topology, config, output):
    """Initialize backend and prepare configuration

    The function takes the parsed parameters and initializes
    and uses the configured backend.
    """

    pass


def delete(config):
    """Dispose of the resources

    The function instantiates the backend class
    and requests to remove any provisioned resources.

    The backend itself is responsible for managing caches.
    """
    pass

@@ -31,16 +31,398 @@
 logging%0A
+import yaml%0A%0Afrom ipaqe_provision_hosts.utils import load_config, load_topology%0Afrom ipaqe_provision_hosts.errors import IPAQEProvisionerError%0Afrom ipaqe_provision_hosts.backend.loader import load_backends%0Afrom ipaqe_provision_hosts.static_inventory import StaticInventory%0Afrom ipaqe_provision_hosts.topology_manager import TopologyInventory%0A%0Afrom ipaqe_provision_hosts import paths
 %0A%0Alog = 
@@ -450,16 +450,17 @@
 ame__)%0A%0A
+%0A
 def crea
@@ -657,243 +657,2834 @@
     
-pass%0A%0A%0Adef delete(config):%0A    %22%22%22Dispose of the resources%0A%0A    The function instantiates the backend class%0A    and requests to remove any provisioned resources.%0A%0A    The backend itself is responsible for managing caches.%0A    %22%22%22%0A    pass
+log.debug(%22Running the create command%22)%0A%0A    try:%0A        # Load configuration files%0A        config = load_config(config)%0A        topology_template = load_topology(topology)%0A%0A        # Initialize backend map%0A        backends = load_backends()%0A%0A        # Prepare relevant parts of configuration%0A        # Instantiate backend according to configuration%0A        try:%0A            b_config = config%5B'backend'%5D%0A            backend = backends%5Bb_config%5B'name'%5D%5D(b_config%5B'config'%5D)%0A        except KeyError as e:%0A            log.error(%0A                %22Problem accessing backend configuration %22%0A                %22or instantiating a backend%22)%0A            raise IPAQEProvisionerError%0A%0A        log.debug(%22Retrieving static inventory file path%22)%0A        static_resources_path = (%0A            config%5B'core'%5D.get('static_resources',%0A                               paths.DEFAULT_STATIC_INVENTORY)%0A        )%0A        static_resources_os_version = (%0A            config%5B'core'%5D.get('os_version')%0A        )%0A        static_inventory = StaticInventory(%0A            static_resources_path, os_version=static_resources_os_version)%0A%0A        # Instantiate the TopologyManager%0A        inventory = TopologyInventory(backend, static_inventory)%0A%0A        dns_forwarder, provisioned_domains = (%0A            inventory.provision_topology(topology_template))%0A        config%5B'domain_settings'%5D%5B'dns_forwarder'%5D = dns_forwarder%0A%0A        multihost_config = %7B%7D%0A%0A        multihost_config%5B'domains'%5D = provisioned_domains%0A        multihost_config.update(config%5B'domain_settings'%5D)%0A%0A        with open(output, mode='w') as f:%0A            log.debug(%22Writing the configuration file to %25s%22, output)%0A            yaml.safe_dump(multihost_config, f, default_flow_style=False)%0A%0A    except IPAQEProvisionerError as e:%0A        log.debug(%22Aborting create call: %25s%22, e.message)%0A        raise%0A%0A%0Adef delete(config):%0A    %22%22%22Dispose of the resources%0A%0A    The function instantiates the backend class%0A    and requests to remove any provisioned resources.%0A%0A    The backend itself is responsible for managing caches.%0A    %22%22%22%0A    log.debug(%22Running the delete command%22)%0A%0A    try:%0A        # Load configuration files%0A        config = load_config(config)%0A        # Initialize backend map%0A        backends = load_backends()%0A%0A        # Prepare relevant parts of configuration%0A        # Instantiate backend according to configuration%0A        try:%0A            b_config = config%5B'backend'%5D%0A            backend = backends%5Bb_config%5B'name'%5D%5D(b_config%5B'config'%5D)%0A        except KeyError as e:%0A            log.error(%0A                %22Problem accessing backend configuration %22%0A                %22or instantiating a backend%22)%0A            raise IPAQEProvisionerError%0A%0A        backend.delete_resources()%0A%0A    except IPAQEProvisionerError as e:%0A        log.debug(%22Aborting delete call: %25s%22, e.message)%0A        raise
 %0A

Implement the runner module