Skip to content

Commit

Permalink
Redo on conflict in rename and name conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
hickeng committed Sep 10, 2017
1 parent 9d146bc commit 28f4251
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
8 changes: 8 additions & 0 deletions cmd/vic-machine/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ func (c *Create) Flags() []cli.Flag {
Destination: &c.ContainerDatastoreName,
Hidden: true,
},
// container naming convention
cli.StringFlag{
Name: "container-name-convention, cnc",
Value: "{name}",
Usage: "Provide a naming convention. Allows the following token '{name}', that will be replaced.",
Destination: &c.ContainerNameConvention,
Hidden: true,
},
}

networks := []cli.Flag{
Expand Down
12 changes: 10 additions & 2 deletions lib/apiservers/engine/backends/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,11 @@ func (c *Container) ContainerRename(oldName, newName string) error {
return derr.NewRequestConflictError(err)
}

if err := c.containerProxy.Rename(vc, newName); err != nil {
renameOp := func() error {
return c.containerProxy.Rename(vc, newName)
}

if err := retry.Do(renameOp, IsConflictError); err != nil {
log.Errorf("Rename error: %s", err)
cache.ContainerCache().ReleaseName(newName)
return err
Expand Down Expand Up @@ -1960,12 +1964,16 @@ func validateCreateConfig(config *types.ContainerCreateConfig) error {
}

// Was a name provided - if not create a friendly name
generatedName := namesgenerator.GetRandomName(0)
if config.Name == "" {
//TODO: Assume we could have a name collison here : need to
// provide validation / retry CDG June 9th 2016
config.Name = namesgenerator.GetRandomName(0)
config.Name = generatedName
}

// apply the naming convention
config.Name = strings.Replace(vchConfig.Cfg.ContainerNameConvention, "{name}", config.Name, -1)

return nil
}

Expand Down
5 changes: 3 additions & 2 deletions lib/config/virtual_container_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ const (
// VM is the VM name - i.e. [ds] {vm}/{vm}.vmx
VM PatternToken = "{vm}"
// ID is the container ID for the VM
ID = "{id}"
ID PatternToken = "{id}"
// Name is the container name of the VM
Name = "{name}"
Name PatternToken = "{name}"

// ID represents the VCH in creating status, which helps to identify VCH VM which still does not have a valid VM moref set
CreatingVCH = "CreatingVCH"

Expand Down
2 changes: 2 additions & 0 deletions lib/install/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ type Data struct {
Rollback bool

SyslogConfig SyslogConfig `cmd:"syslog"`

ContainerNameConvention string `cmd:"container-name-convention"`
}

type SyslogConfig struct {
Expand Down
2 changes: 2 additions & 0 deletions lib/install/validate/config_to_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ func NewDataFromConfig(ctx context.Context, finder Finder, conf *config.VirtualC
return
}
}

d.ContainerNameConvention = conf.ContainerNameConvention
return
}

Expand Down
4 changes: 4 additions & 0 deletions lib/install/validate/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ func (v *Validator) basics(ctx context.Context, input *data.Data, conf *config.V
log.Debugf("Setting scratch image size to %d KB in VCHConfig", conf.ScratchSize)
}

if !strings.Contains(input.ContainerNameConvention, string(config.Name)) {
v.NoteIssue(errors.Errorf("Container name convention must include %s token", config.Name))
}
conf.ContainerNameConvention = input.ContainerNameConvention
}

func (v *Validator) checkSessionSet() []string {
Expand Down

0 comments on commit 28f4251

Please sign in to comment.