本文整理汇总了Golang中github.com/juju/juju/agent.Config.Tag方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.Tag方法的具体用法?Golang Config.Tag怎么用?Golang Config.Tag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/agent.Config
的用法示例。
在下文中一共展示了Config.Tag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newNetworker
// newNetworker creates a Networker worker with the specified arguments.
func newNetworker(
st *apinetworker.State,
agentConfig agent.Config,
configBasePath string,
canWriteNetworkConfig bool,
) (*Networker, error) {
tag, ok := agentConfig.Tag().(names.MachineTag)
if !ok {
// This should never happen, as there is a check for it in the
// machine agent.
return nil, fmt.Errorf("expected names.MachineTag, got %T", agentConfig.Tag())
}
nw := &Networker{
st: st,
tag: tag,
configBasePath: configBasePath,
canWriteNetworkConfig: canWriteNetworkConfig,
configFiles: make(map[string]*configFile),
networkInfo: make(map[string]network.Info),
interfaces: make(map[string]net.Interface),
}
go func() {
defer nw.tomb.Done()
nw.tomb.Kill(nw.loop())
}()
return nw, nil
}
示例2: NewNetworker
// NewNetworker returns a Worker that handles machine networking
// configuration. If there is no <configBasePath>/interfaces file, an
// error is returned.
func NewNetworker(
st apinetworker.State,
agentConfig agent.Config,
intrusiveMode bool,
configBaseDir string,
) (*Networker, error) {
tag, ok := agentConfig.Tag().(names.MachineTag)
if !ok {
// This should never happen, as there is a check for it in the
// machine agent.
return nil, fmt.Errorf("expected names.MachineTag, got %T", agentConfig.Tag())
}
nw := &Networker{
st: st,
tag: tag,
intrusiveMode: intrusiveMode,
configBaseDir: configBaseDir,
configFiles: make(map[string]*configFile),
interfaceInfo: make(map[string]network.InterfaceInfo),
interfaces: make(map[string]net.Interface),
}
err := catacomb.Invoke(catacomb.Plan{
Site: &nw.catacomb,
Work: nw.loop,
})
if err != nil {
return nil, errors.Trace(err)
}
return nw, nil
}
示例3: openState
func openState(agentConfig agent.Config, dialOpts mongo.DialOpts) (_ *state.State, _ *state.Machine, err error) {
info, ok := agentConfig.MongoInfo()
if !ok {
return nil, nil, fmt.Errorf("no state info available")
}
st, err := state.Open(agentConfig.Model(), info, dialOpts, environs.NewStatePolicy())
if err != nil {
return nil, nil, err
}
defer func() {
if err != nil {
st.Close()
}
}()
m0, err := st.FindEntity(agentConfig.Tag())
if err != nil {
if errors.IsNotFound(err) {
err = worker.ErrTerminateAgent
}
return nil, nil, err
}
m := m0.(*state.Machine)
if m.Life() == state.Dead {
return nil, nil, worker.ErrTerminateAgent
}
// Check the machine nonce as provisioned matches the agent.Conf value.
if !m.CheckProvisioned(agentConfig.Nonce()) {
// The agent is running on a different machine to the one it
// should be according to state. It must stop immediately.
logger.Errorf("running machine %v agent on inappropriate instance", m)
return nil, nil, worker.ErrTerminateAgent
}
return st, m, nil
}
示例4: NewWorker
// NewWorker returns a worker that keeps track of
// the machine's authorised ssh keys and ensures the
// ~/.ssh/authorized_keys file is up to date.
func NewWorker(st *keyupdater.State, agentConfig agent.Config) worker.Worker {
if version.Current.OS == version.Windows {
return worker.NewNoOpWorker()
}
kw := &keyupdaterWorker{st: st, tag: agentConfig.Tag().(names.MachineTag)}
return worker.NewNotifyWorker(kw)
}
示例5: NewWorker
// NewWorker returns a worker that keeps track of
// the machine's authorised ssh keys and ensures the
// ~/.ssh/authorized_keys file is up to date.
func NewWorker(st *keyupdater.State, agentConfig agent.Config) worker.Worker {
if os.HostOS() == os.Windows {
return worker.NewNoOpWorker()
}
kw := &keyupdaterWorker{st: st, tag: agentConfig.Tag().(names.MachineTag)}
return worker.NewNotifyWorker(kw)
}
示例6: waitForUpgradeToFinish
func waitForUpgradeToFinish(c *gc.C, conf agent.Config) {
success := false
for attempt := coretesting.LongAttempt.Start(); attempt.Next(); {
diskConf := readConfigFromDisk(c, conf.DataDir(), conf.Tag())
success = diskConf.UpgradedToVersion() == version.Current
if success {
break
}
}
c.Assert(success, jc.IsTrue)
}
示例7: NewReboot
func NewReboot(st *reboot.State, agentConfig agent.Config, machineLock *fslock.Lock) (worker.Worker, error) {
tag, ok := agentConfig.Tag().(names.MachineTag)
if !ok {
return nil, errors.Errorf("Expected names.MachineTag, got %T: %v", agentConfig.Tag(), agentConfig.Tag())
}
r := &Reboot{
st: st,
tag: tag,
machineLock: machineLock,
}
return worker.NewNotifyWorker(r), nil
}
示例8: NewUpgrader
// NewUpgrader returns a new upgrader worker. It watches changes to the
// current version of the current agent (with the given tag) and tries to
// download the tools for any new version into the given data directory. If
// an upgrade is needed, the worker will exit with an UpgradeReadyError
// holding details of the requested upgrade. The tools will have been
// downloaded and unpacked.
func NewUpgrader(st *upgrader.State, agentConfig agent.Config) *Upgrader {
u := &Upgrader{
st: st,
dataDir: agentConfig.DataDir(),
tag: agentConfig.Tag(),
}
go func() {
defer u.tomb.Done()
u.tomb.Kill(u.loop())
}()
return u
}
示例9: NewNetworker
// NewNetworker returns a Worker that handles machine networking
// configuration. If there is no /etc/network/interfaces file, an
// error is returned.
func NewNetworker(st *apinetworker.State, agentConfig agent.Config) (worker.Worker, error) {
nw := &networker{
st: st,
tag: agentConfig.Tag().String(),
}
// Verify we have /etc/network/interfaces first, otherwise bail out.
if !CanStart() {
err := fmt.Errorf("missing %q config file", configFileName)
logger.Infof("not starting worker: %v", err)
return nil, err
}
return worker.NewNotifyWorker(nw), nil
}
示例10: setupAgentLogging
// setupLogging redirects logging to rolled log files.
//
// NOTE: do not use this in the bootstrap agent, or
// if you do, change the bootstrap error reporting.
func setupAgentLogging(conf agent.Config) error {
filename := filepath.Join(conf.LogDir(), conf.Tag().String()+".log")
log := &lumberjack.Logger{
Filename: filename,
MaxSize: 300, // megabytes
MaxBackups: 2,
}
writer := loggo.NewSimpleWriter(log, &loggo.DefaultFormatter{})
_, err := loggo.ReplaceDefaultWriter(writer)
return err
}
示例11: NewMachineEnvironmentWorker
// NewMachineEnvironmentWorker returns a worker.Worker that uses the notify
// watcher returned from the setup.
func NewMachineEnvironmentWorker(api *environment.Facade, agentConfig agent.Config) worker.Worker {
// We don't write out system files for the local provider on machine zero
// as that is the host machine.
writeSystemFiles := (agentConfig.Tag() != names.NewMachineTag("0").String() ||
agentConfig.Value(agent.ProviderType) != provider.Local)
logger.Debugf("write system files: %v", writeSystemFiles)
envWorker := &MachineEnvironmentWorker{
api: api,
writeSystemFiles: writeSystemFiles,
first: true,
}
return worker.NewNotifyWorker(envWorker)
}
示例12: NewReboot
func NewReboot(st reboot.State, agentConfig agent.Config, machineLock *fslock.Lock) (worker.Worker, error) {
tag, ok := agentConfig.Tag().(names.MachineTag)
if !ok {
return nil, errors.Errorf("Expected names.MachineTag, got %T: %v", agentConfig.Tag(), agentConfig.Tag())
}
r := &Reboot{
st: st,
tag: tag,
machineLock: machineLock,
}
w, err := watcher.NewNotifyWorker(watcher.NotifyConfig{
Handler: r,
})
return w, errors.Trace(err)
}
示例13: updateSupportedContainers
// updateSupportedContainers records in state that a machine can run the specified containers.
// It starts a watcher and when a container of a given type is first added to the machine,
// the watcher is killed, the machine is set up to be able to start containers of the given type,
// and a suitable provisioner is started.
func (a *MachineAgent) updateSupportedContainers(
runner worker.Runner,
st api.Connection,
containers []instance.ContainerType,
agentConfig agent.Config,
) error {
pr := apiprovisioner.NewState(st)
tag := agentConfig.Tag().(names.MachineTag)
machine, err := pr.Machine(tag)
if errors.IsNotFound(err) || err == nil && machine.Life() == params.Dead {
return worker.ErrTerminateAgent
}
if err != nil {
return errors.Annotatef(err, "cannot load machine %s from state", tag)
}
if len(containers) == 0 {
if err := machine.SupportsNoContainers(); err != nil {
return errors.Annotatef(err, "clearing supported containers for %s", tag)
}
return nil
}
if err := machine.SetSupportedContainers(containers...); err != nil {
return errors.Annotatef(err, "setting supported containers for %s", tag)
}
// Start the watcher to fire when a container is first requested on the machine.
watcherName := fmt.Sprintf("%s-container-watcher", machine.Id())
params := provisioner.ContainerSetupParams{
Runner: runner,
WorkerName: watcherName,
SupportedContainers: containers,
Machine: machine,
Provisioner: pr,
Config: agentConfig,
InitLockName: agent.MachineLockName,
}
handler := provisioner.NewContainerSetupHandler(params)
a.startWorkerAfterUpgrade(runner, watcherName, func() (worker.Worker, error) {
w, err := watcher.NewStringsWorker(watcher.StringsConfig{
Handler: handler,
})
if err != nil {
return nil, errors.Annotatef(err, "cannot start %s worker", watcherName)
}
return w, nil
})
return nil
}
示例14: tagUserCredentials
// tagUserCredentials is a convenience function that extracts the
// tag user and apipassword, required to access mongodb.
func tagUserCredentials(conf agent.Config) (string, string, error) {
username := conf.Tag().String()
var password string
// TODO(perrito) we might need an accessor for the actual state password
// just in case it ever changes from the same as api password.
apiInfo, ok := conf.APIInfo()
if ok {
password = apiInfo.Password
} else {
// There seems to be no way to reach this inconsistence other than making a
// backup on a machine where these fields are corrupted and even so I find
// no reasonable way to reach this state, yet since APIInfo has it as a
// possibility I prefer to handle it, we cannot recover from this since
// it would mean that the agent.conf is corrupted.
return "", "", errors.New("cannot obtain password to access the controller")
}
return username, password, nil
}
示例15: NewWorker
// NewWorker returns a worker that keeps track of
// the machine's authorised ssh keys and ensures the
// ~/.ssh/authorized_keys file is up to date.
func NewWorker(st *keyupdater.State, agentConfig agent.Config) (worker.Worker, error) {
machineTag, ok := agentConfig.Tag().(names.MachineTag)
if !ok {
return nil, errors.NotValidf("machine tag %v", agentConfig.Tag())
}
if os.HostOS() == os.Windows {
return worker.NewNoOpWorker(), nil
}
w, err := watcher.NewNotifyWorker(watcher.NotifyConfig{
Handler: &keyupdaterWorker{
st: st,
tag: machineTag,
},
})
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
}