示例#1
0
// Locate the policy given project name/id and policy name/id.
func getPolicyObject(
	client *contrail.Client,
	projectName, projectId, policyNameOrId string) (
	*types.NetworkPolicy, error) {

	if len(policyNameOrId) == 0 {
		return nil, fmt.Errorf("policy name or uuid must be specified")
	}

	if uuid := strings.ToLower(policyNameOrId); config.IsUuid(uuid) {
		obj, err := client.FindByUuid("network-policy", uuid)
		if err != nil {
			return nil, err
		}
		return obj.(*types.NetworkPolicy), nil
	}

	fqn, err := config.GetProjectFQN(client, projectName, projectId)
	if err != nil {
		return nil, err
	}
	fqn = append(fqn, policyNameOrId)
	obj, err := client.FindByName("network-policy", strings.Join(fqn, ":"))
	if err != nil {
		return nil, err
	}
	return obj.(*types.NetworkPolicy), nil
}
示例#2
0
func getPolicyId(client *contrail.Client,
	projectName, projectId, policyNameOrId string) (
	string, error) {

	uuid := strings.ToLower(policyNameOrId)
	if !config.IsUuid(uuid) {
		fqn, err := config.GetProjectFQN(client, projectName, projectId)
		if err != nil {
			return "", err
		}
		fqn = append(fqn, policyNameOrId)
		uuid, err = client.UuidByName("network-policy",
			strings.Join(fqn, ":"))
		if err != nil {
			return "", err
		}
	}
	return uuid, nil
}
示例#3
0
// Create (an empty) network-policy.
func policyCreate(client *contrail.Client, flagSet *flag.FlagSet) {
	if flagSet.NArg() < 1 {
		flagSet.Usage()
		os.Exit(2)
	}

	name := flagSet.Args()[0]

	projectFQN, err := config.GetProjectFQN(client,
		policyCommonOpts.project, policyCommonOpts.projectId)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	policy := new(types.NetworkPolicy)
	policy.SetFQName("project", append(projectFQN, name))
	err = client.Create(policy)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}