info(name, template, c1[0][10])
      else
        return get_success_info(name, template, c1[0][10])
      end
    end

    def get_error_info(name, template, job_id)
      info = get_error_job(name, job_id)
      b_json = {
        "ID"=>0,
        "UID"=>@user_details['user_id'],
        "GID"=>@user_details['group_id'],
        "UNAME"=>@user_details['username'],
        "GNAME"=>@user_details['group_name'],
        "NAME"=>name,
        "HOST"=>'ERROR',
        "HOST_GROUP"=>'ERROR',
        "UUID"=> 'ERROR',
        "PERMISSIONS"=>{
          "OWNER_U"=>"1",
          "OWNER_M"=>"1",
          "OWNER_A"=>"0",
          "GROUP_U"=>"0",
          "GROUP_M"=>"0",
          "GROUP_A"=>"0",
          "OTHER_U"=>"0",
          "OTHER_M"=>"0",
          "OTHER_A"=>"0"
        },
        "LAST_POLL"=>"0",
        "STATE"=>'ERROR',
        "CONFIG_STATE"=>'ERROR',
        "LCM_STATE"=>"0",
        "RESCHED"=>"0",
        "STIME"=>'ERROR',
        "MTIME"=>'ERROR',
        "ETIME"=>"0",
        "DEPLOY_ID"=>{},
        "MEMORY"=>'ERROR',
        "CPU"=>'ERROR',
        "NET_TX"=>"0",
        "NET_RX"=>"0",
        "NIC_IPS"=>"",
        "NICS"=>[],
        "ALLOCATED_PORT"=>'ERROR',
        "HYPERVISOR"=>'ERROR',
        "OS"=>'ERROR',
        "DISKS"=> [{
            "DISK_TEMPLATE"=> 'ERROR',
            "SIZE"=> 'ERROR',
            "ACCESS_MODE"=> 'ERROR',
            "LOGICAL_ID"=> 'ERROR'
          }],
        "TEMPLATE"=>{
          "NAME"=> template["NAME"],
          "CPU"=> template["CPU"],
          "MEMORY"=>template["MEMORY"],
          "OPERATING_SYSTEM"=>template["OS"],
          "DISK_SIZE"=>template["DISK_SIZE"],
          "HOST_NAME"=>template["HOST_NAME"],
          "MACHINE"=>template["TEMPLATE"]["OS"]["MACHINE"],
          "KERNEL_CMD"=>template["TEMPLATE"]["OS"]["KERNEL_CMD"],
          "KERNEL"=>template["TEMPLATE"]["OS"]["KERNEL"],
          "INITRD"=>template["TEMPLATE"]["OS"]["INITRD"],
          "REGTIME"=>template["REGTIME"]
        },
        "LOG"=>info["opresult"][0][1],
        "USER_TEMPLATE"=>{},
        "HISTORY_RECORDS"=>{}
      }
      b_json
    end

    def get_success_info(name, template, job_id)
      info = get_info(name, job_id)
      c1 = connect.execute( "select * from vms where vm_name = '" + name + "'")
      template = getTemplate(c1[0][7].to_s)
      b_json = {
        "ID"=>info["opresult"][0]["#{name}"]["serial_no"],
        "UID"=>@user_details['user_id'],
        "GID"=>@user_details['group_id'],
        "UNAME"=>@user_details['username'],
        "GNAME"=>@user_details['group_name'],
        "NAME"=>name,
        "HOST"=>info["opresult"][0]["#{name}"]["pnode"],
        "HOST_GROUP"=>info["opresult"][0]["#{name}"]["pnode_group_name"],
        "UUID"=> info["opresult"][0]["#{name}"]["uuid"],
        "PERMISSIONS"=>{
          "OWNER_U"=>"1",
          "OWNER_M"=>"1",
          "OWNER_A"=>"0",
          "GROUP_U"=>"0",
          "GROUP_M"=>"0",
          "GROUP_A"=>"0",
          "OTHER_U"=>"0",
          "OTHER_M"=>"0",
          "OTHER_A"=>"0"
        },
        "LAST_POLL"=>"0",
        "STATE"=>info["opresult"][0]["#{name}"]["run_state"],
        "CONFIG_STATE"=>info["opresult"][0]["#{name}"]["config_state"],
        "LCM_STATE"=>"0",
        "RESCHED"=>"0",
        "STIME"=>info["opresult"][0]["#{name}"]["ctime"],
        "MTIME"=>info["opresult"][0]["#{name}"]["mtime"],
        "ETIME"=>"0",
        "DEPLOY_ID"=>{},
        "MEMORY"=>info["opresult"][0]["#{name}"]["be_instance"]["maxmem"],
        "CPU"=>info["opresult"][0]["#{name}"]["be_actual"]["vcpus"],
        "NET_TX"=>"0",
        "NET_RX"=>"0",
        "NIC_IPS"=>"",
        "NICS"=>info["opresult"][0]["#{name}"]["nics"],
        "ALLOCATED_PORT"=>info["opresult"][0]["#{name}"]["network_port"],
        "HYPERVISOR"=>info["opresult"][0]["#{name}"]["hypervisor"],
        "OS"=>info["opresult"][0]["#{name}"]["os"],
        "DISKS"=> info["opresult"][0]["#{name}"]["disks"].map { |disk| disk_collect(disk) },
        "TEMPLATE"=>{
          "NAME"=> template["NAME"],
          "CPU"=> template["CPU"],
          "MEMORY"=>template["MEMORY"],
          "OPERATING_SYSTEM"=>template["OS"],
          "DISK_SIZE"=>template["DISK_SIZE"],
          "HOST_NAME"=>template["HOST_NAME"],
          "MACHINE"=>template["TEMPLATE"]["OS"]["MACHINE"],
          "KERNEL_CMD"=>template["TEMPLATE"]["OS"]["KERNEL_CMD"],
          "KERNEL"=>template["TEMPLATE"]["OS"]["KERNEL"],
          "INITRD"=>template["TEMPLATE"]["OS"]["INITRD"],
          "REGTIME"=>template["REGTIME"]
        },
        "LOG"=>[],
        "USER_TEMPLATE"=>{},
        "HISTORY_RECORDS"=>{}
      }
      b_json
    end

    def disk_collect(disk)
      js = {
        "DISK_TEMPLATE"=> disk["dev_type"],
        "SIZE"=> disk["size"],
        "ACCESS_MODE"=> disk["mode"],
        "LOGICAL_ID"=> "#{disk["logical_id"][0]}" +"/" + "#{disk["logical_id"][1]}"
      }
    end

    def get_error_job(name, job_id)
      ins_data = @client.call("/2/jobs/#{job_id}", 'GET')
      JSON.parse(ins_data.data[:body])
    #ins_data.data[:body]
    end

    def get_info(name, job_id)
      ins_data = @client.call(@path+"/#{name}/info", 'GET')
      job = ins_data.data[:body]
      sleep 2
      ins_data = @client.call("/2/jobs/#{job}", 'GET')
      JSON.parse(ins_data.data[:body])
    #ins_data.data[:body]