本文整理汇总了Golang中github.com/juju/juju/api.State类的典型用法代码示例。如果您正苦于以下问题:Golang State类的具体用法?Golang State怎么用?Golang State使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了State类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateAllMachines
// updateAllMachines finds all machines and resets the stored state address
// in each of them. The address does not include the port.
func updateAllMachines(apiState *api.State, stateAddr string) ([]restoreResult, error) {
client := apiState.Client()
status, err := client.Status(nil)
if err != nil {
return nil, errors.Annotate(err, "cannot get status")
}
pendingMachineCount := 0
done := make(chan restoreResult)
for _, machineStatus := range status.Machines {
// A newly resumed state server requires no updating, and more
// than one state server is not yet support by this plugin.
if machineStatus.HasVote || machineStatus.WantsVote || machineStatus.Life == "dead" {
continue
}
pendingMachineCount++
machine := machineStatus
go func() {
err := runMachineUpdate(client, machine.Id, setAgentAddressScript(stateAddr))
if err != nil {
logger.Errorf("failed to update machine %s: %v", machine.Id, err)
} else {
progress("updated machine %s", machine.Id)
}
r := restoreResult{machineName: machine.Id, err: err}
done <- r
}()
}
results := make([]restoreResult, pendingMachineCount)
for ; pendingMachineCount > 0; pendingMachineCount-- {
results[pendingMachineCount-1] = <-done
}
return results, nil
}
示例2: restoreBootstrapMachine
func restoreBootstrapMachine(st *api.State, backupFile string, agentConf agentConfig) (addr string, err error) {
client := st.Client()
addr, err = client.PublicAddress("0")
if err != nil {
return "", errors.Annotate(err, "cannot get public address of bootstrap machine")
}
paddr, err := client.PrivateAddress("0")
if err != nil {
return "", errors.Annotate(err, "cannot get private address of bootstrap machine")
}
status, err := client.Status(nil)
if err != nil {
return "", errors.Annotate(err, "cannot get environment status")
}
info, ok := status.Machines["0"]
if !ok {
return "", fmt.Errorf("cannot find bootstrap machine in status")
}
newInstId := instance.Id(info.InstanceId)
progress("copying backup file to bootstrap host")
if err := sendViaScp(backupFile, addr, "~/juju-backup.tgz"); err != nil {
return "", errors.Annotate(err, "cannot copy backup file to bootstrap instance")
}
progress("updating bootstrap machine")
if err := runViaSsh(addr, updateBootstrapMachineScript(newInstId, agentConf, addr, paddr)); err != nil {
return "", errors.Annotate(err, "update script failed")
}
return addr, nil
}
示例3: testNamespace
// testNamespace starts a worker and ensures that
// the rsyslog config file has the expected filename,
// and the appropriate log dir is used.
func (s *RsyslogSuite) testNamespace(c *gc.C, st *api.State, tag names.Tag, namespace, expectedFilename, expectedLogDir string) {
restarted := make(chan struct{}, 2) // once for create, once for teardown
s.PatchValue(rsyslog.RestartRsyslog, func() error {
restarted <- struct{}{}
return nil
})
err := os.MkdirAll(expectedLogDir, 0755)
c.Assert(err, jc.ErrorIsNil)
worker, err := rsyslog.NewRsyslogConfigWorker(st.Rsyslog(), rsyslog.RsyslogModeAccumulate, tag, namespace, []string{"0.1.2.3"})
c.Assert(err, jc.ErrorIsNil)
defer func() { c.Assert(worker.Wait(), gc.IsNil) }()
defer worker.Kill()
// change the API HostPorts to trigger an rsyslog restart
newHostPorts := network.NewHostPorts(6541, "127.0.0.1")
err = s.State.SetAPIHostPorts([][]network.HostPort{newHostPorts})
c.Assert(err, jc.ErrorIsNil)
// Wait for rsyslog to be restarted, so we can check to see
// what the name of the config file is.
waitForRestart(c, restarted)
// Ensure that ca-cert.pem gets written to the expected log dir.
waitForFile(c, filepath.Join(expectedLogDir, "ca-cert.pem"))
dir, err := os.Open(*rsyslog.RsyslogConfDir)
c.Assert(err, jc.ErrorIsNil)
names, err := dir.Readdirnames(-1)
dir.Close()
c.Assert(err, jc.ErrorIsNil)
c.Assert(names, gc.HasLen, 1)
c.Assert(names[0], gc.Equals, expectedFilename)
}
示例4: updateAllMachines
// updateAllMachines finds all machines and resets the stored state address
// in each of them. The address does not include the port.
func updateAllMachines(apiState *api.State, stateAddr string) error {
client := apiState.Client()
status, err := client.Status(nil)
if err != nil {
return errors.Annotate(err, "cannot get status")
}
pendingMachineCount := 0
done := make(chan error)
for _, machineStatus := range status.Machines {
// A newly resumed state server requires no updating, and more
// than one state server is not yet support by this plugin.
if machineStatus.HasVote || machineStatus.WantsVote || params.Life(machineStatus.Life) == params.Dead {
continue
}
pendingMachineCount++
machine := machineStatus
go func() {
err := runMachineUpdate(client, machine.Id, setAgentAddressScript(stateAddr))
if err != nil {
logger.Errorf("failed to update machine %s: %v", machine.Id, err)
} else {
progress("updated machine %s", machine.Id)
}
done <- err
}()
}
err = nil
for ; pendingMachineCount > 0; pendingMachineCount-- {
if updateErr := <-done; updateErr != nil && err == nil {
err = errors.Annotate(updateErr, "machine update failed")
}
}
return err
}
示例5: opClientAddServiceUnits
func opClientAddServiceUnits(c *gc.C, st *api.State, mst *state.State) (func(), error) {
_, err := st.Client().AddServiceUnits("nosuch", 1, "")
if params.IsCodeNotFound(err) {
err = nil
}
return func() {}, err
}
示例6: opClientServiceDestroy
func opClientServiceDestroy(c *gc.C, st *api.State, mst *state.State) (func(), error) {
err := st.Client().ServiceDestroy("non-existent")
if params.IsCodeNotFound(err) {
err = nil
}
return func() {}, err
}
示例7: opClientDestroyServiceUnits
func opClientDestroyServiceUnits(c *gc.C, st *api.State, mst *state.State) (func(), error) {
err := st.Client().DestroyServiceUnits("wordpress/99")
if err != nil && strings.HasPrefix(err.Error(), "no units were destroyed") {
err = nil
}
return func() {}, err
}
示例8: opClientServiceUnexpose
func opClientServiceUnexpose(c *gc.C, st *api.State, mst *state.State) (func(), error) {
err := st.Client().ServiceUnexpose("wordpress")
if err != nil {
return func() {}, err
}
return func() {}, nil
}
示例9: opClientEnvironmentGet
func opClientEnvironmentGet(c *gc.C, st *api.State, mst *state.State) (func(), error) {
_, err := st.Client().EnvironmentGet()
if err != nil {
return func() {}, err
}
return func() {}, nil
}
示例10: opClientServiceSetYAML
func opClientServiceSetYAML(c *gc.C, st *api.State, mst *state.State) (func(), error) {
err := st.Client().ServiceSetYAML("wordpress", `"wordpress": {"blog-title": "foo"}`)
if err != nil {
return func() {}, err
}
return resetBlogTitle(c, st), nil
}
示例11: opClientWatchAll
func opClientWatchAll(c *gc.C, st *api.State, mst *state.State) (func(), error) {
watcher, err := st.Client().WatchAll()
if err == nil {
watcher.Stop()
}
return func() {}, err
}
示例12: opClientDestroyRelation
func opClientDestroyRelation(c *gc.C, st *api.State, mst *state.State) (func(), error) {
err := st.Client().DestroyRelation("nosuch1", "nosuch2")
if params.IsCodeNotFound(err) {
err = nil
}
return func() {}, err
}
示例13: SetUpTest
func (s *workerSuite) SetUpTest(c *gc.C) {
//TODO(bogdanteleaga): Fix this on windows
if runtime.GOOS == "windows" {
c.Skip("bug 1403084: authentication worker not implemented yet on windows")
}
s.JujuConnSuite.SetUpTest(c)
// Default ssh user is currently "ubuntu".
c.Assert(authenticationworker.SSHUser, gc.Equals, "ubuntu")
// Set the ssh user to empty (the current user) as required by the test infrastructure.
s.PatchValue(&authenticationworker.SSHUser, "")
// Replace the default dummy key in the test environment with a valid one.
// This will be added to the ssh authorised keys when the agent starts.
s.setAuthorisedKeys(c, sshtesting.ValidKeyOne.Key+" [email protected]")
// Record the existing key with its prefix for testing later.
s.existingEnvKey = sshtesting.ValidKeyOne.Key + " Juju:[email protected]"
// Set up an existing key (which is not in the environment) in the ssh authorised_keys file.
s.existingKeys = []string{sshtesting.ValidKeyTwo.Key + " [email protected]"}
err := ssh.AddKeys(authenticationworker.SSHUser, s.existingKeys...)
c.Assert(err, jc.ErrorIsNil)
var apiRoot *api.State
apiRoot, s.machine = s.OpenAPIAsNewMachine(c)
c.Assert(apiRoot, gc.NotNil)
s.keyupdaterApi = apiRoot.KeyUpdater()
c.Assert(s.keyupdaterApi, gc.NotNil)
}
示例14: opClientServiceSetCharm
func opClientServiceSetCharm(c *gc.C, st *api.State, mst *state.State) (func(), error) {
err := st.Client().ServiceSetCharm("nosuch", "local:quantal/wordpress", false)
if params.IsCodeNotFound(err) {
err = nil
}
return func() {}, err
}
示例15: opClientServiceDeployWithNetworks
func opClientServiceDeployWithNetworks(c *gc.C, st *api.State, mst *state.State) (func(), error) {
err := st.Client().ServiceDeployWithNetworks("mad:bad/url-1", "x", 1, "", constraints.Value{}, "", nil)
if err.Error() == `charm URL has invalid schema: "mad:bad/url-1"` {
err = nil
}
return func() {}, err
}