1 // Code generated by ./crud.sh -o crud.go; DO NOT EDIT.
10 // Hosts returns a slice of Host matching the filter expression filter.
11 // If no hosts match, error wraps ErrNoMatch.
12 // To fetch all host, set filter to the empty string ("").
13 func (c *Client) Hosts(filter string) ([]Host, error) {
14 objects, err := c.filterObjects("/objects/hosts", filter)
16 return nil, fmt.Errorf("get hosts filter %s: %w", filter, err)
19 for _, o := range objects {
22 return nil, fmt.Errorf("get hosts filter %s: %T in response", filter, v)
24 hosts = append(hosts, v)
29 // LookupHost returns the Host identified by name. If no Host is found, error
31 func (c *Client) LookupHost(name string) (Host, error) {
32 obj, err := c.lookupObject("/objects/hosts/" + url.PathEscape(name))
34 return Host{}, fmt.Errorf("lookup host %s: %w", name, err)
38 return Host{}, fmt.Errorf("lookup host %s: result type %T is not Host", name, v)
43 // CreateHost creates host. Some fields of host must be set for successful
44 // creation; see the type definition of Host for details.
45 func (c *Client) CreateHost(host Host) error {
46 if err := c.createObject(host); err != nil {
47 return fmt.Errorf("create host %s: %w", host.Name, err)
52 // DeleteHost deletes the Host identified by name. If cascade is true, objects
53 // depending on the Host are also deleted. If no Host is found, error wraps
55 func (c *Client) DeleteHost(name string, cascade bool) error {
56 if err := c.deleteObject("/objects/hosts/"+url.PathEscape(name), cascade); err != nil {
57 return fmt.Errorf("delete host %s: %w", name, err)
61 // Services returns a slice of Service matching the filter expression filter.
62 // If no services match, error wraps ErrNoMatch.
63 // To fetch all service, set filter to the empty string ("").
64 func (c *Client) Services(filter string) ([]Service, error) {
65 objects, err := c.filterObjects("/objects/services", filter)
67 return nil, fmt.Errorf("get services filter %s: %w", filter, err)
69 var services []Service
70 for _, o := range objects {
73 return nil, fmt.Errorf("get services filter %s: %T in response", filter, v)
75 services = append(services, v)
80 // LookupService returns the Service identified by name. If no Service is found, error
82 func (c *Client) LookupService(name string) (Service, error) {
83 obj, err := c.lookupObject("/objects/services/" + url.PathEscape(name))
85 return Service{}, fmt.Errorf("lookup service %s: %w", name, err)
87 v, ok := obj.(Service)
89 return Service{}, fmt.Errorf("lookup service %s: result type %T is not Service", name, v)
94 // CreateService creates service. Some fields of service must be set for successful
95 // creation; see the type definition of Service for details.
96 func (c *Client) CreateService(service Service) error {
97 if err := c.createObject(service); err != nil {
98 return fmt.Errorf("create service %s: %w", service.Name, err)
103 // DeleteService deletes the Service identified by name. If cascade is true, objects
104 // depending on the Service are also deleted. If no Service is found, error wraps
106 func (c *Client) DeleteService(name string, cascade bool) error {
107 if err := c.deleteObject("/objects/services/"+url.PathEscape(name), cascade); err != nil {
108 return fmt.Errorf("delete service %s: %w", name, err)
112 // Users returns a slice of User matching the filter expression filter.
113 // If no users match, error wraps ErrNoMatch.
114 // To fetch all user, set filter to the empty string ("").
115 func (c *Client) Users(filter string) ([]User, error) {
116 objects, err := c.filterObjects("/objects/users", filter)
118 return nil, fmt.Errorf("get users filter %s: %w", filter, err)
121 for _, o := range objects {
124 return nil, fmt.Errorf("get users filter %s: %T in response", filter, v)
126 users = append(users, v)
131 // LookupUser returns the User identified by name. If no User is found, error
132 // wraps ErrNotExist.
133 func (c *Client) LookupUser(name string) (User, error) {
134 obj, err := c.lookupObject("/objects/users/" + url.PathEscape(name))
136 return User{}, fmt.Errorf("lookup user %s: %w", name, err)
140 return User{}, fmt.Errorf("lookup user %s: result type %T is not User", name, v)
145 // CreateUser creates user. Some fields of user must be set for successful
146 // creation; see the type definition of User for details.
147 func (c *Client) CreateUser(user User) error {
148 if err := c.createObject(user); err != nil {
149 return fmt.Errorf("create user %s: %w", user.Name, err)
154 // DeleteUser deletes the User identified by name. If cascade is true, objects
155 // depending on the User are also deleted. If no User is found, error wraps
157 func (c *Client) DeleteUser(name string, cascade bool) error {
158 if err := c.deleteObject("/objects/users/"+url.PathEscape(name), cascade); err != nil {
159 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 %s: %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 %s: %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/" + url.PathEscape(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/"+url.PathEscape(name), cascade); err != nil {
210 return fmt.Errorf("delete hostgroup %s: %w", name, err)