本文整理汇总了Golang中github.com/wallyworld/core/names.MachineTag函数的典型用法代码示例。如果您正苦于以下问题:Golang MachineTag函数的具体用法?Golang MachineTag怎么用?Golang MachineTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MachineTag函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetUpTest
func (s *deployerSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
// The two known machines now contain the following units:
// machine 0 (not authorized): mysql/1 (principal1)
// machine 1 (authorized): mysql/0 (principal0), logging/0 (subordinate0)
var err error
s.machine0, err = s.State.AddMachine("quantal", state.JobManageEnviron, state.JobHostUnits)
c.Assert(err, gc.IsNil)
s.machine1, err = s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
s.service0 = s.AddTestingService(c, "mysql", s.AddTestingCharm(c, "mysql"))
s.service1 = s.AddTestingService(c, "logging", s.AddTestingCharm(c, "logging"))
eps, err := s.State.InferEndpoints([]string{"mysql", "logging"})
c.Assert(err, gc.IsNil)
rel, err := s.State.AddRelation(eps...)
c.Assert(err, gc.IsNil)
s.principal0, err = s.service0.AddUnit()
c.Assert(err, gc.IsNil)
err = s.principal0.AssignToMachine(s.machine1)
c.Assert(err, gc.IsNil)
s.principal1, err = s.service0.AddUnit()
c.Assert(err, gc.IsNil)
err = s.principal1.AssignToMachine(s.machine0)
c.Assert(err, gc.IsNil)
relUnit0, err := rel.Unit(s.principal0)
c.Assert(err, gc.IsNil)
err = relUnit0.EnterScope(nil)
c.Assert(err, gc.IsNil)
s.subordinate0, err = s.service1.Unit("logging/0")
c.Assert(err, gc.IsNil)
// Create a FakeAuthorizer so we can check permissions,
// set up assuming machine 1 has logged in.
s.authorizer = apiservertesting.FakeAuthorizer{
Tag: names.MachineTag(s.machine1.Id()),
LoggedIn: true,
MachineAgent: true,
}
// Create the resource registry separately to track invocations to
// Register.
s.resources = common.NewResources()
// Create a deployer API for machine 1.
deployer, err := deployer.NewDeployerAPI(
s.State,
s.resources,
s.authorizer,
)
c.Assert(err, gc.IsNil)
s.deployer = deployer
}
示例2: primeAgent
// primeAgent adds a new Machine to run the given jobs, and sets up the
// machine agent's directory. It returns the new machine, the
// agent's configuration and the tools currently running.
func (s *commonMachineSuite) primeAgent(
c *gc.C, vers version.Binary,
jobs ...state.MachineJob) (m *state.Machine, config agent.ConfigSetterWriter, tools *tools.Tools) {
// Add a machine and ensure it is provisioned.
m, err := s.State.AddMachine("quantal", jobs...)
c.Assert(err, gc.IsNil)
inst, md := jujutesting.AssertStartInstance(c, s.Conn.Environ, m.Id())
c.Assert(m.SetProvisioned(inst.Id(), state.BootstrapNonce, md), gc.IsNil)
// Add an address for the tests in case the maybeInitiateMongoServer
// codepath is exercised.
s.setFakeMachineAddresses(c, m)
// Set up the new machine.
err = m.SetAgentVersion(vers)
c.Assert(err, gc.IsNil)
err = m.SetPassword(initialMachinePassword)
c.Assert(err, gc.IsNil)
tag := names.MachineTag(m.Id())
if m.IsManager() {
err = m.SetMongoPassword(initialMachinePassword)
c.Assert(err, gc.IsNil)
config, tools = s.agentSuite.primeStateAgent(c, tag, initialMachinePassword, vers)
info, ok := config.StateServingInfo()
c.Assert(ok, jc.IsTrue)
err = s.State.SetStateServingInfo(info)
c.Assert(err, gc.IsNil)
} else {
config, tools = s.agentSuite.primeAgent(c, tag, initialMachinePassword, vers)
}
err = config.Write()
c.Assert(err, gc.IsNil)
return m, config, tools
}
示例3: populateMachineMaps
func (task *provisionerTask) populateMachineMaps(ids []string) error {
task.instances = make(map[instance.Id]instance.Instance)
instances, err := task.broker.AllInstances()
if err != nil {
logger.Errorf("failed to get all instances from broker: %v", err)
return err
}
for _, i := range instances {
task.instances[i.Id()] = i
}
// Update the machines map with new data for each of the machines in the
// change list.
// TODO(thumper): update for API server later to get all machines in one go.
for _, id := range ids {
machineTag := names.MachineTag(id)
machine, err := task.machineGetter.Machine(machineTag)
switch {
case params.IsCodeNotFoundOrCodeUnauthorized(err):
logger.Debugf("machine %q not found in state", id)
delete(task.machines, id)
case err == nil:
task.machines[id] = machine
default:
logger.Errorf("failed to get machine: %v", err)
}
}
return nil
}
示例4: checkCanUpgrade
func (st *State) checkCanUpgrade(currentVersion, newVersion string) error {
matchCurrent := "^" + regexp.QuoteMeta(currentVersion) + "-"
matchNew := "^" + regexp.QuoteMeta(newVersion) + "-"
// Get all machines and units with a different or empty version.
sel := bson.D{{"$or", []bson.D{
{{"tools", bson.D{{"$exists", false}}}},
{{"$and", []bson.D{
{{"tools.version", bson.D{{"$not", bson.RegEx{matchCurrent, ""}}}}},
{{"tools.version", bson.D{{"$not", bson.RegEx{matchNew, ""}}}}},
}}},
}}}
var agentTags []string
for _, collection := range []*mgo.Collection{st.machines, st.units} {
var doc struct {
Id string `bson:"_id"`
}
iter := collection.Find(sel).Select(bson.D{{"_id", 1}}).Iter()
for iter.Next(&doc) {
switch collection.Name {
case "machines":
agentTags = append(agentTags, names.MachineTag(doc.Id))
case "units":
agentTags = append(agentTags, names.UnitTag(doc.Id))
}
}
if err := iter.Err(); err != nil {
return err
}
}
if len(agentTags) > 0 {
return newVersionInconsistentError(version.MustParse(currentVersion), agentTags)
}
return nil
}
示例5: DeployerTag
// DeployerTag returns the tag of the agent responsible for deploying
// the unit. If no such entity can be determined, false is returned.
func (u *Unit) DeployerTag() (string, bool) {
if u.doc.Principal != "" {
return names.UnitTag(u.doc.Principal), true
} else if u.doc.MachineId != "" {
return names.MachineTag(u.doc.MachineId), true
}
return "", false
}
示例6: FakeAPIInfo
// FakeAPIInfo holds information about no state - it will always
// give an error when connected to. The machine id gives the machine id
// of the machine to be started.
func FakeAPIInfo(machineId string) *api.Info {
return &api.Info{
Addrs: []string{"0.1.2.3:1234"},
Tag: names.MachineTag(machineId),
Password: "unimportant",
CACert: testing.CACert,
}
}
示例7: NewProvisionerAPI
// NewProvisionerAPI creates a new server-side ProvisionerAPI facade.
func NewProvisionerAPI(
st *state.State,
resources *common.Resources,
authorizer common.Authorizer,
) (*ProvisionerAPI, error) {
if !authorizer.AuthMachineAgent() && !authorizer.AuthEnvironManager() {
return nil, common.ErrPerm
}
getAuthFunc := func() (common.AuthFunc, error) {
isEnvironManager := authorizer.AuthEnvironManager()
isMachineAgent := authorizer.AuthMachineAgent()
authEntityTag := authorizer.GetAuthTag()
return func(tag string) bool {
if isMachineAgent && tag == authEntityTag {
// A machine agent can always access its own machine.
return true
}
_, id, err := names.ParseTag(tag, names.MachineTagKind)
if err != nil {
return false
}
parentId := state.ParentId(id)
if parentId == "" {
// All top-level machines are accessible by the
// environment manager.
return isEnvironManager
}
// All containers with the authenticated machine as a
// parent are accessible by it.
return isMachineAgent && names.MachineTag(parentId) == authEntityTag
}, nil
}
// Both provisioner types can watch the environment.
getCanWatch := common.AuthAlways(true)
// Only the environment provisioner can read secrets.
getCanReadSecrets := common.AuthAlways(authorizer.AuthEnvironManager())
return &ProvisionerAPI{
Remover: common.NewRemover(st, false, getAuthFunc),
StatusSetter: common.NewStatusSetter(st, getAuthFunc),
DeadEnsurer: common.NewDeadEnsurer(st, getAuthFunc),
PasswordChanger: common.NewPasswordChanger(st, getAuthFunc),
LifeGetter: common.NewLifeGetter(st, getAuthFunc),
StateAddresser: common.NewStateAddresser(st),
APIAddresser: common.NewAPIAddresser(st, resources),
ToolsGetter: common.NewToolsGetter(st, getAuthFunc),
EnvironWatcher: common.NewEnvironWatcher(st, resources, getCanWatch, getCanReadSecrets),
EnvironMachinesWatcher: common.NewEnvironMachinesWatcher(st, resources, getCanReadSecrets),
InstanceIdGetter: common.NewInstanceIdGetter(st, getAuthFunc),
st: st,
resources: resources,
authorizer: authorizer,
getAuthFunc: getAuthFunc,
getCanWatchMachines: getCanReadSecrets,
}, nil
}
示例8: newLxcProvisioner
func (s *lxcProvisionerSuite) newLxcProvisioner(c *gc.C) provisioner.Provisioner {
parentMachineTag := names.MachineTag(s.parentMachineId)
agentConfig := s.AgentConfigForTag(c, parentMachineTag)
tools, err := s.provisioner.Tools(agentConfig.Tag())
c.Assert(err, gc.IsNil)
managerConfig := container.ManagerConfig{container.ConfigName: "juju"}
broker, err := provisioner.NewLxcBroker(s.provisioner, tools, agentConfig, managerConfig)
c.Assert(err, gc.IsNil)
return provisioner.NewContainerProvisioner(instance.LXC, s.provisioner, agentConfig, broker)
}
示例9: 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.MachineTag("0") ||
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)
}
示例10: checkStartInstanceCustom
func (s *CommonProvisionerSuite) checkStartInstanceCustom(c *gc.C, m *state.Machine, secret string, cons constraints.Value, includeNetworks, excludeNetworks []string, networkInfo []network.Info, waitInstanceId bool) (inst instance.Instance) {
s.BackingState.StartSync()
for {
select {
case o := <-s.op:
switch o := o.(type) {
case dummy.OpStartInstance:
inst = o.Instance
if waitInstanceId {
s.waitInstanceId(c, m, inst.Id())
}
// Check the instance was started with the expected params.
c.Assert(o.MachineId, gc.Equals, m.Id())
nonceParts := strings.SplitN(o.MachineNonce, ":", 2)
c.Assert(nonceParts, gc.HasLen, 2)
c.Assert(nonceParts[0], gc.Equals, names.MachineTag("0"))
c.Assert(nonceParts[1], jc.Satisfies, utils.IsValidUUIDString)
c.Assert(o.Secret, gc.Equals, secret)
c.Assert(o.IncludeNetworks, jc.DeepEquals, includeNetworks)
c.Assert(o.ExcludeNetworks, jc.DeepEquals, excludeNetworks)
c.Assert(o.NetworkInfo, jc.DeepEquals, networkInfo)
// All provisioned machines in this test suite have
// their hardware characteristics attributes set to
// the same values as the constraints due to the dummy
// environment being used.
if !constraints.IsEmpty(&cons) {
c.Assert(o.Constraints, gc.DeepEquals, cons)
hc, err := m.HardwareCharacteristics()
c.Assert(err, gc.IsNil)
c.Assert(*hc, gc.DeepEquals, instance.HardwareCharacteristics{
Arch: cons.Arch,
Mem: cons.Mem,
RootDisk: cons.RootDisk,
CpuCores: cons.CpuCores,
CpuPower: cons.CpuPower,
Tags: cons.Tags,
})
}
return
default:
c.Logf("ignoring unexpected operation %#v", o)
}
case <-time.After(2 * time.Second):
c.Fatalf("provisioner did not start an instance")
return
}
}
return
}
示例11: makeMachineConfig
// makeMachineConfig produces a valid cloudinit machine config.
func makeMachineConfig(c *gc.C) *cloudinit.MachineConfig {
machineID := "0"
return &cloudinit.MachineConfig{
MachineId: machineID,
MachineNonce: "gxshasqlnng",
DataDir: environs.DataDir,
LogDir: agent.DefaultLogDir,
Jobs: []params.MachineJob{params.JobManageEnviron, params.JobHostUnits},
CloudInitOutputLog: environs.CloudInitOutputLog,
Tools: &tools.Tools{URL: "file://" + c.MkDir()},
StateInfo: &state.Info{
CACert: testing.CACert,
Addrs: []string{"127.0.0.1:123"},
Tag: names.MachineTag(machineID),
Password: "password",
},
APIInfo: &api.Info{
CACert: testing.CACert,
Addrs: []string{"127.0.0.1:123"},
Tag: names.MachineTag(machineID),
},
MachineAgentServiceName: "jujud-machine-0",
}
}
示例12: Init
func (c *RetryProvisioningCommand) Init(args []string) error {
if err := c.EnsureEnvName(); err != nil {
return err
}
if len(args) == 0 {
return fmt.Errorf("no machine specified")
}
c.Machines = make([]string, len(args))
for i, arg := range args {
if !names.IsMachine(arg) {
return fmt.Errorf("invalid machine %q", arg)
}
c.Machines[i] = names.MachineTag(arg)
}
return nil
}
示例13: CreateContainer
func (manager *containerManager) CreateContainer(
machineConfig *cloudinit.MachineConfig,
series string,
network *container.NetworkConfig) (instance.Instance, *instance.HardwareCharacteristics, error) {
name := names.MachineTag(machineConfig.MachineId)
if manager.name != "" {
name = fmt.Sprintf("%s-%s", manager.name, name)
}
// Note here that the kvmObjectFacotry only returns a valid container
// object, and doesn't actually construct the underlying kvm container on
// disk.
kvmContainer := KvmObjectFactory.New(name)
// Create the cloud-init.
directory, err := container.NewDirectory(name)
if err != nil {
return nil, nil, fmt.Errorf("failed to create container directory: %v", err)
}
logger.Tracef("write cloud-init")
userDataFilename, err := container.WriteUserData(machineConfig, directory)
if err != nil {
return nil, nil, errors.LoggedErrorf(logger, "failed to write user data: %v", err)
}
// Create the container.
startParams := ParseConstraintsToStartParams(machineConfig.Constraints)
startParams.Arch = version.Current.Arch
startParams.Series = series
startParams.Network = network
startParams.UserDataFile = userDataFilename
var hardware instance.HardwareCharacteristics
hardware, err = instance.ParseHardware(
fmt.Sprintf("arch=%s mem=%vM root-disk=%vG cpu-cores=%v",
startParams.Arch, startParams.Memory, startParams.RootDisk, startParams.CpuCores))
if err != nil {
logger.Warningf("failed to parse hardware: %v", err)
}
logger.Tracef("create the container, constraints: %v", machineConfig.Constraints)
if err := kvmContainer.Start(startParams); err != nil {
return nil, nil, errors.LoggedErrorf(logger, "kvm container creation failed: %v", err)
}
logger.Tracef("kvm container created")
return &kvmInstance{kvmContainer, name}, &hardware, nil
}
示例14: MachinesWithTransientErrors
// MachinesWithTransientErrors returns a slice of machines and corresponding status information
// for those machines which have transient provisioning errors.
func (st *State) MachinesWithTransientErrors() ([]*Machine, []params.StatusResult, error) {
var results params.StatusResults
err := st.call("MachinesWithTransientErrors", nil, &results)
if err != nil {
return nil, nil, err
}
machines := make([]*Machine, len(results.Results))
for i, status := range results.Results {
if status.Error != nil {
continue
}
machines[i] = &Machine{
tag: names.MachineTag(status.Id),
life: status.Life,
st: st,
}
}
return machines, results.Results, nil
}
示例15: InitializeState
func InitializeState(c ConfigSetter, envCfg *config.Config, machineCfg BootstrapMachineConfig, timeout state.DialOpts, policy state.Policy) (_ *state.State, _ *state.Machine, resultErr error) {
if c.Tag() != names.MachineTag(BootstrapMachineId) {
return nil, nil, fmt.Errorf("InitializeState not called with bootstrap machine's configuration")
}
servingInfo, ok := c.StateServingInfo()
if !ok {
return nil, nil, fmt.Errorf("state serving information not available")
}
// N.B. no users are set up when we're initializing the state,
// so don't use any tag or password when opening it.
info, ok := c.StateInfo()
if !ok {
return nil, nil, fmt.Errorf("stateinfo not available")
}
info.Tag = ""
info.Password = ""
logger.Debugf("initializing address %v", info.Addrs)
st, err := state.Initialize(info, envCfg, timeout, policy)
if err != nil {
return nil, nil, fmt.Errorf("failed to initialize state: %v", err)
}
logger.Debugf("connected to initial state")
defer func() {
if resultErr != nil {
st.Close()
}
}()
servingInfo.SharedSecret = machineCfg.SharedSecret
c.SetStateServingInfo(servingInfo)
if err = initAPIHostPorts(c, st, machineCfg.Addresses, servingInfo.APIPort); err != nil {
return nil, nil, err
}
if err := st.SetStateServingInfo(servingInfo); err != nil {
return nil, nil, fmt.Errorf("cannot set state serving info: %v", err)
}
m, err := initUsersAndBootstrapMachine(c, st, machineCfg)
if err != nil {
return nil, nil, err
}
return st, m, nil
}