Ejemplo n.º 1
0
// NewREST returns a RESTStorage object that will work against networks.
func NewREST(opts generic.RESTOptions) (*REST, *StatusREST) {
	prefix := "/networks"

	newListFunc := func() runtime.Object { return &api.NetworkList{} }
	storageInterface := opts.Decorator(
		opts.Storage, cachesize.GetWatchCacheSizeByResource(cachesize.Namespaces), &api.Network{}, prefix, network.Strategy, newListFunc)

	store := &registry.Store{
		NewFunc:     func() runtime.Object { return &api.Network{} },
		NewListFunc: newListFunc,
		KeyRootFunc: func(ctx api.Context) string {
			return prefix
		},
		KeyFunc: func(ctx api.Context, name string) (string, error) {
			return prefix + "/" + name, nil
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.Network).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return network.MatchNetwork(label, field)
		},
		QualifiedResource: api.Resource("networks"),

		CreateStrategy:      network.Strategy,
		UpdateStrategy:      network.Strategy,
		DeleteStrategy:      network.Strategy,
		ReturnDeletedObject: true,

		Storage: storageInterface,
	}

	statusStore := *store
	statusStore.UpdateStrategy = network.StatusStrategy

	return &REST{Store: store, status: &statusStore}, &StatusREST{store: &statusStore}
}
Ejemplo n.º 2
0
// NewREST returns a RESTStorage object that will work against networks.
func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) (*REST, *StatusREST) {
	prefix := "/networks"

	newListFunc := func() runtime.Object { return &api.NetworkList{} }
	storageInterface := storageDecorator(
		s, 100, &api.Network{}, prefix, true, newListFunc)

	store := &etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &api.Network{} },
		NewListFunc: newListFunc,
		KeyRootFunc: func(ctx api.Context) string {
			return prefix
		},
		KeyFunc: func(ctx api.Context, name string) (string, error) {
			return prefix + "/" + name, nil
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.Network).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return network.MatchNetwork(label, field)
		},
		QualifiedResource: api.Resource("networks"),

		CreateStrategy:      network.Strategy,
		UpdateStrategy:      network.Strategy,
		ReturnDeletedObject: true,

		Storage: storageInterface,
	}

	statusStore := *store
	statusStore.UpdateStrategy = network.StatusStrategy

	return &REST{Etcd: store, status: &statusStore}, &StatusREST{store: &statusStore}
}