-
Notifications
You must be signed in to change notification settings - Fork 933
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kadin Sayani <[email protected]>
- Loading branch information
1 parent
cf8c654
commit 7cbdfa6
Showing
2 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package lxd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/canonical/lxd/shared/api" | ||
) | ||
|
||
// GetServerSites returns all sites. | ||
func (r *ProtocolLXD) GetSites() ([]api.Site, error) { | ||
err := r.CheckExtension("sites") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
sites := []api.Site{} | ||
_, err = r.queryStruct("GET", "/sites/", nil, "", &sites) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return sites, nil | ||
} | ||
|
||
// GetSite returns information about a site. | ||
func (r *ProtocolLXD) GetSite(name string) (*api.Site, string, error) { | ||
err := r.CheckExtension("sites") | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
site := &api.Site{} | ||
etag, err := r.queryStruct("GET", fmt.Sprintf("/sites/%s", name), nil, "", &site) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
return site, etag, nil | ||
} | ||
|
||
// JoinSite requests add a new site. | ||
func (r *ProtocolLXD) JoinSite(site api.SitePost) (Operation, error) { | ||
err := r.CheckExtension("sites") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
op, _, err := r.queryOperation("POST", "/site/join", site, "", true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return op, nil | ||
} | ||
|
||
// UpdateSiteName updates a site's name. | ||
func (r *ProtocolLXD) UpdateSiteName(name string) (Operation, error) { | ||
// TODO: expand function to provide support for updating site addresses. | ||
err := r.CheckExtension("sites") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
op, _, err := r.queryOperation("PUT", fmt.Sprintf("/sites/%s", name), nil, "", true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return op, nil | ||
} | ||
|
||
// DeleteSite deletes a site. | ||
func (r *ProtocolLXD) DeleteSite(name string) (Operation, error) { | ||
err := r.CheckExtension("sites") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
op, _, err := r.queryOperation("DELETE", fmt.Sprintf("/sites/%s", name), nil, "", true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return op, nil | ||
} |