#!/usr/bin/env python
#coding=utf-8

from userValidate import UserValidate
from vmlist import VmList
from virtMachine import VirtMachine

if __name__ == "__main__":

    import os,sys
    _dirs = os.path.abspath(__file__)  #  当前文件路径
    _dirs = os.path.dirname(_dirs)     #  当前文件目录
    _dirs = os.path.dirname(_dirs)     #  上级文件路径
    _dirs = os.path.dirname(_dirs)     #  上级文件路径
    sys.path.append(_dirs)  #

    from des import Des

    from os import environ
    environ["LOG_STDOUT"] = "stdout"  #
    en_str = Des.Encrypt("Pass1234")  #加密
    print en_str
    # dec_str = Des.Decrypt(en_str)
    # print dec_str

    userInfo = {
                "userName"      : "wr",
                "userPassword"  :  en_str,    #"Pass1234",
    }
    from os import environ
    environ["MCOS_APP_ICON_PATH"] = "/tmp/images/appIcon"

    #登录验证
    userValidate = UserValidate(userInfo,"192.168.102.33:8080")
    res = userValidate.login()
    print "userValidate : ",res

    # #虚拟机列表
    # vmList = VmList(userInfo,"192.168.102.33:8080")
    # res = vmList.getVMlist()
    # if res[0] == True:
    #     vmlistInfo = res[1]
    #
    #     virtMachineList = []
    #     for i in range(len(vmlistInfo)):
    #         vm = VirtMachine(vmlistInfo[i],userInfo,"192.168.102.33:8080")
    #         # print vm.getSingleVMInfo()
    #         #vm.getVMPasswd()
    #         #vm.VMPoweroff()
    #         #vm.VMPowerOn()
    #
    #         # vm.enterVM()
    #         # vm.downloadCertificate()
    #         from spiceDomain import SpiceDomain
    #         # print vmlistInfo[i]
    #         spicedomain = SpiceDomain(vmlistInfo[i],userInfo,"192.168.102.33:8080")
    #         print "------------"
    #         #spicedomain.getSpiceDomain()
    #         print "------------"
    #         print "------------"
    #         res = spicedomain.getSpiceServerIp()
    #         print "))))) ",res
    #         print "------------"
    #         print "------------"
    #         virtMachineList.append(vm)

        # for i in range(len(virtMachineList)):
        #     print "****************"
        #     print virtMachineList[i].getSingleVMInfo()
        #     #print "虚拟机密码：", virtMachineList[i].getVMPasswd()     # 动态 密码
        #
        #     print "+++++++++++++"
        #     virtMachineList[i].vmInfoShow()

    # from agentInfo import AgentInfo
    # agent = AgentInfo(userInfo,"192.168.102.33:8080")
    # applist = agent.getApplist()
    # agent.downloadAppIcons()
    # print "-----  &&& ------ : ",applist
    # agentInfo = agent.getAgentInfo()
    # print "### : ",agentInfo

    # userValidate.setSessionState_loged()
    # #注销
    a = raw_input("")
    print userValidate.logout()
    print userValidate.sessionIsLogout()

    #print vmlistInfo