# vm_exercise_3_1.py - script to  run/delete a VM.
#
# R. Melton
# 9/25/15
####################################################################


from keystone_mgr import KeystoneMgr
from nova_mgr import NovaMgr
import os, json, sys

# we need to fix the python search path so that we can find crendentials.py
sys.path.append(os.environ["HOME"] + "/code/scripts/class/python_class_1")
from credentials import get_neutron_creds, get_keystone_creds

print "\n\nexercise ", sys.argv[0]
# create the OpenStack objects we will need
my_nova = NovaMgr()
my_nova.check_params()
my_keystone = KeystoneMgr()

# list beginning info for the system
my_keystone.print_tenant()
my_nova.print_instances()
vm_name = sys.argv[1]
net_uuid = sys.argv[2]
inst = my_nova.create_instance(vm_name, net_uuid)
my_nova.print_instances()
my_nova.delete_instance(name=vm_name)
my_nova.print_instances()