Permalink
Browse files

add resources to the API for deploy

  • Loading branch information...
1 parent 2ff0a55 commit 2910afceacca26dc1d880cedaa5d7560b249ebbe @natefinch natefinch committed Feb 2, 2016
View
@@ -55,50 +55,55 @@ func (c *Client) EnvironmentUUID() string {
return tag.Id()
}
+// ServiceDelpoyArgs holds the arguments to be sent to Client.ServiceDeploy.
+type ServiceDeployArgs struct {
+ CharmURL string
+ ServiceName string
+ Series string
+ NumUnits int
+ ConfigYAML string
+ Cons constraints.Value
+ ToMachineSpec string
+ Placement []*instance.Placement
+ Networks []string
+ Storage map[string]storage.Constraints
+ Resources map[string]string
+}
+
// ServiceDeploy obtains the charm, either locally or from
// the charm store, and deploys it. It allows the specification of
// requested networks that must be present on the machines where the
// service is deployed. Another way to specify networks to include/exclude
// is using constraints. Placement directives, if provided, specify the
// machine on which the charm is deployed.
-func (c *Client) ServiceDeploy(
- charmURL string,
- serviceName string,
- series string,
- numUnits int,
- configYAML string,
- cons constraints.Value,
- toMachineSpec string,
- placement []*instance.Placement,
- networks []string,
- storage map[string]storage.Constraints,
-) error {
- args := params.ServicesDeploy{
+func (c *Client) ServiceDeploy(args ServiceDeployArgs) error {
+ apiArgs := params.ServicesDeploy{
Services: []params.ServiceDeploy{{
- ServiceName: serviceName,
- Series: series,
- CharmUrl: charmURL,
- NumUnits: numUnits,
- ConfigYAML: configYAML,
- Constraints: cons,
- ToMachineSpec: toMachineSpec,
- Placement: placement,
- Networks: networks,
- Storage: storage,
+ ServiceName: args.ServiceName,
+ Series: args.Series,
+ CharmUrl: args.CharmURL,
+ NumUnits: args.NumUnits,
+ ConfigYAML: args.ConfigYAML,
+ Constraints: args.Cons,
+ ToMachineSpec: args.ToMachineSpec,
+ Placement: args.Placement,
+ Networks: args.Networks,
+ Storage: args.Storage,
+ Resources: args.Resources,
}},
}
var results params.ErrorResults
var err error
- if len(placement) > 0 {
- err = c.FacadeCall("ServicesDeployWithPlacement", args, &results)
+ if len(args.Placement) > 0 {
+ err = c.FacadeCall("ServicesDeployWithPlacement", apiArgs, &results)
if err != nil {
if params.IsCodeNotImplemented(err) {
- return errors.Errorf("unsupported --to parameter %q", toMachineSpec)
+ return errors.Errorf("unsupported --to parameter %q", args.ToMachineSpec)
}
return err
}
} else {
- err = c.FacadeCall("ServicesDeploy", args, &results)
+ err = c.FacadeCall("ServicesDeploy", apiArgs, &results)
}
if err != nil {
return err
View
@@ -91,13 +91,27 @@ func (s *serviceSuite) TestSetServiceDeploy(c *gc.C) {
c.Assert(args.Services[0].ToMachineSpec, gc.Equals, "machineSpec")
c.Assert(args.Services[0].Networks, gc.DeepEquals, []string{"neta"})
c.Assert(args.Services[0].Storage, gc.DeepEquals, map[string]storage.Constraints{"data": storage.Constraints{Pool: "pool"}})
+ c.Assert(args.Services[0].Resources, gc.DeepEquals, map[string]string{"foo": "bar"})
result := response.(*params.ErrorResults)
result.Results = make([]params.ErrorResult, 1)
return nil
})
- err := s.client.ServiceDeploy("charmURL", "serviceA", "series", 2, "configYAML", constraints.MustParse("mem=4G"),
- "machineSpec", nil, []string{"neta"}, map[string]storage.Constraints{"data": storage.Constraints{Pool: "pool"}})
+
+ args := service.ServiceDeployArgs{
+ CharmURL: "charmURL",
+ ServiceName: "serviceA",
+ Series: "series",
+ NumUnits: 2,
+ ConfigYAML: "configYAML",
+ Cons: constraints.MustParse("mem=4G"),
+ ToMachineSpec: "machineSpec",
+ Placement: nil,
+ Networks: []string{"neta"},
+ Storage: map[string]storage.Constraints{"data": storage.Constraints{Pool: "pool"}},
+ Resources: map[string]string{"foo": "bar"},
+ }
+ err := s.client.ServiceDeploy(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, jc.IsTrue)
}
@@ -205,6 +205,7 @@ type ServiceDeploy struct {
Placement []*instance.Placement
Networks []string
Storage map[string]storage.Constraints
+ Resources map[string]string
}
// ServiceUpdate holds the parameters for making the ServiceUpdate call.
@@ -170,6 +170,7 @@ func DeployService(st *state.State, owner string, args params.ServiceDeploy) err
Placement: args.Placement,
Networks: requestedNetworks,
Storage: args.Storage,
+ Resources: args.Resources,
})
return err
}
@@ -224,7 +224,7 @@ func (c *DeployCommand) SetFlags(f *gnuflag.FlagSet) {
f.BoolVar(&c.Force, "force", false, "allow a charm to be deployed to a machine running an unsupported series")
f.Var(storageFlag{&c.Storage, &c.BundleStorage}, "storage", "charm storage constraints")
f.Var(stringMap{&c.Resources}, "resources", "resources to be uploaded to the controller")
-
+
for _, step := range c.Steps {
step.SetFlags(f)
}
@@ -510,7 +510,12 @@ func (c *DeployCommand) deployCharm(
}
}
- if err := deployer.serviceDeploy(serviceDeployParams{
+ resources, err := c.uploadResources()
+ if err != nil {
+ return errors.Trace(err)
+ }
+
+ params := serviceDeployParams{
curl.String(),
serviceName,
series,
@@ -521,7 +526,9 @@ func (c *DeployCommand) deployCharm(
c.Placement,
c.Networks,
c.Storage,
- }); err != nil {
+ resources,
+ }
+ if err := deployer.serviceDeploy(params); err != nil {
return err
}
@@ -544,6 +551,13 @@ func (c *DeployCommand) deployCharm(
return err
}
+// uploadResources uploads the bytes and most metadata for resources, returning
+// a map of resource name to uniqueIds, to be passed along with the
+// ServiceDeploy API command.
+func (c *DeployCommand) uploadResources() (map[string]string, error) {
+ return nil, nil
+}
+
type serviceDeployParams struct {
charmURL string
serviceName string
@@ -555,6 +569,7 @@ type serviceDeployParams struct {
placement []*instance.Placement
networks string
storage map[string]storage.Constraints
+ resources map[string]string
}
type serviceDeployer struct {
@@ -589,7 +604,8 @@ func (c *serviceDeployer) serviceDeploy(args serviceDeployParams) error {
}
args.placement[i] = p
}
- return serviceClient.ServiceDeploy(
+
+ clientArgs := apiservice.ServiceDeployArgs{
args.charmURL,
args.serviceName,
args.series,
@@ -600,7 +616,10 @@ func (c *serviceDeployer) serviceDeploy(args serviceDeployParams) error {
args.placement,
[]string{},
args.storage,
- )
+ args.resources,
+ }
+
+ return serviceClient.ServiceDeploy(clientArgs)
}
func (c *DeployCommand) Run(ctx *cmd.Context) error {
View
@@ -39,6 +39,10 @@ type DeployServiceParams struct {
// TODO(dimitern): Drop this in a follow-up in favor of constraints.
Networks []string
Storage map[string]storage.Constraints
+ // Resources is a map of resource name to unique ID, resources that were
+ // uploaded before the deploy call was made, which should be associated with
+ // this service.
+ Resources map[string]string
}
type ServiceDeployer interface {
@@ -94,6 +98,7 @@ func DeployService(st ServiceDeployer, args DeployServiceParams) (*state.Service
Settings: settings,
NumUnits: args.NumUnits,
Placement: args.Placement,
+ Resources: args.Resources,
}
if !args.Charm.Meta().Subordinate {
View
@@ -101,6 +101,22 @@ func (s *DeployLocalSuite) TestDeploySeries(c *gc.C) {
c.Assert(f.args.Series, gc.Equals, "aseries")
}
+func (s *DeployLocalSuite) TestDeployResources(c *gc.C) {
+ f := &fakeDeployer{State: s.State}
+
+ _, err := juju.DeployService(f,
+ juju.DeployServiceParams{
+ ServiceName: "bob",
+ Charm: s.charm,
+ Resources: map[string]string{"foo": "bar"},
+ })
+ c.Assert(err, jc.ErrorIsNil)
+
+ c.Assert(f.args.Name, gc.Equals, "bob")
+ c.Assert(f.args.Charm, gc.DeepEquals, s.charm)
+ c.Assert(f.args.Resources, gc.DeepEquals, map[string]string{"foo": "bar"})
+}
+
func (s *DeployLocalSuite) TestDeploySettings(c *gc.C) {
service, err := juju.DeployService(s.State,
juju.DeployServiceParams{
View
@@ -1139,6 +1139,7 @@ type AddServiceArgs struct {
NumUnits int
Placement []*instance.Placement
Constraints constraints.Value
+ Resources map[string]string
}
// AddService creates a new service, running the supplied charm, with the

0 comments on commit 2910afc

Please sign in to comment.