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
edaf1919
Commit
edaf1919
authored
Jun 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Environment has Cache method, RPC implements
parent
2c8b1980
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
0 deletions
+42
-0
packer/environment.go
packer/environment.go
+9
-0
packer/rpc/environment.go
packer/rpc/environment.go
+23
-0
packer/rpc/environment_test.go
packer/rpc/environment_test.go
+10
-0
No files found.
packer/environment.go
View file @
edaf1919
...
...
@@ -39,6 +39,7 @@ type ComponentFinder struct {
// list of available builders, and more.
type
Environment
interface
{
Builder
(
string
)
(
Builder
,
error
)
Cache
()
Cache
Cli
([]
string
)
(
int
,
error
)
Hook
(
string
)
(
Hook
,
error
)
Provisioner
(
string
)
(
Provisioner
,
error
)
...
...
@@ -48,6 +49,7 @@ type Environment interface {
// An implementation of an Environment that represents the Packer core
// environment.
type
coreEnvironment
struct
{
cache
Cache
commands
[]
string
components
ComponentFinder
ui
Ui
...
...
@@ -55,6 +57,7 @@ type coreEnvironment struct {
// This struct configures new environments.
type
EnvironmentConfig
struct
{
Cache
Cache
Commands
[]
string
Components
ComponentFinder
Ui
Ui
...
...
@@ -77,6 +80,7 @@ func NewEnvironment(config *EnvironmentConfig) (resultEnv Environment, err error
}
env
:=
&
coreEnvironment
{}
env
.
cache
=
config
.
Cache
env
.
commands
=
config
.
Commands
env
.
components
=
config
.
Components
env
.
ui
=
config
.
Ui
...
...
@@ -119,6 +123,11 @@ func (e *coreEnvironment) Builder(name string) (b Builder, err error) {
return
}
// Returns the cache for this environment
func
(
e
*
coreEnvironment
)
Cache
()
Cache
{
return
e
.
cache
}
// Returns a hook of the given name that is registered with this
// environment.
func
(
e
*
coreEnvironment
)
Hook
(
name
string
)
(
h
Hook
,
err
error
)
{
...
...
packer/rpc/environment.go
View file @
edaf1919
...
...
@@ -37,6 +37,20 @@ func (e *Environment) Builder(name string) (b packer.Builder, err error) {
return
}
func
(
e
*
Environment
)
Cache
()
packer
.
Cache
{
var
reply
string
if
err
:=
e
.
client
.
Call
(
"Environment.Cache"
,
new
(
interface
{}),
&
reply
);
err
!=
nil
{
panic
(
err
)
}
client
,
err
:=
rpc
.
Dial
(
"tcp"
,
reply
)
if
err
!=
nil
{
panic
(
err
)
}
return
Cache
(
client
)
}
func
(
e
*
Environment
)
Cli
(
args
[]
string
)
(
result
int
,
err
error
)
{
rpcArgs
:=
&
EnvironmentCliArgs
{
args
}
err
=
e
.
client
.
Call
(
"Environment.Cli"
,
rpcArgs
,
&
result
)
...
...
@@ -98,6 +112,15 @@ func (e *EnvironmentServer) Builder(name *string, reply *string) error {
return
nil
}
func
(
e
*
EnvironmentServer
)
Cache
(
args
*
interface
{},
reply
*
string
)
error
{
cache
:=
e
.
env
.
Cache
()
server
:=
rpc
.
NewServer
()
RegisterCache
(
server
,
cache
)
*
reply
=
serveSingleConn
(
server
)
return
nil
}
func
(
e
*
EnvironmentServer
)
Cli
(
args
*
EnvironmentCliArgs
,
reply
*
int
)
(
err
error
)
{
*
reply
,
err
=
e
.
env
.
Cli
(
args
.
Args
)
return
...
...
packer/rpc/environment_test.go
View file @
edaf1919
...
...
@@ -8,6 +8,7 @@ import (
)
var
testEnvBuilder
=
&
testBuilder
{}
var
testEnvCache
=
&
testCache
{}
var
testEnvUi
=
&
testUi
{}
type
testEnvironment
struct
{
...
...
@@ -28,6 +29,10 @@ func (e *testEnvironment) Builder(name string) (packer.Builder, error) {
return
testEnvBuilder
,
nil
}
func
(
e
*
testEnvironment
)
Cache
()
packer
.
Cache
{
return
testEnvCache
}
func
(
e
*
testEnvironment
)
Cli
(
args
[]
string
)
(
int
,
error
)
{
e
.
cliCalled
=
true
e
.
cliArgs
=
args
...
...
@@ -75,6 +80,11 @@ func TestEnvironmentRPC(t *testing.T) {
builder
.
Prepare
(
nil
)
assert
.
True
(
testEnvBuilder
.
prepareCalled
,
"Prepare should be called"
)
// Test Cache
cache
:=
eClient
.
Cache
()
cache
.
Lock
(
"foo"
)
assert
.
True
(
testEnvCache
.
lockCalled
,
"lock should be called"
)
// Test Cli
cliArgs
:=
[]
string
{
"foo"
,
"bar"
}
result
,
_
:=
eClient
.
Cli
(
cliArgs
)
...
...
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