#!/usr/bin/python

"""
Retrieves the VNC certificate from an Invirt host
"""

from invirt.config import structs as config
from subprocess import Popen, call, PIPE
import sys


def main(argv):
    if len(argv) < 2:
        print >> sys.stderr, "usage: invirt-remote-vnccert <host>"
        return 2
    
    host = argv[1]
    
    if host not in list(i.hostname for i in config.hosts):
        print >> sys.stderr, "Invalid hostname specified"
        return 1
    
    return call(['remctl', host, 'remote', 'web', 'vnccert'])

if __name__ == '__main__':
    sys.exit(main(sys.argv))
