1 // Code generated by ./crud.sh -o crud.go; DO NOT EDIT.
7 // Hosts returns a slice of Host matching the filter expression filter.
8 // If no hosts match, error wraps ErrNoMatch.
9 // To fetch all host, set filter to the empty string ("").
10 func (c *Client) Hosts(filter string) ([]Host, error) {
11 objects, err := c.filterObjects("/objects/hosts", filter)
13 return nil, fmt.Errorf("get hosts filter %q: %w", filter, err)
16 for _, o := range objects {
19 return nil, fmt.Errorf("get hosts filter %q: %T in response", filter, v)
21 hosts = append(hosts, v)
26 // LookupHost returns the Host identified by name. If no Host is found, error
28 func (c *Client) LookupHost(name string) (Host, error) {
29 obj, err := c.lookupObject("/objects/hosts/" + name)
31 return Host{}, fmt.Errorf("lookup host %s: %w", name, err)
35 return Host{}, fmt.Errorf("lookup host %s: result type %T is not Host", name, v)
40 // CreateHost creates host. Some fields of host must be set for successful
41 // creation; see the type definition of Host for details.
42 func (c *Client) CreateHost(host Host) error {
43 if err := c.createObject(host); err != nil {
44 return fmt.Errorf("create host %s: %w", host.Name, err)
49 // DeleteHost deletes the Host identified by name. If cascade is true, objects
50 // depending on the Host are also deleted. If no Host is found, error wraps
52 func (c *Client) DeleteHost(name string, cascade bool) error {
53 if err := c.deleteObject("/objects/hosts/"+name, cascade); err != nil {
54 return fmt.Errorf("delete host %s: %w", name, err)
59 // Services returns a slice of Service matching the filter expression filter.
60 // If no services match, error wraps ErrNoMatch.
61 // To fetch all service, set filter to the empty string ("").
62 func (c *Client) Services(filter string) ([]Service, error) {
63 objects, err := c.filterObjects("/objects/services", filter)
65 return nil, fmt.Errorf("get services filter %q: %w", filter, err)
67 var services []Service
68 for _, o := range objects {
71 return nil, fmt.Errorf("get services filter %q: %T in response", filter, v)
73 services = append(services, v)
78 // LookupService returns the Service identified by name. If no Service is found, error
80 func (c *Client) LookupService(name string) (Service, error) {
81 obj, err := c.lookupObject("/objects/services/" + name)
83 return Service{}, fmt.Errorf("lookup service %s: %w", name, err)
85 v, ok := obj.(Service)
87 return Service{}, fmt.Errorf("lookup service %s: result type %T is not Service", name, v)
92 // CreateService creates service. Some fields of service must be set for successful
93 // creation; see the type definition of Service for details.
94 func (c *Client) CreateService(service Service) error {
95 if err := c.createObject(service); err != nil {
96 return fmt.Errorf("create service %s: %w", service.Name, err)
101 // DeleteService deletes the Service identified by name. If cascade is true, objects
102 // depending on the Service are also deleted. If no Service is found, error wraps
104 func (c *Client) DeleteService(name string, cascade bool) error {
105 if err := c.deleteObject("/objects/services/"+name, cascade); err != nil {
106 return fmt.Errorf("delete service %s: %w", name, err)
111 // Users returns a slice of User matching the filter expression filter.
112 // If no users match, error wraps ErrNoMatch.
113 // To fetch all user, set filter to the empty string ("").
114 func (c *Client) Users(filter string) ([]User, error) {
115 objects, err := c.filterObjects("/objects/users", filter)
117 return nil, fmt.Errorf("get users filter %q: %w", filter, err)
120 for _, o := range objects {
123 return nil, fmt.Errorf("get users filter %q: %T in response", filter, v)
125 users = append(users, v)
130 // LookupUser returns the User identified by name. If no User is found, error
131 // wraps ErrNotExist.
132 func (c *Client) LookupUser(name string) (User, error) {
133 obj, err := c.lookupObject("/objects/users/" + name)
135 return User{}, fmt.Errorf("lookup user %s: %w", name, err)
139 return User{}, fmt.Errorf("lookup user %s: result type %T is not User", name, v)
144 // CreateUser creates user. Some fields of user must be set for successful
145 // creation; see the type definition of User for details.
146 func (c *Client) CreateUser(user User) error {
147 if err := c.createObject(user); err != nil {
148 return fmt.Errorf("create user %s: %w", user.Name, err)
153 // DeleteUser deletes the User identified by name. If cascade is true, objects
154 // depending on the User are also deleted. If no User is found, error wraps
156 func (c *Client) DeleteUser(name string, cascade bool) error {
157 if err := c.deleteObject("/objects/users/"+name, cascade); err != nil {
158 return fmt.Errorf("delete user %s: %w", name, err)
163 // HostGroups returns a slice of HostGroup matching the filter expression filter.
164 // If no hostgroups match, error wraps ErrNoMatch.
165 // To fetch all hostgroup, set filter to the empty string ("").
166 func (c *Client) HostGroups(filter string) ([]HostGroup, error) {
167 objects, err := c.filterObjects("/objects/hostgroups", filter)
169 return nil, fmt.Errorf("get hostgroups filter %q: %w", filter, err)
171 var hostgroups []HostGroup
172 for _, o := range objects {
173 v, ok := o.(HostGroup)
175 return nil, fmt.Errorf("get hostgroups filter %q: %T in response", filter, v)
177 hostgroups = append(hostgroups, v)
179 return hostgroups, nil
182 // LookupHostGroup returns the HostGroup identified by name. If no HostGroup is found, error
183 // wraps ErrNotExist.
184 func (c *Client) LookupHostGroup(name string) (HostGroup, error) {
185 obj, err := c.lookupObject("/objects/hostgroups/" + name)
187 return HostGroup{}, fmt.Errorf("lookup hostgroup %s: %w", name, err)
189 v, ok := obj.(HostGroup)
191 return HostGroup{}, fmt.Errorf("lookup hostgroup %s: result type %T is not HostGroup", name, v)
196 // CreateHostGroup creates hostgroup. Some fields of hostgroup must be set for successful
197 // creation; see the type definition of HostGroup for details.
198 func (c *Client) CreateHostGroup(hostgroup HostGroup) error {
199 if err := c.createObject(hostgroup); err != nil {
200 return fmt.Errorf("create hostgroup %s: %w", hostgroup.Name, err)
205 // DeleteHostGroup deletes the HostGroup identified by name. If cascade is true, objects
206 // depending on the HostGroup are also deleted. If no HostGroup is found, error wraps
208 func (c *Client) DeleteHostGroup(name string, cascade bool) error {
209 if err := c.deleteObject("/objects/hostgroups/"+name, cascade); err != nil {
210 return fmt.Errorf("delete hostgroup %s: %w", name, err)