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
92b6b5c3
Commit
92b6b5c3
authored
Jun 12, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/openstack: can ref flavor by name
parent
ad374e82
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
5 deletions
+70
-5
builder/openstack/builder.go
builder/openstack/builder.go
+3
-1
builder/openstack/step_load_flavor.go
builder/openstack/step_load_flavor.go
+61
-0
builder/openstack/step_run_source_server.go
builder/openstack/step_run_source_server.go
+5
-3
website/source/docs/builders/openstack.html.markdown
website/source/docs/builders/openstack.html.markdown
+1
-1
No files found.
builder/openstack/builder.go
View file @
92b6b5c3
...
...
@@ -67,13 +67,15 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Build the steps
steps
:=
[]
multistep
.
Step
{
&
StepLoadFlavor
{
Flavor
:
b
.
config
.
Flavor
,
},
&
StepKeyPair
{
Debug
:
b
.
config
.
PackerDebug
,
DebugKeyPath
:
fmt
.
Sprintf
(
"os_%s.pem"
,
b
.
config
.
PackerBuildName
),
},
&
StepRunSourceServer
{
Name
:
b
.
config
.
ImageName
,
Flavor
:
b
.
config
.
Flavor
,
SourceImage
:
b
.
config
.
SourceImage
,
SecurityGroups
:
b
.
config
.
SecurityGroups
,
Networks
:
b
.
config
.
Networks
,
...
...
builder/openstack/step_load_flavor.go
0 → 100644
View file @
92b6b5c3
package
openstack
import
(
"fmt"
"log"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/rackspace/gophercloud/openstack/compute/v2/flavors"
)
// StepLoadFlavor gets the FlavorRef from a Flavor. It first assumes
// that the Flavor is a ref and verifies it. Otherwise, it tries to find
// the flavor by name.
type
StepLoadFlavor
struct
{
Flavor
string
}
func
(
s
*
StepLoadFlavor
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
Config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
// We need the v2 compute client
client
,
err
:=
config
.
computeV2Client
()
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"Error initializing compute client: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
ui
.
Say
(
fmt
.
Sprintf
(
"Loading flavor: %s"
,
s
.
Flavor
))
log
.
Printf
(
"[INFO] Loading flavor by ID: %s"
,
s
.
Flavor
)
flavor
,
err
:=
flavors
.
Get
(
client
,
s
.
Flavor
)
.
Extract
()
if
err
!=
nil
{
log
.
Printf
(
"[ERROR] Failed to find flavor by ID: %s"
,
err
)
geterr
:=
err
log
.
Printf
(
"[INFO] Loading flavor by name: %s"
,
s
.
Flavor
)
id
,
err
:=
flavors
.
IDFromName
(
client
,
s
.
Flavor
)
if
err
!=
nil
{
log
.
Printf
(
"[ERROR] Failed to find flavor by name: %s"
,
err
)
err
=
fmt
.
Errorf
(
"Unable to find specified flavor by ID or name!
\n\n
"
+
"Error from ID lookup: %s
\n\n
"
+
"Error from name lookup: %s"
,
geterr
,
err
)
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
flavor
=
&
flavors
.
Flavor
{
ID
:
id
}
}
ui
.
Message
(
fmt
.
Sprintf
(
"Verified flavor. ID: %s"
,
flavor
.
ID
))
state
.
Put
(
"flavor_id"
,
flavor
.
ID
)
return
multistep
.
ActionContinue
}
func
(
s
*
StepLoadFlavor
)
Cleanup
(
state
multistep
.
StateBag
)
{
}
builder/openstack/step_run_source_server.go
View file @
92b6b5c3
...
...
@@ -11,7 +11,6 @@ import (
)
type
StepRunSourceServer
struct
{
Flavor
string
Name
string
SourceImage
string
SecurityGroups
[]
string
...
...
@@ -22,6 +21,7 @@ type StepRunSourceServer struct {
func
(
s
*
StepRunSourceServer
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
Config
)
flavor
:=
state
.
Get
(
"flavor_id"
)
.
(
string
)
keyName
:=
state
.
Get
(
"keyPair"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
...
...
@@ -38,11 +38,12 @@ func (s *StepRunSourceServer) Run(state multistep.StateBag) multistep.StepAction
networks
[
i
]
.
UUID
=
networkUuid
}
ui
.
Say
(
"Launching server..."
)
s
.
server
,
err
=
servers
.
Create
(
computeClient
,
keypairs
.
CreateOptsExt
{
CreateOptsBuilder
:
servers
.
CreateOpts
{
Name
:
s
.
Name
,
ImageRef
:
s
.
SourceImage
,
Flavor
Name
:
s
.
F
lavor
,
Flavor
Ref
:
f
lavor
,
SecurityGroups
:
s
.
SecurityGroups
,
Networks
:
networks
,
},
...
...
@@ -56,9 +57,10 @@ func (s *StepRunSourceServer) Run(state multistep.StateBag) multistep.StepAction
return
multistep
.
ActionHalt
}
ui
.
Message
(
fmt
.
Sprintf
(
"Server ID: %s"
,
s
.
server
.
ID
))
log
.
Printf
(
"server id: %s"
,
s
.
server
.
ID
)
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting for server (%s) to become ready..."
,
s
.
server
.
ID
)
)
ui
.
Say
(
"Waiting for server to become ready..."
)
stateChange
:=
StateChangeConf
{
Pending
:
[]
string
{
"BUILD"
},
Target
:
"ACTIVE"
,
...
...
website/source/docs/builders/openstack.html.markdown
View file @
92b6b5c3
...
...
@@ -29,7 +29,7 @@ each category, the available configuration keys are alphabetized.
### Required:
*
`flavor`
(string) - The ID or full URL for the desired flavor for the
*
`flavor`
(string) - The ID
, name,
or full URL for the desired flavor for the
server to be created.
*
`image_name`
(string) - The name of the resulting image.
...
...
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