func ListResource(nsId string, resourceType string) (interface{}, error) {

	err := common.CheckString(nsId)
	if err != nil {
		common.CBLog.Error(err)
		return nil, err
	}

	if resourceType == common.StrImage ||
		resourceType == common.StrSSHKey ||
		resourceType == common.StrSpec ||
		resourceType == common.StrVNet ||
		//resourceType == "subnet" ||
		//resourceType == "publicIp" ||
		//resourceType == "vNic" ||
		resourceType == common.StrSecurityGroup {
		// continue
	} else {
		errString := "Cannot list " + resourceType + "s."
		err := fmt.Errorf(errString)
		return nil, err
	}

	fmt.Println("[Get " + resourceType + " list")
	key := "/ns/" + nsId + "/resources/" + resourceType
	fmt.Println(key)

	keyValue, err := common.CBStore.GetList(key, true)
	keyValue = cbstore_utils.GetChildList(keyValue, key)

	if err != nil {
		common.CBLog.Error(err)
		/*
			fmt.Println("func ListResource; common.CBStore.GetList gave error")
			var resourceList []string
			for _, v := range keyValue {
				resourceList = append(resourceList, strings.TrimPrefix(v.Key, "/ns/"+nsId+"/resources/"+resourceType+"/"))
			}
			for _, v := range resourceList {
				fmt.Println("<" + v + "> \n")
			}
			fmt.Println("===============================================")
		*/
		return nil, err
	}
	if keyValue != nil {
		switch resourceType {
		case common.StrImage:
			res := []TbImageInfo{}
			for _, v := range keyValue {
				tempObj := TbImageInfo{}
				err = json.Unmarshal([]byte(v.Value), &tempObj)
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
				res = append(res, tempObj)
			}
			return res, nil
		case common.StrSecurityGroup:
			res := []TbSecurityGroupInfo{}
			for _, v := range keyValue {
				tempObj := TbSecurityGroupInfo{}
				err = json.Unmarshal([]byte(v.Value), &tempObj)
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
				res = append(res, tempObj)
			}
			return res, nil
		case common.StrSpec:
			res := []TbSpecInfo{}
			for _, v := range keyValue {
				tempObj := TbSpecInfo{}
				err = json.Unmarshal([]byte(v.Value), &tempObj)
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
				res = append(res, tempObj)
			}
			return res, nil
		case common.StrSSHKey:
			res := []TbSshKeyInfo{}
			for _, v := range keyValue {
				tempObj := TbSshKeyInfo{}
				err = json.Unmarshal([]byte(v.Value), &tempObj)
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
				res = append(res, tempObj)
			}
			return res, nil
		case common.StrVNet:
			res := []TbVNetInfo{}
			for _, v := range keyValue {
				tempObj := TbVNetInfo{}
				err = json.Unmarshal([]byte(v.Value), &tempObj)
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
				res = append(res, tempObj)
			}
			return res, nil
		}

		//return true, nil
	}

	return nil, nil // When err == nil && keyValue == nil
}
// ListResource returns the list of TB MCIR objects of given resourceType
ListResource returns the list of TB MCIR objects of given resourceType
// ListResource returns the list of TB MCIR objects of given resourceType
func ListResource(nsId string, resourceType string) (interface{}, error) {
	err := common.CheckString(nsId)
	if err != nil {
		common.CBLog.Error(err)
		return nil, err
	}
	if resourceType == common.StrImage ||
		resourceType == common.StrSSHKey ||
		resourceType == common.StrSpec ||
		resourceType == common.StrVNet ||
		resourceType == common.StrSecurityGroup {
	} else {
		errString := "Cannot list " + resourceType + "s."
		err := fmt.Errorf(errString)
		return nil, err
	}
	fmt.Println("[Get " + resourceType + " list")
	key := "/ns/" + nsId + "/resources/" + resourceType
	fmt.Println(key)
	keyValue, err := common.CBStore.GetList(key, true)
	keyValue = cbstore_utils.GetChildList(keyValue, key)
	if err != nil {
		common.CBLog.Error(err)
		return nil, err
	}
	if keyValue != nil {
		switch resourceType {
		case common.StrImage:
			res := []TbImageInfo{}
			for _, v := range keyValue {
				tempObj := TbImageInfo{}
				err = json.Unmarshal([]byte(v.Value), &tempObj)
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
				res = append(res, tempObj)
			}
			return res, nil
		case common.StrSecurityGroup:
			res := []TbSecurityGroupInfo{}
			for _, v := range keyValue {
				tempObj := TbSecurityGroupInfo{}
				err = json.Unmarshal([]byte(v.Value), &tempObj)
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
				res = append(res, tempObj)
			}
			return res, nil
		case common.StrSpec:
			res := []TbSpecInfo{}
			for _, v := range keyValue {
				tempObj := TbSpecInfo{}
				err = json.Unmarshal([]byte(v.Value), &tempObj)
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
				res = append(res, tempObj)
			}
			return res, nil
		case common.StrSSHKey:
			res := []TbSshKeyInfo{}
			for _, v := range keyValue {
				tempObj := TbSshKeyInfo{}
				err = json.Unmarshal([]byte(v.Value), &tempObj)
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
				res = append(res, tempObj)
			}
			return res, nil
		case common.StrVNet:
			res := []TbVNetInfo{}
			for _, v := range keyValue {
				tempObj := TbVNetInfo{}
				err = json.Unmarshal([]byte(v.Value), &tempObj)
				if err != nil {
					common.CBLog.Error(err)
					return nil, err
				}
				res = append(res, tempObj)
			}
			return res, nil
		}
	}
	return nil, nil 
}
func ListResource ( nsId string , resourceType string ) ( interface { } , error ) { err := common . CheckString ( nsId ) if err != nil { common . CBLog . Error ( err ) return nil , err } if resourceType == common . StrImage || resourceType == common . StrSSHKey || resourceType == common . StrSpec || resourceType == common . StrVNet || resourceType == common . StrSecurityGroup { } else { errString := " " + resourceType + " " err := fmt . Errorf ( errString ) return nil , err } fmt . Println ( " " + resourceType + " " ) key := " " + nsId + " " + resourceType fmt . Println ( key ) keyValue , err := common . CBStore . GetList ( key , true ) keyValue = cbstore_utils . GetChildList ( keyValue , key ) if err != nil { common . CBLog . Error ( err ) return nil , err } if keyValue != nil { switch resourceType { case common . StrImage : res := [ ] TbImageInfo { } for _ , v := range keyValue { tempObj := TbImageInfo { } err = json . Unmarshal ( [ ] byte ( v . Value ) , & tempObj ) if err != nil { common . CBLog . Error ( err ) return nil , err } res = append ( res , tempObj ) } return res , nil case common . StrSecurityGroup : res := [ ] TbSecurityGroupInfo { } for _ , v := range keyValue { tempObj := TbSecurityGroupInfo { } err = json . Unmarshal ( [ ] byte ( v . Value ) , & tempObj ) if err != nil { common . CBLog . Error ( err ) return nil , err } res = append ( res , tempObj ) } return res , nil case common . StrSpec : res := [ ] TbSpecInfo { } for _ , v := range keyValue { tempObj := TbSpecInfo { } err = json . Unmarshal ( [ ] byte ( v . Value ) , & tempObj ) if err != nil { common . CBLog . Error ( err ) return nil , err } res = append ( res , tempObj ) } return res , nil case common . StrSSHKey : res := [ ] TbSshKeyInfo { } for _ , v := range keyValue { tempObj := TbSshKeyInfo { } err = json . Unmarshal ( [ ] byte ( v . Value ) , & tempObj ) if err != nil { common . CBLog . Error ( err ) return nil , err } res = append ( res , tempObj ) } return res , nil case common . StrVNet : res := [ ] TbVNetInfo { } for _ , v := range keyValue { tempObj := TbVNetInfo { } err = json . Unmarshal ( [ ] byte ( v . Value ) , & tempObj ) if err != nil { common . CBLog . Error ( err ) return nil , err } res = append ( res , tempObj ) } return res , nil } } return nil , nil }
ListResource returns the list of TB MCIR objects of given resourceType
ListResource returns the list of TB MCIR objects of given resourceType
//resourceType == "subnet" || //resourceType == "publicIp" || //resourceType == "vNic" || // continue /*
			fmt.Println("func ListResource; common.CBStore.GetList gave error")
			var resourceList []string
			for _, v := range keyValue {
				resourceList = append(resourceList, strings.TrimPrefix(v.Key, "/ns/"+nsId+"/resources/"+resourceType+"/"))
			}
			for _, v := range resourceList {
				fmt.Println("<" + v + "> \n")
			}
			fmt.Println("===============================================")
		*/ //return true, nil // When err == nil && keyValue == nil