本文整理汇总了Golang中github.com/juju/juju/juju/sockets.Dial函数的典型用法代码示例。如果您正苦于以下问题:Golang Dial函数的具体用法?Golang Dial怎么用?Golang Dial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Dial函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: step
func (cmds asyncRunCommands) step(c *gc.C, ctx *context) {
commands := strings.Join(cmds, "\n")
args := uniter.RunCommandsArgs{
Commands: commands,
RelationId: -1,
RemoteUnitName: "",
}
var socketPath string
if runtime.GOOS == "windows" {
socketPath = `\\.\pipe\unit-u-0-run`
} else {
socketPath = filepath.Join(ctx.path, "run.socket")
}
ctx.wg.Add(1)
go func() {
defer ctx.wg.Done()
// make sure the socket exists
client, err := sockets.Dial(socketPath)
// Don't use asserts in go routines.
if !c.Check(err, jc.ErrorIsNil) {
return
}
defer client.Close()
var result utilexec.ExecResponse
err = client.Call(uniter.JujuRunEndpoint, args, &result)
if c.Check(err, jc.ErrorIsNil) {
c.Check(result.Code, gc.Equals, 0)
c.Check(string(result.Stdout), gc.Equals, "")
c.Check(string(result.Stderr), gc.Equals, "")
}
}()
}
示例2: executeInUnitContext
func (c *RunCommand) executeInUnitContext() (*exec.ExecResponse, error) {
unitDir := agent.Dir(cmdutil.DataDir, c.unit)
logger.Debugf("looking for unit dir %s", unitDir)
// make sure the unit exists
_, err := os.Stat(unitDir)
if os.IsNotExist(err) {
return nil, errors.Errorf("unit %q not found on this machine", c.unit.Id())
} else if err != nil {
return nil, errors.Trace(err)
}
relationId, err := checkRelationId(c.relationId)
if err != nil {
return nil, errors.Trace(err)
}
if len(c.remoteUnitName) > 0 && relationId == -1 {
return nil, errors.Errorf("remote unit: %s, provided without a relation", c.remoteUnitName)
}
client, err := sockets.Dial(c.socketPath())
if err != nil {
return nil, errors.Trace(err)
}
defer client.Close()
var result exec.ExecResponse
args := uniter.RunCommandsArgs{
Commands: c.commands,
RelationId: relationId,
RemoteUnitName: c.remoteUnitName,
ForceRemoteUnit: c.forceRemoteUnit,
}
err = client.Call(uniter.JujuRunEndpoint, args, &result)
return &result, errors.Trace(err)
}
示例3: Call
func (s *ServerSuite) Call(c *gc.C, req jujuc.Request) (resp exec.ExecResponse, err error) {
client, err := sockets.Dial(s.sockPath)
c.Assert(err, jc.ErrorIsNil)
defer client.Close()
err = client.Call("Jujuc.Main", req, &resp)
return resp, err
}
示例4: jujuCMain
// jujuCMain uses JUJU_CONTEXT_ID and JUJU_AGENT_SOCKET to ask a running unit agent
// to execute a Command on our behalf. Individual commands should be exposed
// by symlinking the command name to this executable.
func jujuCMain(commandName string, args []string) (code int, err error) {
code = 1
contextId, err := getenv("JUJU_CONTEXT_ID")
if err != nil {
return
}
dir, err := getwd()
if err != nil {
return
}
req := jujuc.Request{
ContextId: contextId,
Dir: dir,
CommandName: commandName,
Args: args[1:],
}
socketPath, err := getenv("JUJU_AGENT_SOCKET")
if err != nil {
return
}
client, err := sockets.Dial(socketPath)
if err != nil {
return
}
defer client.Close()
var resp exec.ExecResponse
err = client.Call("Jujuc.Main", req, &resp)
if err != nil {
return
}
os.Stdout.Write(resp.Stdout)
os.Stderr.Write(resp.Stderr)
return resp.Code, nil
}
示例5: TestClientCall
func (s *ListenerSuite) TestClientCall(c *gc.C) {
s.NewRunListener(c)
client, err := sockets.Dial(s.socketPath)
c.Assert(err, gc.IsNil)
defer client.Close()
var result exec.ExecResponse
err = client.Call(uniter.JujuRunEndpoint, "some-command", &result)
c.Assert(err, gc.IsNil)
c.Assert(string(result.Stdout), gc.Equals, "some-command stdout")
c.Assert(string(result.Stderr), gc.Equals, "some-command stderr")
c.Assert(result.Code, gc.Equals, 42)
}
示例6: jujuCMain
// jujuCMain uses JUJU_CONTEXT_ID and JUJU_AGENT_SOCKET to ask a running unit agent
// to execute a Command on our behalf. Individual commands should be exposed
// by symlinking the command name to this executable.
func jujuCMain(commandName string, ctx *cmd.Context, args []string) (code int, err error) {
code = 1
contextId, err := getenv("JUJU_CONTEXT_ID")
if err != nil {
return
}
dir, err := getwd()
if err != nil {
return
}
req := jujuc.Request{
ContextId: contextId,
Dir: dir,
CommandName: commandName,
Args: args[1:],
}
socketPath, err := getenv("JUJU_AGENT_SOCKET")
if err != nil {
return
}
client, err := sockets.Dial(socketPath)
if err != nil {
return
}
defer client.Close()
var resp exec.ExecResponse
err = client.Call("Jujuc.Main", req, &resp)
if err != nil && err.Error() == jujuc.ErrNoStdin.Error() {
req.Stdin, err = ioutil.ReadAll(os.Stdin)
if err != nil {
err = errors.Annotate(err, "cannot read stdin")
return
}
req.StdinSet = true
err = client.Call("Jujuc.Main", req, &resp)
}
if err != nil {
return
}
os.Stdout.Write(resp.Stdout)
os.Stderr.Write(resp.Stderr)
return resp.Code, nil
}
示例7: TestClientCall
func (s *ListenerSuite) TestClientCall(c *gc.C) {
s.NewRunListener(c)
client, err := sockets.Dial(s.socketPath)
c.Assert(err, jc.ErrorIsNil)
defer client.Close()
var result exec.ExecResponse
args := uniter.RunCommandsArgs{
Commands: "some-command",
RelationId: -1,
RemoteUnitName: "",
ForceRemoteUnit: false,
}
err = client.Call(uniter.JujuRunEndpoint, args, &result)
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(result.Stdout), gc.Equals, "some-command stdout")
c.Assert(string(result.Stderr), gc.Equals, "some-command stderr")
c.Assert(result.Code, gc.Equals, 42)
}
示例8: executeInUnitContext
func (c *RunCommand) executeInUnitContext() (*exec.ExecResponse, error) {
unitDir := filepath.Join(AgentDir, c.unit)
logger.Debugf("looking for unit dir %s", unitDir)
// make sure the unit exists
_, err := os.Stat(unitDir)
if os.IsNotExist(err) {
return nil, fmt.Errorf("unit %q not found on this machine", c.unit)
} else if err != nil {
return nil, err
}
// make sure the socket exists
socketPath := c.sockPath()
client, err := sockets.Dial(socketPath)
if err != nil {
return nil, err
}
defer client.Close()
var result exec.ExecResponse
err = client.Call(uniter.JujuRunEndpoint, c.commands, &result)
return &result, err
}