Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
88d50889
Commit
88d50889
authored
Jun 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: client to Client so it can be used outside
parent
7fe98e50
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
17 deletions
+20
-17
packer/plugin/builder.go
packer/plugin/builder.go
+1
-1
packer/plugin/client.go
packer/plugin/client.go
+16
-13
packer/plugin/command.go
packer/plugin/command.go
+1
-1
packer/plugin/hook.go
packer/plugin/hook.go
+1
-1
packer/plugin/provisioner.go
packer/plugin/provisioner.go
+1
-1
No files found.
packer/plugin/builder.go
View file @
88d50889
...
@@ -7,7 +7,7 @@ import (
...
@@ -7,7 +7,7 @@ import (
type
cmdBuilder
struct
{
type
cmdBuilder
struct
{
builder
packer
.
Builder
builder
packer
.
Builder
client
*
c
lient
client
*
C
lient
}
}
func
(
b
*
cmdBuilder
)
Prepare
(
config
interface
{})
error
{
func
(
b
*
cmdBuilder
)
Prepare
(
config
interface
{})
error
{
...
...
packer/plugin/client.go
View file @
88d50889
...
@@ -18,9 +18,12 @@ import (
...
@@ -18,9 +18,12 @@ import (
// This is a slice of the "managed" clients which are cleaned up when
// This is a slice of the "managed" clients which are cleaned up when
// calling Cleanup
// calling Cleanup
var
managedClients
=
make
([]
*
c
lient
,
0
,
5
)
var
managedClients
=
make
([]
*
C
lient
,
0
,
5
)
type
client
struct
{
// Client handles the lifecycle of a plugin application, determining its
// RPC address, and returning various types of packer interface implementations
// across the multi-process communication layer.
type
Client
struct
{
config
*
ClientConfig
config
*
ClientConfig
exited
bool
exited
bool
doneLogging
bool
doneLogging
bool
...
@@ -81,7 +84,7 @@ func CleanupClients() {
...
@@ -81,7 +84,7 @@ func CleanupClients() {
// the client is a managed client (created with NewManagedClient) you
// the client is a managed client (created with NewManagedClient) you
// can just call CleanupClients at the end of your program and they will
// can just call CleanupClients at the end of your program and they will
// be properly cleaned.
// be properly cleaned.
func
NewClient
(
config
*
ClientConfig
)
(
c
*
c
lient
)
{
func
NewClient
(
config
*
ClientConfig
)
(
c
*
C
lient
)
{
if
config
.
MinPort
==
0
&&
config
.
MaxPort
==
0
{
if
config
.
MinPort
==
0
&&
config
.
MaxPort
==
0
{
config
.
MinPort
=
10000
config
.
MinPort
=
10000
config
.
MaxPort
=
25000
config
.
MaxPort
=
25000
...
@@ -91,7 +94,7 @@ func NewClient(config *ClientConfig) (c *client) {
...
@@ -91,7 +94,7 @@ func NewClient(config *ClientConfig) (c *client) {
config
.
StartTimeout
=
1
*
time
.
Minute
config
.
StartTimeout
=
1
*
time
.
Minute
}
}
c
=
&
c
lient
{
config
:
config
}
c
=
&
C
lient
{
config
:
config
}
if
config
.
Managed
{
if
config
.
Managed
{
managedClients
=
append
(
managedClients
,
c
)
managedClients
=
append
(
managedClients
,
c
)
}
}
...
@@ -100,13 +103,13 @@ func NewClient(config *ClientConfig) (c *client) {
...
@@ -100,13 +103,13 @@ func NewClient(config *ClientConfig) (c *client) {
}
}
// Tells whether or not the underlying process has exited.
// Tells whether or not the underlying process has exited.
func
(
c
*
c
lient
)
Exited
()
bool
{
func
(
c
*
C
lient
)
Exited
()
bool
{
return
c
.
exited
return
c
.
exited
}
}
// Returns a builder implementation that is communicating over this
// Returns a builder implementation that is communicating over this
// client. If the client hasn't been started, this will start it.
// client. If the client hasn't been started, this will start it.
func
(
c
*
c
lient
)
Builder
()
(
packer
.
Builder
,
error
)
{
func
(
c
*
C
lient
)
Builder
()
(
packer
.
Builder
,
error
)
{
client
,
err
:=
c
.
rpcClient
()
client
,
err
:=
c
.
rpcClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -117,7 +120,7 @@ func (c *client) Builder() (packer.Builder, error) {
...
@@ -117,7 +120,7 @@ func (c *client) Builder() (packer.Builder, error) {
// Returns a command implementation that is communicating over this
// Returns a command implementation that is communicating over this
// client. If the client hasn't been started, this will start it.
// client. If the client hasn't been started, this will start it.
func
(
c
*
c
lient
)
Command
()
(
packer
.
Command
,
error
)
{
func
(
c
*
C
lient
)
Command
()
(
packer
.
Command
,
error
)
{
client
,
err
:=
c
.
rpcClient
()
client
,
err
:=
c
.
rpcClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -128,7 +131,7 @@ func (c *client) Command() (packer.Command, error) {
...
@@ -128,7 +131,7 @@ func (c *client) Command() (packer.Command, error) {
// Returns a hook implementation that is communicating over this
// Returns a hook implementation that is communicating over this
// client. If the client hasn't been started, this will start it.
// client. If the client hasn't been started, this will start it.
func
(
c
*
c
lient
)
Hook
()
(
packer
.
Hook
,
error
)
{
func
(
c
*
C
lient
)
Hook
()
(
packer
.
Hook
,
error
)
{
client
,
err
:=
c
.
rpcClient
()
client
,
err
:=
c
.
rpcClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -139,7 +142,7 @@ func (c *client) Hook() (packer.Hook, error) {
...
@@ -139,7 +142,7 @@ func (c *client) Hook() (packer.Hook, error) {
// Returns a provisioner implementation that is communicating over this
// Returns a provisioner implementation that is communicating over this
// client. If the client hasn't been started, this will start it.
// client. If the client hasn't been started, this will start it.
func
(
c
*
c
lient
)
Provisioner
()
(
packer
.
Provisioner
,
error
)
{
func
(
c
*
C
lient
)
Provisioner
()
(
packer
.
Provisioner
,
error
)
{
client
,
err
:=
c
.
rpcClient
()
client
,
err
:=
c
.
rpcClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -154,7 +157,7 @@ func (c *client) Provisioner() (packer.Provisioner, error) {
...
@@ -154,7 +157,7 @@ func (c *client) Provisioner() (packer.Provisioner, error) {
// This method blocks until the process successfully exits.
// This method blocks until the process successfully exits.
//
//
// This method can safely be called multiple times.
// This method can safely be called multiple times.
func
(
c
*
c
lient
)
Kill
()
{
func
(
c
*
C
lient
)
Kill
()
{
cmd
:=
c
.
config
.
Cmd
cmd
:=
c
.
config
.
Cmd
if
cmd
.
Process
==
nil
{
if
cmd
.
Process
==
nil
{
...
@@ -182,7 +185,7 @@ func (c *client) Kill() {
...
@@ -182,7 +185,7 @@ func (c *client) Kill() {
// This method is safe to call multiple times. Subsequent calls have no effect.
// This method is safe to call multiple times. Subsequent calls have no effect.
// Once a client has been started once, it cannot be started again, even if
// Once a client has been started once, it cannot be started again, even if
// it was killed.
// it was killed.
func
(
c
*
c
lient
)
Start
()
(
address
string
,
err
error
)
{
func
(
c
*
C
lient
)
Start
()
(
address
string
,
err
error
)
{
c
.
l
.
Lock
()
c
.
l
.
Lock
()
defer
c
.
l
.
Unlock
()
defer
c
.
l
.
Unlock
()
...
@@ -269,7 +272,7 @@ func (c *client) Start() (address string, err error) {
...
@@ -269,7 +272,7 @@ func (c *client) Start() (address string, err error) {
return
return
}
}
func
(
c
*
c
lient
)
logStderr
(
buf
*
bytes
.
Buffer
)
{
func
(
c
*
C
lient
)
logStderr
(
buf
*
bytes
.
Buffer
)
{
for
done
:=
false
;
!
done
;
{
for
done
:=
false
;
!
done
;
{
if
c
.
Exited
()
{
if
c
.
Exited
()
{
done
=
true
done
=
true
...
@@ -291,7 +294,7 @@ func (c *client) logStderr(buf *bytes.Buffer) {
...
@@ -291,7 +294,7 @@ func (c *client) logStderr(buf *bytes.Buffer) {
c
.
doneLogging
=
true
c
.
doneLogging
=
true
}
}
func
(
c
*
c
lient
)
rpcClient
()
(
*
rpc
.
Client
,
error
)
{
func
(
c
*
C
lient
)
rpcClient
()
(
*
rpc
.
Client
,
error
)
{
address
,
err
:=
c
.
Start
()
address
,
err
:=
c
.
Start
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
packer/plugin/command.go
View file @
88d50889
...
@@ -7,7 +7,7 @@ import (
...
@@ -7,7 +7,7 @@ import (
type
cmdCommand
struct
{
type
cmdCommand
struct
{
command
packer
.
Command
command
packer
.
Command
client
*
c
lient
client
*
C
lient
}
}
func
(
c
*
cmdCommand
)
Help
()
(
result
string
)
{
func
(
c
*
cmdCommand
)
Help
()
(
result
string
)
{
...
...
packer/plugin/hook.go
View file @
88d50889
...
@@ -7,7 +7,7 @@ import (
...
@@ -7,7 +7,7 @@ import (
type
cmdHook
struct
{
type
cmdHook
struct
{
hook
packer
.
Hook
hook
packer
.
Hook
client
*
c
lient
client
*
C
lient
}
}
func
(
c
*
cmdHook
)
Run
(
name
string
,
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
data
interface
{})
{
func
(
c
*
cmdHook
)
Run
(
name
string
,
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
data
interface
{})
{
...
...
packer/plugin/provisioner.go
View file @
88d50889
...
@@ -7,7 +7,7 @@ import (
...
@@ -7,7 +7,7 @@ import (
type
cmdProvisioner
struct
{
type
cmdProvisioner
struct
{
p
packer
.
Provisioner
p
packer
.
Provisioner
client
*
c
lient
client
*
C
lient
}
}
func
(
c
*
cmdProvisioner
)
Prepare
(
configs
...
interface
{})
error
{
func
(
c
*
cmdProvisioner
)
Prepare
(
configs
...
interface
{})
error
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment