forked from ContainX/depcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment.go
42 lines (37 loc) · 992 Bytes
/
deployment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package marathon
import (
"errors"
"fmt"
"github.com/gondor/depcon/pkg/httpclient"
)
func (c *MarathonClient) ListDeployments() ([]*Deploy, error) {
var deploys []*Deploy
resp := c.http.HttpGet(c.marathonUrl(API_DEPLOYMENTS), &deploys)
if resp.Error != nil {
return nil, resp.Error
}
return deploys, nil
}
func (c *MarathonClient) HasDeployment(id string) (bool, error) {
deployments, err := c.ListDeployments()
if err != nil {
return false, err
}
for _, deployment := range deployments {
if deployment.DeployID == id {
return true, nil
}
}
return false, nil
}
func (c *MarathonClient) DeleteDeployment(id string) (*DeploymentID, error) {
deploymentID := new(DeploymentID)
resp := c.http.HttpDelete(c.marathonUrl(API_DEPLOYMENTS, id), nil, deploymentID)
if resp.Error != nil {
if resp.Error == httpclient.ErrorNotFound {
return nil, errors.New(fmt.Sprintf("Deployment '%s' was not found", id))
}
return nil, resp.Error
}
return deploymentID, nil
}