Beispiel #1
0
func getNetworkUuidByName(
	client *contrail.Client, project_name, project_id, name string) (
	string, error) {
	var fqn []string
	if len(project_id) > 0 {
		uuid := strings.ToLower(project_id)
		if !config.IsUuid(uuid) {
			fmt.Fprintf(os.Stderr,
				"Invalid project-id value: %s\n", uuid)
			os.Exit(2)
		}
		obj, err := client.FindByUuid("project", project_id)
		if err != nil {
			fmt.Fprint(os.Stderr, err)
			os.Exit(2)
		}
		fqn = obj.GetFQName()
	} else {
		fqn = strings.Split(project_name, ":")
		if len(fqn) == 1 {
			obj := new(types.Project)
			fqn = append(obj.GetDefaultParent(), project_name)
		}
	}
	fqn = append(fqn, name)
	return client.UuidByName("virtual-network", strings.Join(fqn, ":"))
}
Beispiel #2
0
func GetProjectFQN(
	client *contrail.Client, projectName string, projectId string) (
	[]string, error) {
	if len(projectId) > 0 {
		uuid := strings.ToLower(projectId)
		if !IsUuid(uuid) {
			return nil,
				fmt.Errorf("Invalid uuid value: %s\n", uuid)
		}
		return client.FQNameByUuid(uuid)
	}

	if strings.ContainsRune(projectName, ':') {
		return strings.Split(projectName, ":"), nil
	}

	obj := new(types.Project)
	return append(obj.GetDefaultParent(), projectName), nil
}
Beispiel #3
0
func GetProjectId(
	client *contrail.Client, project_name string, project_id string) (
	string, error) {
	if len(project_id) > 0 {
		uuid := strings.ToLower(project_id)
		if !IsUuid(uuid) {
			return "",
				fmt.Errorf("Invalid uuid value: %s\n", uuid)
		}
		return uuid, nil
	}

	var name string
	if strings.ContainsRune(project_name, ':') {
		name = project_name
	} else {
		obj := new(types.Project)
		fqn := append(obj.GetDefaultParent(), project_name)
		name = strings.Join(fqn, `:`)
	}
	return client.UuidByName("project", name)
}