Skip to content

Commit

Permalink
Upgrade and configure support folders (vmware#7826)
Browse files Browse the repository at this point in the history
* Upgrade and configure support folders (vmware#7677)

Upgrade will now update the inventory for the VCH by
moving the VCH and containerVMs into a folder with the
same name as the VCH.  This will match the functionality
provided in create.

Upgrade also has a debug flag allowing for more verbose
output from the cli.

Configure will not make any inventory changes.

fixes vmware#7497

* Update 6-04-Create-Basic with correct error message (vmware#7819)

The existing name test was expecting the word 'exists'
in the failure message.  That wording was changed to
'already in use', but the test wasn't updated.

* Properly handle type cast for inventory path setting (vmware#7820)

The upgrade / configure PR (7677) introduced some test
code into master.  Specifically around validation of vic-machine
data.

This change will revert the code to the proper type cast and
set the inventory path as intended.
  • Loading branch information
Anchal Agrawal authored Apr 24, 2018
1 parent 14bb1a9 commit def7889
Show file tree
Hide file tree
Showing 35 changed files with 527 additions and 288 deletions.
2 changes: 1 addition & 1 deletion cmd/vic-machine/common/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r *ResourceLimits) VCHCPULimitFlags(hidden bool) []cli.Flag {
cli.GenericFlag{
Name: "cpu-shares, cpus",
Value: flags.NewSharesFlag(&r.VCHCPUShares),
Usage: "VCH VCH resource pool vCPUs shares, in level or share number, e.g. high, normal, low, or 4000",
Usage: "VCH resource pool vCPUs shares, in level or share number, e.g. high, normal, low, or 4000",
Hidden: hidden,
},
}
Expand Down
41 changes: 19 additions & 22 deletions cmd/vic-machine/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type Configure struct {

certificates common.CertFactory

upgrade bool
executor *management.Dispatcher

Force bool
Expand Down Expand Up @@ -86,12 +85,6 @@ func (c *Configure) Flags() []cli.Flag {
Destination: &c.Rollback,
Hidden: true,
},
cli.BoolFlag{
Name: "upgrade",
Usage: "Upgrade VCH to latest version together with configure",
Destination: &c.upgrade,
Hidden: true,
},
}

dns := c.dns.DNSFlags(false)
Expand Down Expand Up @@ -317,12 +310,6 @@ func (c *Configure) Run(clic *cli.Context) (err error) {
return errors.New("invalid CLI arguments")
}

// TODO: add additional parameter processing, reuse same code with create command as well

if c.upgrade {
// verify upgrade required parameters here
}

op.Infof("### Configuring VCH ####")

validator, err := validate.NewValidator(op, c.Data)
Expand All @@ -337,7 +324,7 @@ func (c *Configure) Run(clic *cli.Context) (err error) {
op.Errorf("Configuring cannot continue - target validation failed: %s", err)
return errors.New("configure failed")
}
executor := management.NewDispatcher(validator.Context, validator.Session, nil, c.Force)
executor := management.NewDispatcher(validator.Context, validator.Session, management.ConfigureAction, c.Force)

var vch *vm.VirtualMachine
if c.Data.ID != "" {
Expand All @@ -364,12 +351,7 @@ func (c *Configure) Run(clic *cli.Context) (err error) {
return nil
}

var vchConfig *config.VirtualContainerHostConfigSpec
if c.upgrade {
vchConfig, err = executor.FetchAndMigrateVCHConfig(vch)
} else {
vchConfig, err = executor.GetVCHConfig(vch)
}
vchConfig, err := executor.GetVCHConfig(vch)
if err != nil {
op.Error("Failed to get Virtual Container Host configuration")
op.Error(err)
Expand Down Expand Up @@ -405,8 +387,19 @@ func (c *Configure) Run(clic *cli.Context) (err error) {
op.Error("Configuring cannot continue: copying configuration failed")
return err
}
// Copy original and merged resources
// This copy is needed so that we validate only the resource settings
// (--mem, --cpu, etc) supplied by the user.
inputResources := c.Data.ResourceLimits
mergedResources := oldData.ResourceLimits

// overwriting user input w/merged dataset
c.Data = oldData

// Set the ResourceLimits to the input received from
// the user
oldData.ResourceLimits = inputResources

// in Create we process certificates as part of processParams but we need the old conf
// to do this in the context of Configure so we need to call this method here instead
if err = c.processCertificates(op, c.Data.ClientNetwork, c.Data.PublicNetwork, c.Data.ManagementNetwork); err != nil {
Expand All @@ -419,6 +412,9 @@ func (c *Configure) Run(clic *cli.Context) (err error) {
op.Error("Configuring cannot continue: configuration validation failed")
return err
}
// The user supplied resource information has been validated, so
// switch back to the merged results
c.Data.ResourceLimits = mergedResources

// TODO: copy changed configuration here. https://github.com/vmware/vic/issues/2911
c.copyChangedConf(vchConfig, newConfig)
Expand Down Expand Up @@ -453,9 +449,10 @@ func (c *Configure) Run(clic *cli.Context) (err error) {
}()

if !c.Data.Rollback {
err = executor.Configure(vch, vchConfig, vConfig, true)
err = executor.Configure(vchConfig, vConfig)
} else {
err = executor.Rollback(vch, vchConfig, vConfig)
executor.Action = management.RollbackAction
err = executor.Rollback(vchConfig, vConfig)
}

if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/vic-machine/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,8 @@ func (c *Create) Run(clic *cli.Context) (err error) {
// separate initial validation from dispatch of creation task
op.Info("")

executor := management.NewDispatcher(op, validator.Session, vchConfig, c.Force)
executor := management.NewDispatcher(op, validator.Session, management.CreateAction, c.Force)
executor.InitDiagnosticLogsFromConf(vchConfig)
if err = executor.CreateVCH(vchConfig, vConfig, datastoreLog); err != nil {
executor.CollectDiagnosticLogs()
op.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/vic-machine/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (d *Debug) Run(clic *cli.Context) (err error) {
return errors.New("debug failed")
}

executor := management.NewDispatcher(validator.Context, validator.Session, nil, d.Force)
executor := management.NewDispatcher(validator.Context, validator.Session, management.DebugAction, d.Force)

var vch *vm.VirtualMachine
if d.Data.ID != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/vic-machine/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (d *Uninstall) Run(clic *cli.Context) (err error) {
return errors.New("delete failed")
}

executor := management.NewDispatcher(validator.Context, validator.Session, nil, d.Force)
executor := management.NewDispatcher(validator.Context, validator.Session, management.DeleteAction, d.Force)

var vch *vm.VirtualMachine
if d.Data.ID != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/vic-machine/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (i *Inspect) run(clic *cli.Context, op trace.Operation, cmd command) (err e
return errors.New("inspect failed")
}

executor := management.NewDispatcher(validator.Context, validator.Session, nil, i.Force)
executor := management.NewDispatcher(validator.Context, validator.Session, management.InspectAction, i.Force)

var vch *vm.VirtualMachine
if i.Data.ID != "" {
Expand Down
5 changes: 3 additions & 2 deletions cmd/vic-machine/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ func (l *List) Run(clic *cli.Context) (err error) {
op.Errorf("List cannot continue - compute resource validation failed: %s", err)
return errors.New("list failed")
}
executor := management.NewDispatcher(validator.Context, validator.Session, nil, false)
vchs, err := executor.SearchVCHs(validator.Session.ClusterPath)

executor := management.NewDispatcher(validator.Context, validator.Session, management.ListAction, false)
vchs, err := executor.SearchVCHs(validator.ClusterPath)
if err != nil {
op.Errorf("List cannot continue - failed to search VCHs in %s: %s", validator.ResourcePoolPath, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/vic-machine/update/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (i *UpdateFw) Run(clic *cli.Context) (err error) {
return errors.New("update firewall failed")
}

executor := management.NewDispatcher(validator.Context, validator.Session, nil, false)
executor := management.NewDispatcher(validator.Context, validator.Session, management.UpdateAction, false)

if i.enableFw {
op.Info("")
Expand Down
10 changes: 6 additions & 4 deletions cmd/vic-machine/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (u *Upgrade) Flags() []cli.Flag {
id := u.IDFlags()
compute := u.ComputeFlags()
iso := u.ImageFlags(false)
debug := u.DebugFlags(true)
debug := u.DebugFlags(false)

// flag arrays are declared, now combined
var flags []cli.Flag
Expand Down Expand Up @@ -134,7 +134,8 @@ func (u *Upgrade) Run(clic *cli.Context) (err error) {
op.Errorf("Upgrade cannot continue - target validation failed: %s", err)
return errors.New("upgrade failed")
}
executor := management.NewDispatcher(validator.Context, validator.Session, nil, u.Force)

executor := management.NewDispatcher(validator.Context, validator.Session, management.UpgradeAction, u.Force)

var vch *vm.VirtualMachine
if u.Data.ID != "" {
Expand Down Expand Up @@ -214,9 +215,10 @@ func (u *Upgrade) Run(clic *cli.Context) (err error) {
}

if !u.Data.Rollback {
err = executor.Configure(vch, vchConfig, vConfig, false)
err = executor.Configure(vchConfig, vConfig)
} else {
err = executor.Rollback(vch, vchConfig, vConfig)
executor.Action = management.RollbackAction
err = executor.Rollback(vchConfig, vConfig)
}

if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/vicadmin/vicadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ func listVMPaths(ctx context.Context, s *session.Session) ([]logfile, error) {

ref := vchConfig.ComputeResources[0]
rp := compute.NewResourcePool(ctx, s, ref)
if children, err = rp.GetChildrenVMs(ctx, s); err != nil {
op := trace.NewOperation(ctx, "GetChildren")
if children, err = rp.GetChildrenVMs(op); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion lib/apiservers/service/restapi/handlers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func upgradeStatusMessage(op trace.Operation, vch *vm.VirtualMachine, installerV
}

func getVCHConfig(op trace.Operation, d *data.Data, validator *validate.Validator) (*config.VirtualContainerHostConfigSpec, error) {
executor := management.NewDispatcher(validator.Context, validator.Session, nil, false)
executor := management.NewDispatcher(validator.Context, validator.Session, management.NoAction, false)
vch, err := executor.NewVCHFromID(d.ID)
if err != nil {
return nil, util.NewError(http.StatusNotFound, fmt.Sprintf("Unable to find VCH %s: %s", d.ID, err))
Expand Down
2 changes: 1 addition & 1 deletion lib/apiservers/service/restapi/handlers/vch_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func handleCreate(op trace.Operation, c *create.Create, validator *validate.Vali
vConfig.HTTPProxy = c.HTTPProxy
vConfig.HTTPSProxy = c.HTTPSProxy

executor := management.NewDispatcher(op, validator.Session, nil, false)
executor := management.NewDispatcher(op, validator.Session, management.CreateAction, false)
err = executor.CreateVCH(vchConfig, vConfig, receiver)
if err != nil {
return nil, util.NewError(http.StatusInternalServerError, fmt.Sprintf("Failed to create VCH: %s", err))
Expand Down
2 changes: 1 addition & 1 deletion lib/apiservers/service/restapi/handlers/vch_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (h *VCHDatacenterDelete) Handle(params operations.DeleteTargetTargetDatacen
}

func deleteVCH(op trace.Operation, d *data.Data, validator *validate.Validator, specification *models.DeletionSpecification) error {
executor := management.NewDispatcher(validator.Context, validator.Session, nil, false)
executor := management.NewDispatcher(validator.Context, validator.Session, management.DeleteAction, false)
vch, err := executor.NewVCHFromID(d.ID)
if err != nil {
return util.NewError(http.StatusNotFound, fmt.Sprintf("Failed to find VCH: %s", err))
Expand Down
2 changes: 1 addition & 1 deletion lib/apiservers/service/restapi/handlers/vch_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (h *VCHDatacenterGet) Handle(params operations.GetTargetTargetDatacenterDat
}

func getVCH(op trace.Operation, d *data.Data, validator *validate.Validator) (*models.VCH, error) {
executor := management.NewDispatcher(validator.Context, validator.Session, nil, false)
executor := management.NewDispatcher(validator.Context, validator.Session, management.NoAction, false)
vch, err := executor.NewVCHFromID(d.ID)
if err != nil {
return nil, util.NewError(http.StatusNotFound, fmt.Sprintf("Failed to inspect VCH: %s", err))
Expand Down
5 changes: 3 additions & 2 deletions lib/apiservers/service/restapi/handlers/vch_list_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ func (h *VCHDatacenterListGet) Handle(params operations.GetTargetTargetDatacente
}

func listVCHs(op trace.Operation, d *data.Data, validator *validate.Validator) ([]*models.VCHListItem, error) {
executor := management.NewDispatcher(validator.Context, validator.Session, nil, false)
vchs, err := executor.SearchVCHs(validator.Session.ClusterPath)

executor := management.NewDispatcher(validator.Context, validator.Session, management.NoAction, false)
vchs, err := executor.SearchVCHs(validator.ClusterPath)
if err != nil {
return nil, util.NewError(http.StatusInternalServerError, fmt.Sprintf("Failed to search VCHs in %s: %s", validator.ResourcePoolPath, err))
}
Expand Down
2 changes: 1 addition & 1 deletion lib/apiservers/service/restapi/handlers/vch_log_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (h *VCHDatacenterLogGet) Handle(params operations.GetTargetTargetDatacenter

// getDatastoreHelper validates the VCH and returns the datastore helper for the VCH. It errors when validation fails or when datastore is not ready
func getDatastoreHelper(op trace.Operation, d *data.Data, validator *validate.Validator) (*datastore.Helper, error) {
executor := management.NewDispatcher(validator.Context, validator.Session, nil, false)
executor := management.NewDispatcher(validator.Context, validator.Session, management.NoAction, false)
vch, err := executor.NewVCHFromID(d.ID)
if err != nil {
return nil, util.NewError(http.StatusNotFound, fmt.Sprintf("Unable to find VCH %s: %s", d.ID, err))
Expand Down
33 changes: 16 additions & 17 deletions lib/install/management/appliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (d *Dispatcher) checkExistence(conf *config.VirtualContainerHostConfigSpec,
}

rp := compute.NewResourcePool(d.op, d.session, orp.Reference())
vm, err := rp.GetChildVM(d.op, d.session, conf.Name)
vm, err := rp.GetChildVM(d.op, conf.Name)
if err != nil {
return err
}
Expand Down Expand Up @@ -168,7 +168,7 @@ func (d *Dispatcher) deleteVM(vm *vm.VirtualMachine, force bool) error {
}

// get the actual folder name before we delete it
folder, err := vm.FolderName(d.op)
folder, err := vm.DatastoreFolderName(d.op)
if err != nil {
// failed to get folder name, might not be able to remove files for this VM
name, _ := vm.ObjectName(d.op)
Expand Down Expand Up @@ -501,19 +501,17 @@ func (d *Dispatcher) createAppliance(conf *config.VirtualContainerHostConfigSpec

// Create the VCH inventory folder
if d.isVC {
folderPath := fmt.Sprintf("%s", path.Join(d.session.VMFolder.InventoryPath, conf.Name))

d.op.Info("Creating the VCH folder")
// update the session pointer with the VCH Folder
d.session.VCHFolder, err = d.session.VMFolder.CreateFolder(d.op, spec.Name)
if err != nil {
if soap.IsSoapFault(err) {
switch soap.ToSoapFault(err).VimFault().(type) {
case types.DuplicateName:
return fmt.Errorf("Unable to create the VCH due to an existing object with the same name %s", conf.Name)
return fmt.Errorf("The specified VCH name (%s) is already in use", conf.Name)
}
}
return fmt.Errorf("Unable to create the VCH Folder(%s): %s", folderPath, err)
return fmt.Errorf("Unable to create the VCH Folder(%s): %s", conf.Name, err)
}
}

Expand Down Expand Up @@ -551,7 +549,7 @@ func (d *Dispatcher) createAppliance(conf *config.VirtualContainerHostConfigSpec
vm2.DisableDestroy(d.op)

// update the displayname to the actual folder name used
if d.vmPathName, err = vm2.FolderName(d.op); err != nil {
if d.vmPathName, err = vm2.DatastoreFolderName(d.op); err != nil {
d.op.Errorf("Failed to get canonical name for appliance: %s", err)
return err
}
Expand Down Expand Up @@ -704,7 +702,7 @@ func (d *Dispatcher) decryptVCHConfig(vm *vm.VirtualMachine, cfg map[string]stri
err = errors.Errorf("Failure finding image store from VCH VM %q: %s", name, err)
return nil, err
}
path, err := vm.FolderName(d.op)
path, err := vm.DatastoreFolderName(d.op)
if err != nil {
err = errors.Errorf("Failed to get VM %q datastore path: %s", name, err)
return nil, err
Expand Down Expand Up @@ -1200,27 +1198,28 @@ func (d *Dispatcher) CheckServiceReady(ctx context.Context, conf *config.Virtual
return nil
}

// deleteVCHFolder deletes an empty VCH folder. During a VCH Delete there is a slight possibility vic
// deleteFolder deletes the supplied folder if it is empty. During a VCH Delete there is a slight possibility vic
// could delete a folder it didn't create. The only time a VCH would be in a folder vic didn't create
// would be outside of normal vic operations. There is no risk of loss of data as it will this will only
// delete an empty folder.
func (d *Dispatcher) deleteVCHFolder() {
// only continue if VC and the VCH Folder is NOT the datacenter wide VM Folder
if d.isVC && d.session.VCHFolder != nil && d.session.VCHFolder.Reference() != d.session.VMFolder.Reference() {
children, err := d.session.VCHFolder.Children(d.op)
func (d *Dispatcher) deleteFolder(folder *object.Folder) {
// only continue if VC and the target Folder is NOT the datacenter wide VM Folder
if d.isVC && folder != nil && folder.Reference() != d.session.VMFolder.Reference() {
children, err := folder.Children(d.op)
if err != nil {
d.op.Errorf("Unable to retrieve VCH Folder(%s) contents: %s", d.session.VCHFolder.InventoryPath, err)
d.op.Errorf("Unable to retrieve Folder(%s) contents: %s", folder.InventoryPath, err)
return
}
if len(children) > 0 {
d.op.Warnf("VCH Folder(%s) contains %d object(s) and will not be removed", d.session.VCHFolder.InventoryPath, len(children))
d.op.Warnf("Folder(%s) is not empty and will not be removed", folder.InventoryPath)
return
}
d.op.Debugf("Destroying folder %s", folder.Name())
_, err = tasks.WaitForResult(d.op, func(ctx context.Context) (tasks.Task, error) {
return d.session.VCHFolder.Destroy(d.op)
return folder.Destroy(d.op)
})
if err != nil {
d.op.Errorf("Failed to remove VCH Folder(%s) - manual removal may be needed: %s", d.session.VCHFolder.InventoryPath, err)
d.op.Errorf("Failed to remove Folder(%s) - manual removal may be needed: %s", folder.InventoryPath, err)
}
}
}
Loading

0 comments on commit def7889

Please sign in to comment.