func init() { registerResource( api.NewHostEndpoint(), api.NewHostEndpointList(), []string{"NODE", "NAME"}, []string{"NODE", "NAME", "INTERFACE", "IPS", "PROFILES"}, map[string]string{ "NODE": "{{.Metadata.Node}}", "NAME": "{{.Metadata.Name}}", "INTERFACE": "{{.Spec.InterfaceName}}", "IPS": "{{join .Spec.ExpectedIPs \",\"}}", "PROFILES": "{{join .Spec.Profiles \",\"}}", }, func(client *client.Client, resource unversioned.Resource) (unversioned.Resource, error) { r := resource.(api.HostEndpoint) return client.HostEndpoints().Apply(&r) }, func(client *client.Client, resource unversioned.Resource) (unversioned.Resource, error) { r := resource.(api.HostEndpoint) return client.HostEndpoints().Create(&r) }, func(client *client.Client, resource unversioned.Resource) (unversioned.Resource, error) { r := resource.(api.HostEndpoint) return client.HostEndpoints().Update(&r) }, func(client *client.Client, resource unversioned.Resource) (unversioned.Resource, error) { r := resource.(api.HostEndpoint) return nil, client.HostEndpoints().Delete(r.Metadata) }, func(client *client.Client, resource unversioned.Resource) (unversioned.Resource, error) { r := resource.(api.HostEndpoint) return client.HostEndpoints().List(r.Metadata) }, ) }
// getResourceFromArguments returns a resource instance from the command line arguments. func getResourceFromArguments(args map[string]interface{}) (unversioned.Resource, error) { kind := args["<KIND>"].(string) name := argutils.ArgStringOrBlank(args, "<NAME>") node := argutils.ArgStringOrBlank(args, "--node") workload := argutils.ArgStringOrBlank(args, "--workload") orchestrator := argutils.ArgStringOrBlank(args, "--orchestrator") resScope := argutils.ArgStringOrBlank(args, "--scope") switch strings.ToLower(kind) { case "node", "nodes": p := api.NewNode() p.Metadata.Name = name return *p, nil case "hostendpoint", "hostendpoints": h := api.NewHostEndpoint() h.Metadata.Name = name h.Metadata.Node = node return *h, nil case "workloadendpoint", "workloadendpoints": h := api.NewWorkloadEndpoint() h.Metadata.Name = name h.Metadata.Orchestrator = orchestrator h.Metadata.Workload = workload h.Metadata.Node = node return *h, nil case "profile", "profiles": p := api.NewProfile() p.Metadata.Name = name return *p, nil case "policy", "policies": p := api.NewPolicy() p.Metadata.Name = name return *p, nil case "ippool", "ippools": p := api.NewIPPool() if name != "" { _, cidr, err := net.ParseCIDR(name) if err != nil { return nil, err } p.Metadata.CIDR = *cidr } return *p, nil case "bgppeer", "bgppeers": p := api.NewBGPPeer() if name != "" { err := p.Metadata.PeerIP.UnmarshalText([]byte(name)) if err != nil { return nil, err } } p.Metadata.Node = node switch resScope { case "node": p.Metadata.Scope = scope.Node case "global": p.Metadata.Scope = scope.Global case "": p.Metadata.Scope = scope.Undefined default: return nil, fmt.Errorf("Unrecognized scope '%s', must be one of: global, node", resScope) } return *p, nil default: return nil, fmt.Errorf("Resource type '%s' is not supported", kind) } }