|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|
|
|
package client
|
|
|
|
package client
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
@ -29,6 +30,7 @@ import (
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/ghodss/yaml"
|
|
|
|
"github.com/kubernetes/deployment-manager/pkg/common"
|
|
|
|
"github.com/kubernetes/deployment-manager/pkg/common"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -108,7 +110,7 @@ func (c *Client) agent() string {
|
|
|
|
// CallService is a low-level function for making an API call.
|
|
|
|
// CallService is a low-level function for making an API call.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// This calls the service and then unmarshals the returned data into dest.
|
|
|
|
// This calls the service and then unmarshals the returned data into dest.
|
|
|
|
func (c *Client) CallService(path, method, action string, dest interface{}, reader io.ReadCloser) error {
|
|
|
|
func (c *Client) CallService(path, method, action string, dest interface{}, reader io.Reader) error {
|
|
|
|
u, err := c.url(path)
|
|
|
|
u, err := c.url(path)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -125,7 +127,7 @@ func (c *Client) CallService(path, method, action string, dest interface{}, read
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// callHTTP is a low-level primitive for executing HTTP operations.
|
|
|
|
// callHTTP is a low-level primitive for executing HTTP operations.
|
|
|
|
func (c *Client) callHTTP(path, method, action string, reader io.ReadCloser) (string, error) {
|
|
|
|
func (c *Client) callHTTP(path, method, action string, reader io.Reader) (string, error) {
|
|
|
|
request, err := http.NewRequest(method, path, reader)
|
|
|
|
request, err := http.NewRequest(method, path, reader)
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: dynamically set version
|
|
|
|
// TODO: dynamically set version
|
|
|
@ -280,7 +282,25 @@ func (c *Client) DeleteDeployment(name string) (*common.Deployment, error) {
|
|
|
|
return deployment, nil
|
|
|
|
return deployment, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// PostDeployment posts a deployment objec to the manager service.
|
|
|
|
// PostDeployment posts a deployment object to the manager service.
|
|
|
|
func (c *Client) PostDeployment(cfg *common.Configuration) error {
|
|
|
|
func (c *Client) PostDeployment(name string, cfg *common.Configuration) error {
|
|
|
|
return c.CallService("/deployments", "POST", "post deployment", cfg, nil)
|
|
|
|
d, err := yaml.Marshal(cfg)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a stop-gap until we get this API cleaned up.
|
|
|
|
|
|
|
|
t := common.Template{
|
|
|
|
|
|
|
|
Name: name,
|
|
|
|
|
|
|
|
Content: string(d),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data, err := json.Marshal(t)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var out interface{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b := bytes.NewBuffer(data)
|
|
|
|
|
|
|
|
return c.CallService("/deployments", "POST", "post deployment", &out, b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|