func (b *CmcSetup) Apply() {  
	var interrupt bool
	go func() { <-b.stopChan; interrupt = true }()
	var resources []string
	setupActionSuccess := true
	if len(b.resources) > 0 {
		resources = b.resources
	} else {
		resources = b.setup.ResourcesSetup()
	}
	b.vendor = b.chassis.Vendor()
	b.model, _ = b.chassis.Model()
	b.serial, _ = b.chassis.Serial()
	b.ip = b.asset.IPAddress
	var failed, success []string
	b.log.WithFields(logrus.Fields{
		"Vendor":    b.vendor,
		"Model":     b.model,
		"Serial":    b.serial,
		"IPAddress": b.ip,
		"To apply":  strings.Join(resources, ", "),
	}).Trace("Configuration resources to be applied.")
	for _, resource := range resources {
		var err error
		if interrupt == true {
			b.log.WithFields(logrus.Fields{
				"Vendor":    b.vendor,
				"Model":     b.model,
				"Serial":    b.serial,
				"IPAddress": b.ip,
			}).Debug("Received interrupt.")
			break
		}
		err = b.ensurePoweredUp()
		if err != nil {
			b.log.WithFields(logrus.Fields{
				"resource":  resource,
				"Vendor":    b.vendor,
				"Model":     b.model,
				"Serial":    b.serial,
				"IPAddress": b.ip,
				"Error":     err,
			}).Warn("Chassis power status")
			return
		}
		b.log.WithFields(logrus.Fields{
			"resource":  resource,
			"Vendor":    b.vendor,
			"Model":     b.model,
			"Serial":    b.serial,
			"IPAddress": b.ip,
		}).Debug("Chassis is powered on, continuing setup.")
		switch resource {
		case "setipmioverlan":
			if b.config.IpmiOverLan != nil {
				err = b.setIpmiOverLan()
			}
		case "flexaddress":
			if b.config.FlexAddress != nil {
				err = b.setFlexAddressState()
			}
		case "dynamicpower":
			if b.config.DynamicPower != nil {
				err = b.setDynamicPower()
			}
		case "bladespower":
			if b.config.BladesPower != nil {
				err = b.setBladesPower()
			}
		case "add_blade_bmc_admins":
			if len(b.config.AddBladeBmcAdmins) > 0 {
				err = b.addBladeBmcAdmins()
			}
		case "remove_blade_bmc_users":
			if len(b.config.RemoveBladeBmcUsers) > 0 {
				err = b.removeBladeBmcUsers()
			}
		default:
			b.log.WithFields(logrus.Fields{
				"resource": resource,
			}).Warn("Unknown setup resource.")
		}
		if err != nil {
			setupActionSuccess = false
			failed = append(failed, resource)
			b.log.WithFields(logrus.Fields{
				"resource":  resource,
				"Vendor":    b.vendor,
				"Model":     b.model,
				"Serial":    b.serial,
				"IPAddress": b.ip,
				"Error":     err,
			}).Warn("Setup resource returned errors.")
		} else {
			success = append(success, resource)
		}
		b.log.WithFields(logrus.Fields{
			"resource":  resource,
			"Vendor":    b.vendor,
			"Model":     b.model,
			"Serial":    b.serial,
			"IPAddress": b.ip,
		}).Trace("Resource configuration applied.")
	}
	if setupActionSuccess {
		b.Post()
	}
	b.log.WithFields(logrus.Fields{
		"Vendor":       b.vendor,
		"Model":        b.model,
		"Serial":       b.serial,
		"IPAddress":    b.ip,
		"applied":      strings.Join(success, ", "),
		"unsuccessful": strings.Join(failed, ", "),
	}).Info("Chassis setup actions done.")
}
Apply applies one time setup configuration.
package configure
import (
	"errors"
	"fmt"
	"strings"
	"time"
	"github.com/bmc-toolbox/bmcbutler/pkg/asset"
	"github.com/bmc-toolbox/bmcbutler/pkg/config"
	"github.com/bmc-toolbox/bmcbutler/pkg/inventory"
	"github.com/bmc-toolbox/bmclib/cfgresources"
	"github.com/bmc-toolbox/bmclib/devices"
	"github.com/sirupsen/logrus"
)
type CmcSetup struct {
	asset        *asset.Asset
	chassis      devices.Cmc
	setup        devices.CmcSetup
	config       *cfgresources.SetupChassis
	resources    []string
	butlerConfig *config.Params
	log          *logrus.Logger
	ip           string
	serial       string
	vendor       string
	model        string
	stopChan     <-chan struct{}
}
func NewCmcSetup(
	chassis devices.Cmc,
	asset *asset.Asset,
	resources []string,
	config *cfgresources.SetupChassis,
	butlerConfig *config.Params,
	stopChan <-chan struct{},
	logger *logrus.Logger) *CmcSetup {
	return &CmcSetup{
		asset: asset,
		chassis: chassis,
		setup:        chassis.(devices.CmcSetup),
		butlerConfig: butlerConfig,
		resources: resources,
		config:    config,
		log:       logger,
		stopChan:  stopChan,
	}
}