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 %s: %w", filter, err)
16 for _, o := range objects {
19 return nil, fmt.Errorf("get hosts filter %s: %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)
58 // Services returns a slice of Service matching the filter expression filter.
59 // If no services match, error wraps ErrNoMatch.
60 // To fetch all service, set filter to the empty string ("").
61 func (c *Client) Services(filter string) ([]Service, error) {
62 objects, err := c.filterObjects("/objects/services", filter)
64 return nil, fmt.Errorf("get services filter %s: %w", filter, err)
66 var services []Service
67 for _, o := range objects {
70 return nil, fmt.Errorf("get services filter %s: %T in response", filter, v)
72 services = append(services, v)
77 // LookupService returns the Service identified by name. If no Service is found, error
79 func (c *Client) LookupService(name string) (Service, error) {
80 obj, err := c.lookupObject("/objects/services/" + name)
82 return Service{}, fmt.Errorf("lookup service %s: %w", name, err)
84 v, ok := obj.(Service)
86 return Service{}, fmt.Errorf("lookup service %s: result type %T is not Service", name, v)
91 // CreateService creates service. Some fields of service must be set for successful
92 // creation; see the type definition of Service for details.
93 func (c *Client) CreateService(service Service) error {
94 if err := c.createObject(service); err != nil {
95 return fmt.Errorf("create service %s: %w", service.Name, err)
100 // DeleteService deletes the Service identified by name. If cascade is true, objects
101 // depending on the Service are also deleted. If no Service is found, error wraps
103 func (c *Client) DeleteService(name string, cascade bool) error {
104 if err := c.deleteObject("/objects/services/"+name, cascade); err != nil {
105 return fmt.Errorf("delete service %s: %w", name, err)
109 // Users returns a slice of User matching the filter expression filter.
110 // If no users match, error wraps ErrNoMatch.
111 // To fetch all user, set filter to the empty string ("").
112 func (c *Client) Users(filter string) ([]User, error) {
113 objects, err := c.filterObjects("/objects/users", filter)
115 return nil, fmt.Errorf("get users filter %s: %w", filter, err)
118 for _, o := range objects {
121 return nil, fmt.Errorf("get users filter %s: %T in response", filter, v)
123 users = append(users, v)
128 // LookupUser returns the User identified by name. If no User is found, error
129 // wraps ErrNotExist.
130 func (c *Client) LookupUser(name string) (User, error) {
131 obj, err := c.lookupObject("/objects/users/" + name)
133 return User{}, fmt.Errorf("lookup user %s: %w", name, err)
137 return User{}, fmt.Errorf("lookup user %s: result type %T is not User", name, v)
142 // CreateUser creates user. Some fields of user must be set for successful
143 // creation; see the type definition of User for details.
144 func (c *Client) CreateUser(user User) error {
145 if err := c.createObject(user); err != nil {
146 return fmt.Errorf("create user %s: %w", user.Name, err)
151 // DeleteUser deletes the User identified by name. If cascade is true, objects
152 // depending on the User are also deleted. If no User is found, error wraps
154 func (c *Client) DeleteUser(name string, cascade bool) error {
155 if err := c.deleteObject("/objects/users/"+name, cascade); err != nil {
156 return fmt.Errorf("delete user %s: %w", name, err)
160 // HostGroups returns a slice of HostGroup matching the filter expression filter.
161 // If no hostgroups match, error wraps ErrNoMatch.
162 // To fetch all hostgroup, set filter to the empty string ("").
163 func (c *Client) HostGroups(filter string) ([]HostGroup, error) {
164 objects, err := c.filterObjects("/objects/hostgroups", filter)
166 return nil, fmt.Errorf("get hostgroups filter %s: %w", filter, err)
168 var hostgroups []HostGroup
169 for _, o := range objects {
170 v, ok := o.(HostGroup)
172 return nil, fmt.Errorf("get hostgroups filter %s: %T in response", filter, v)
174 hostgroups = append(hostgroups, v)
176 return hostgroups, nil
179 // LookupHostGroup returns the HostGroup identified by name. If no HostGroup is found, error
180 // wraps ErrNotExist.
181 func (c *Client) LookupHostGroup(name string) (HostGroup, error) {
182 obj, err := c.lookupObject("/objects/hostgroups/" + name)
184 return HostGroup{}, fmt.Errorf("lookup hostgroup %s: %w", name, err)
186 v, ok := obj.(HostGroup)
188 return HostGroup{}, fmt.Errorf("lookup hostgroup %s: result type %T is not HostGroup", name, v)
193 // CreateHostGroup creates hostgroup. Some fields of hostgroup must be set for successful
194 // creation; see the type definition of HostGroup for details.
195 func (c *Client) CreateHostGroup(hostgroup HostGroup) error {
196 if err := c.createObject(hostgroup); err != nil {
197 return fmt.Errorf("create hostgroup %s: %w", hostgroup.Name, err)
202 // DeleteHostGroup deletes the HostGroup identified by name. If cascade is true, objects
203 // depending on the HostGroup are also deleted. If no HostGroup is found, error wraps
205 func (c *Client) DeleteHostGroup(name string, cascade bool) error {
206 if err := c.deleteObject("/objects/hostgroups/"+name, cascade); err != nil {
207 return fmt.Errorf("delete hostgroup %s: %w", name, err)