1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

support mounts, devices and args for docker plugin set

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2016-11-07 17:15:31 -08:00
parent a2937b2013
commit fc7a265258
3 changed files with 53 additions and 5 deletions

View file

@ -137,6 +137,8 @@ func (p *Plugin) Set(args []string) error {
return err
}
// TODO(vieux): lots of code duplication here, needs to be refactored.
next:
for _, s := range sets {
// range over all the envs in the config
@ -150,12 +152,58 @@ next:
return fmt.Errorf("%q is not settable", s.prettyName())
}
// is it, so lets update the settings in memory
updateConfigEnv(&p.PluginObj.Settings.Env, &s)
updateSettingsEnv(&p.PluginObj.Settings.Env, &s)
continue next
}
}
//TODO: check devices, mount and args
// range over all the mounts in the config
for _, mount := range p.PluginObj.Config.Mounts {
// found the mount in the config
if mount.Name == s.name {
// is it settable ?
if ok, err := s.isSettable(allowedSettableFieldsMounts, mount.Settable); err != nil {
return err
} else if !ok {
return fmt.Errorf("%q is not settable", s.prettyName())
}
// it is, so lets update the settings in memory
*mount.Source = s.value
continue next
}
}
// range over all the devices in the config
for _, device := range p.PluginObj.Config.Devices {
// found the device in the config
if device.Name == s.name {
// is it settable ?
if ok, err := s.isSettable(allowedSettableFieldsDevices, device.Settable); err != nil {
return err
} else if !ok {
return fmt.Errorf("%q is not settable", s.prettyName())
}
// it is, so lets update the settings in memory
*device.Path = s.value
continue next
}
}
// found the name in the config
if p.PluginObj.Config.Args.Name == s.name {
// is it settable ?
if ok, err := s.isSettable(allowedSettableFieldsArgs, p.PluginObj.Config.Args.Settable); err != nil {
return err
} else if !ok {
return fmt.Errorf("%q is not settable", s.prettyName())
}
// it is, so lets update the settings in memory
p.PluginObj.Settings.Args = strings.Split(s.value, " ")
continue next
}
return fmt.Errorf("setting %q not found in the plugin configuration", s.name)
}

View file

@ -90,7 +90,7 @@ func (set *settable) isSettable(allowedSettableFields []string, settable []strin
return false, nil
}
func updateConfigEnv(env *[]string, set *settable) {
func updateSettingsEnv(env *[]string, set *settable) {
for i, e := range *env {
if parts := strings.SplitN(e, "=", 2); parts[0] == set.name {
(*env)[i] = fmt.Sprintf("%s=%s", set.name, set.value)

View file

@ -68,7 +68,7 @@ func TestIsSettable(t *testing.T) {
}
}
func TestUpdateConfigEnv(t *testing.T) {
func TestUpdateSettinsEnv(t *testing.T) {
contexts := []struct {
env []string
set settable
@ -82,7 +82,7 @@ func TestUpdateConfigEnv(t *testing.T) {
}
for _, c := range contexts {
updateConfigEnv(&c.env, &c.set)
updateSettingsEnv(&c.env, &c.set)
if !reflect.DeepEqual(c.env, c.newEnv) {
t.Fatalf("expected env to be %q, got %q", c.newEnv, c.env)