from subprocess import call
from load_deployment_config import load_server_config

if __name__ == '__main__':
    try:
        print (" Loading server node structure...")
        serverList = load_server_config()
	for vm in serverList:
                print (" Deleting certificate for " + vm + ".openstacklocal...")
		call("puppet cert clean " + vm + ".openstacklocal", shell=True)

    except BaseException as b:
        print 'Exception in deletePuppetCert.py: ', b
        # get deployment automation environment name
        print(" Finding Environment...")
        environment = get_environment()

        if environment == "openstack":
            """Perform OpenStack specific deployment automation pre-tasks"""

            # load openstack cloud configurations
            print(" Loading nova configuration and spawning instances...")
            imageName = get_openstack_image()
            flavorName = get_openstack_flavor()
            networkName = get_openstack_network()
            instancePassword = get_openstack_instance_password()
            keyPairName = get_openstack_key_pair()

            # load server configurations
            print(" Loading deployment cluster configuration...")
            serverList = load_server_config()

            # spawn cluster topology in OpenStack environment and update puppet templates with instances' facter info
            cluster = initialize_cluster(serverList, imageName, flavorName,
                                         networkName, instancePassword,
                                         keyPairName)

        else:
            print(" Deployment automation for " + environment +
                  " is not implemented yet...")

    except BaseException as b:
        print 'Exception in __main__.py: ', b