本文整理汇总了Golang中github.com/wallyworld/core/environs.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestMachineConfig
func (s *machineConfigSuite) TestMachineConfig(c *gc.C) {
addrs := []instance.Address{instance.NewAddress("1.2.3.4", instance.NetworkUnknown)}
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Jobs: []params.MachineJob{params.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: addrs,
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, gc.IsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
machineConfig, err := client.MachineConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, gc.IsNil)
envConfig, err := s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
env, err := environs.New(envConfig)
c.Assert(err, gc.IsNil)
stateInfo, apiInfo, err := env.StateInfo()
c.Assert(err, gc.IsNil)
c.Check(machineConfig.StateInfo.Addrs, gc.DeepEquals, stateInfo.Addrs)
c.Check(machineConfig.APIInfo.Addrs, gc.DeepEquals, apiInfo.Addrs)
c.Assert(machineConfig.Tools.URL, gc.Not(gc.Equals), "")
}
示例2: Tools
// Tools finds the tools necessary for the given agents.
func (t *ToolsGetter) Tools(args params.Entities) (params.ToolsResults, error) {
result := params.ToolsResults{
Results: make([]params.ToolsResult, len(args.Entities)),
}
canRead, err := t.getCanRead()
if err != nil {
return result, err
}
agentVersion, cfg, err := t.getGlobalAgentVersion()
if err != nil {
return result, err
}
// SSLHostnameVerification defaults to true, so we need to
// invert that, for backwards-compatibility (older versions
// will have DisableSSLHostnameVerification: false by default).
disableSSLHostnameVerification := !cfg.SSLHostnameVerification()
env, err := environs.New(cfg)
if err != nil {
return result, err
}
for i, entity := range args.Entities {
agentTools, err := t.oneAgentTools(canRead, entity.Tag, agentVersion, env)
if err == nil {
result.Results[i].Tools = agentTools
result.Results[i].DisableSSLHostnameVerification = disableSSLHostnameVerification
}
result.Results[i].Error = ServerError(err)
}
return result, nil
}
示例3: loop
func (obs *EnvironObserver) loop() error {
for {
select {
case <-obs.tomb.Dying():
return nil
case _, ok := <-obs.environWatcher.Changes():
if !ok {
return watcher.MustErr(obs.environWatcher)
}
}
config, err := obs.st.EnvironConfig()
if err != nil {
logger.Warningf("error reading environment config: %v", err)
continue
}
environ, err := environs.New(config)
if err != nil {
logger.Warningf("error creating Environ: %v", err)
continue
}
obs.mu.Lock()
obs.environ = environ
obs.mu.Unlock()
}
}
示例4: assertGetImageMetadataSources
func (s *localServerSuite) assertGetImageMetadataSources(c *gc.C, stream, officialSourcePath string) {
// Create a config that matches s.TestConfig but with the specified stream.
envAttrs := s.TestConfig
if stream != "" {
envAttrs = envAttrs.Merge(coretesting.Attrs{"image-stream": stream})
}
cfg, err := config.New(config.NoDefaults, envAttrs)
c.Assert(err, gc.IsNil)
env, err := environs.New(cfg)
c.Assert(err, gc.IsNil)
sources, err := imagemetadata.GetMetadataSources(env)
c.Assert(err, gc.IsNil)
c.Assert(sources, gc.HasLen, 4)
var urls = make([]string, len(sources))
for i, source := range sources {
url, err := source.URL("")
c.Assert(err, gc.IsNil)
urls[i] = url
}
// The image-metadata-url ends with "/juju-dist-test/".
c.Check(strings.HasSuffix(urls[0], "/juju-dist-test/"), jc.IsTrue)
// The control bucket URL contains the bucket name.
c.Check(strings.Contains(urls[1], openstack.ControlBucketName(env)+"/images"), jc.IsTrue)
// The product-streams URL ends with "/imagemetadata".
c.Check(strings.HasSuffix(urls[2], "/imagemetadata/"), jc.IsTrue)
c.Assert(urls[3], gc.Equals, fmt.Sprintf("http://cloud-images.ubuntu.com/%s/", officialSourcePath))
}
示例5: assertStartInstanceDefaultSecurityGroup
func (s *LiveTests) assertStartInstanceDefaultSecurityGroup(c *gc.C, useDefault bool) {
attrs := s.TestConfig.Merge(coretesting.Attrs{
"name": "sample-" + randomName(),
"control-bucket": "juju-test-" + randomName(),
"use-default-secgroup": useDefault,
})
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)
// Set up a test environment.
env, err := environs.New(cfg)
c.Assert(err, gc.IsNil)
c.Assert(env, gc.NotNil)
defer env.Destroy()
// Bootstrap and start an instance.
err = bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
inst, _ := jujutesting.AssertStartInstance(c, env, "100")
// Check whether the instance has the default security group assigned.
novaClient := openstack.GetNovaClient(env)
groups, err := novaClient.GetServerSecurityGroups(string(inst.Id()))
c.Assert(err, gc.IsNil)
defaultGroupFound := false
for _, group := range groups {
if group.Name == "default" {
defaultGroupFound = true
break
}
}
c.Assert(defaultGroupFound, gc.Equals, useDefault)
}
示例6: MachineConfig
// MachineConfig returns information from the environment config that is
// needed for machine cloud-init (for non-state servers only).
// It is exposed for testing purposes.
// TODO(rog) fix environs/manual tests so they do not need to
// call this, or move this elsewhere.
func MachineConfig(st *state.State, machineId, nonce, dataDir string) (*cloudinit.MachineConfig, error) {
environConfig, err := st.EnvironConfig()
if err != nil {
return nil, err
}
// Get the machine so we can get its series and arch.
// If the Arch is not set in hardware-characteristics,
// an error is returned.
machine, err := st.Machine(machineId)
if err != nil {
return nil, err
}
hc, err := machine.HardwareCharacteristics()
if err != nil {
return nil, err
}
if hc.Arch == nil {
return nil, fmt.Errorf("arch is not set for %q", machine.Tag())
}
// Find the appropriate tools information.
env, err := environs.New(environConfig)
if err != nil {
return nil, err
}
tools, err := findInstanceTools(env, machine.Series(), *hc.Arch)
if err != nil {
return nil, err
}
// Find the secrets and API endpoints.
auth, err := environs.NewEnvironAuthenticator(env)
if err != nil {
return nil, err
}
stateInfo, apiInfo, err := auth.SetupAuthentication(machine)
if err != nil {
return nil, err
}
// Find requested networks.
includeNetworks, excludeNetworks, err := machine.RequestedNetworks()
if err != nil {
return nil, err
}
mcfg := environs.NewMachineConfig(machineId, nonce, includeNetworks, excludeNetworks, stateInfo, apiInfo)
if dataDir != "" {
mcfg.DataDir = dataDir
}
mcfg.Tools = tools
err = environs.FinishMachineConfig(mcfg, environConfig, constraints.Value{})
if err != nil {
return nil, err
}
return mcfg, nil
}
示例7: findTools1dot17
// findTools1dot17 allows 1.17.x versions to be upgraded.
func findTools1dot17(cfg *config.Config) (coretools.List, error) {
logger.Warningf("running find tools in 1.17 compatibility mode")
env, err := environs.New(cfg)
if err != nil {
return nil, err
}
clientVersion := version.Current.Number
return envtools.FindTools(env, clientVersion.Major, -1, coretools.Filter{}, envtools.DoNotAllowRetry)
}
示例8: Open
// Open opens an instance of the testing environment.
func (t *Tests) Open(c *gc.C) environs.Environ {
info, err := t.ConfigStore.ReadInfo(t.TestConfig["name"].(string))
c.Assert(err, gc.IsNil)
cfg, err := config.New(config.NoDefaults, info.BootstrapConfig())
c.Assert(err, gc.IsNil)
e, err := environs.New(cfg)
c.Assert(err, gc.IsNil, gc.Commentf("opening environ %#v", cfg.AllAttrs()))
c.Assert(e, gc.NotNil)
return e
}
示例9: uploadTools1dot17
func (context *upgradeContext) uploadTools1dot17(builtTools *sync.BuiltTools,
series ...string) (*coretools.Tools, error) {
logger.Warningf("running upload tools in 1.17 compatibility mode")
env, err := environs.New(context.config)
if err != nil {
return nil, err
}
return sync.SyncBuiltTools(env.Storage(), builtTools, series...)
}
示例10: TestStartInstanceNetworkUnknownLabel
func (s *localServerSuite) TestStartInstanceNetworkUnknownLabel(c *gc.C) {
cfg, err := config.New(config.NoDefaults, s.TestConfig.Merge(coretesting.Attrs{
// A label that has no related network in the nova test service
"network": "no-network-with-this-label",
}))
c.Assert(err, gc.IsNil)
env, err := environs.New(cfg)
c.Assert(err, gc.IsNil)
inst, _, _, err := testing.StartInstance(env, "100")
c.Check(inst, gc.IsNil)
c.Assert(err, gc.ErrorMatches, "No networks exist with label .*")
}
示例11: TestNew
func (*OpenSuite) TestNew(c *gc.C) {
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(
testing.Attrs{
"state-server": false,
"name": "erewhemos",
},
))
c.Assert(err, gc.IsNil)
e, err := environs.New(cfg)
c.Assert(err, gc.ErrorMatches, "environment is not prepared")
c.Assert(e, gc.IsNil)
}
示例12: TestStartInstanceNetwork
func (s *localServerSuite) TestStartInstanceNetwork(c *gc.C) {
cfg, err := config.New(config.NoDefaults, s.TestConfig.Merge(coretesting.Attrs{
// A label that corresponds to a nova test service network
"network": "net",
}))
c.Assert(err, gc.IsNil)
env, err := environs.New(cfg)
c.Assert(err, gc.IsNil)
inst, _ := testing.AssertStartInstance(c, env, "100")
err = env.StopInstances([]instance.Instance{inst})
c.Assert(err, gc.IsNil)
}
示例13: destroyInstances
// destroyInstances directly destroys all non-manager,
// non-manual machine instances.
func destroyInstances(st *state.State, machines []*state.Machine) error {
var ids []instance.Id
for _, m := range machines {
if m.IsManager() {
continue
}
manual, err := m.IsManual()
if manual {
continue
} else if err != nil {
return err
}
id, err := m.InstanceId()
if err != nil {
continue
}
ids = append(ids, id)
}
if len(ids) == 0 {
return nil
}
envcfg, err := st.EnvironConfig()
if err != nil {
return err
}
env, err := environs.New(envcfg)
if err != nil {
return err
}
// TODO(axw) 2013-12-12 #1260171
// Modify InstanceBroker.StopInstances to take
// a slice of IDs rather than Instances.
instances, err := env.Instances(ids)
switch err {
case nil:
default:
return err
case environs.ErrNoInstances:
return nil
case environs.ErrPartialInstances:
var nonNilInstances []instance.Instance
for i, inst := range instances {
if inst == nil {
logger.Warningf("unknown instance ID: %v", ids[i])
continue
}
nonNilInstances = append(nonNilInstances, inst)
}
instances = nonNilInstances
}
return env.StopInstances(instances)
}
示例14: NewConnFromState
// NewConnFromState returns a Conn that uses an Environ
// made by reading the environment configuration.
// The resulting Conn uses the given State - closing
// it will close that State.
func NewConnFromState(st *state.State) (*Conn, error) {
cfg, err := st.EnvironConfig()
if err != nil {
return nil, err
}
environ, err := environs.New(cfg)
if err != nil {
return nil, err
}
return &Conn{
Environ: environ,
State: st,
}, nil
}
示例15: uploadToStorage
// uploadToStorage uploads the tools from the specified directory to environment storage.
func (h *toolsHandler) uploadToStorage(uploadedTools *tools.Tools, toolsDir,
toolsFilename string, fakeSeries ...string) (*tools.Tools, bool, error) {
// SyncTools requires simplestreams metadata to find the tools to upload.
stor, err := filestorage.NewFileStorageWriter(toolsDir)
if err != nil {
return nil, false, fmt.Errorf("cannot create metadata storage: %v", err)
}
// Generate metadata for the fake series. The URL for each fake series
// record points to the same tools tarball.
allToolsMetadata := []*tools.Tools{uploadedTools}
for _, series := range fakeSeries {
vers := uploadedTools.Version
vers.Series = series
allToolsMetadata = append(allToolsMetadata, &tools.Tools{
Version: vers,
URL: uploadedTools.URL,
Size: uploadedTools.Size,
SHA256: uploadedTools.SHA256,
})
}
err = envtools.MergeAndWriteMetadata(stor, allToolsMetadata, false)
if err != nil {
return nil, false, fmt.Errorf("cannot get environment config: %v", err)
}
// Create the environment so we can get the storage to which we upload the tools.
envConfig, err := h.state.EnvironConfig()
if err != nil {
return nil, false, fmt.Errorf("cannot get environment config: %v", err)
}
env, err := environs.New(envConfig)
if err != nil {
return nil, false, fmt.Errorf("cannot access environment: %v", err)
}
// Now perform the upload.
builtTools := &sync.BuiltTools{
Version: uploadedTools.Version,
Dir: toolsDir,
StorageName: toolsFilename,
Size: uploadedTools.Size,
Sha256Hash: uploadedTools.SHA256,
}
uploadedTools, err = sync.SyncBuiltTools(env.Storage(), builtTools, fakeSeries...)
if err != nil {
return nil, false, err
}
return uploadedTools, !envConfig.SSLHostnameVerification(), nil
}