本文整理汇总了Golang中github.com/wallyworld/core/names.MachineTag函数的典型用法代码示例。如果您正苦于以下问题:Golang MachineTag函数的具体用法?Golang MachineTag怎么用?Golang MachineTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MachineTag函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:jameinel,项目名称:core,代码行数:60,代码来源:deployer_test.go
示例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
}
开发者ID:jameinel,项目名称:core,代码行数:38,代码来源:machine_test.go
示例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
}
开发者ID:jameinel,项目名称:core,代码行数:30,代码来源:provisioner_task.go
示例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
}
开发者ID:jameinel,项目名称:core,代码行数:34,代码来源:state.go
示例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
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:unit.go
示例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,
}
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:instance.go
示例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
}
开发者ID:jameinel,项目名称:core,代码行数:57,代码来源:provisioner.go
示例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)
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:lxc-broker_test.go
示例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)
}
开发者ID:jameinel,项目名称:core,代码行数:15,代码来源:machineenvironmentworker.go
示例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
}
开发者ID:jameinel,项目名称:core,代码行数:51,代码来源:provisioner_test.go
示例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",
}
}
开发者ID:jameinel,项目名称:core,代码行数:25,代码来源:customdata_test.go
示例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
}
开发者ID:jameinel,项目名称:core,代码行数:16,代码来源:retryprovisioning.go
示例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
}
开发者ID:jameinel,项目名称:core,代码行数:46,代码来源:kvm.go
示例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
}
开发者ID:jameinel,项目名称:core,代码行数:21,代码来源:provisioner.go
示例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
}
开发者ID:jameinel,项目名称:core,代码行数:42,代码来源:bootstrap.go
示例16: NewMachineConfig
// NewMachineConfig sets up a basic machine configuration, for a non-bootstrap
// node. You'll still need to supply more information, but this takes care of
// the fixed entries and the ones that are always needed.
func NewMachineConfig(machineID, machineNonce string, includeNetworks, excludeNetworks []string,
stateInfo *state.Info, apiInfo *api.Info) *cloudinit.MachineConfig {
mcfg := &cloudinit.MachineConfig{
// Fixed entries.
DataDir: DataDir,
LogDir: agent.DefaultLogDir,
Jobs: []params.MachineJob{params.JobHostUnits},
CloudInitOutputLog: CloudInitOutputLog,
MachineAgentServiceName: "jujud-" + names.MachineTag(machineID),
// Parameter entries.
MachineId: machineID,
MachineNonce: machineNonce,
IncludeNetworks: includeNetworks,
ExcludeNetworks: excludeNetworks,
StateInfo: stateInfo,
APIInfo: apiInfo,
}
return mcfg
}
开发者ID:jameinel,项目名称:core,代码行数:23,代码来源:cloudinit.go
示例17: GetAssignedMachine
// GetAssignedMachine returns the assigned machine tag (if any) for
// each given unit.
func (f *FirewallerAPI) GetAssignedMachine(args params.Entities) (params.StringResults, error) {
result := params.StringResults{
Results: make([]params.StringResult, len(args.Entities)),
}
canAccess, err := f.accessUnit()
if err != nil {
return params.StringResults{}, err
}
for i, entity := range args.Entities {
var unit *state.Unit
unit, err = f.getUnit(canAccess, entity.Tag)
if err == nil {
var machineId string
machineId, err = unit.AssignedMachineId()
if err == nil {
result.Results[i].Result = names.MachineTag(machineId)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
开发者ID:jameinel,项目名称:core,代码行数:24,代码来源:firewaller.go
示例18: TestCloudInit
// TestCloudInit checks that the output from the various tests
// in cloudinitTests is well formed.
func (*cloudinitSuite) TestCloudInit(c *gc.C) {
for i, test := range cloudinitTests {
c.Logf("test %d", i)
if test.setEnvConfig {
test.cfg.Config = minimalConfig(c)
}
ci := coreCloudinit.New()
err := cloudinit.Configure(&test.cfg, ci)
c.Assert(err, gc.IsNil)
c.Check(ci, gc.NotNil)
// render the cloudinit config to bytes, and then
// back to a map so we can introspect it without
// worrying about internal details of the cloudinit
// package.
data, err := ci.Render()
c.Assert(err, gc.IsNil)
x := make(map[interface{}]interface{})
err = goyaml.Unmarshal(data, &x)
c.Assert(err, gc.IsNil)
c.Check(x["apt_upgrade"], gc.Equals, true)
c.Check(x["apt_update"], gc.Equals, true)
scripts := getScripts(x)
assertScriptMatch(c, scripts, test.expectScripts, !test.inexactMatch)
if test.cfg.Config != nil {
checkEnvConfig(c, test.cfg.Config, x, scripts)
}
checkPackage(c, x, "git", true)
tag := names.MachineTag(test.cfg.MachineId)
acfg := getAgentConfig(c, tag, scripts)
c.Assert(acfg, jc.Contains, "AGENT_SERVICE_NAME: jujud-"+tag)
source := "deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/cloud-tools main"
needCloudArchive := test.cfg.Tools.Version.Series == "precise"
checkAptSource(c, x, source, cloudinit.CanonicalCloudArchiveSigningKey, needCloudArchive)
}
}
开发者ID:jameinel,项目名称:core,代码行数:40,代码来源:cloudinit_test.go
示例19: MachineTag
// MachineTag returns the machine tag of the interface.
func (ni *NetworkInterface) MachineTag() string {
return names.MachineTag(ni.doc.MachineId)
}
开发者ID:jameinel,项目名称:core,代码行数:4,代码来源:networkinterfaces.go
示例20: TestMachineTag
func (s *machineSuite) TestMachineTag(c *gc.C) {
c.Assert(names.MachineTag("10"), gc.Equals, "machine-10")
// Check a container id.
c.Assert(names.MachineTag("10/lxc/1"), gc.Equals, "machine-10-lxc-1")
}
开发者ID:jameinel,项目名称:core,代码行数:5,代码来源:machine_test.go
注:本文中的github.com/wallyworld/core/names.MachineTag函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论