From c00696992abe62ec9ccd411a1791c9b6305d3687 Mon Sep 17 00:00:00 2001 From: Ian Delahorne Date: Sun, 15 Jun 2014 13:56:19 -0500 Subject: [PATCH 1/2] Add ability to configure networks for openstack Add configuration option `networks`, a list of network UUIDs, to attach to the source instance. In some openstack installs, no default network will be attached or the network with the ability to attach a public floating IP will need to be specified. --- builder/openstack/builder.go | 1 + builder/openstack/run_config.go | 1 + builder/openstack/step_run_source_server.go | 7 +++++++ website/source/docs/builders/openstack.html.markdown | 2 ++ 4 files changed, 11 insertions(+) diff --git a/builder/openstack/builder.go b/builder/openstack/builder.go index 93dd18520..a4b4eea19 100644 --- a/builder/openstack/builder.go +++ b/builder/openstack/builder.go @@ -92,6 +92,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Flavor: b.config.Flavor, SourceImage: b.config.SourceImage, SecurityGroups: b.config.SecurityGroups, + Networks: b.config.Networks, }, &StepAllocateIp{ FloatingIpPool: b.config.FloatingIpPool, diff --git a/builder/openstack/run_config.go b/builder/openstack/run_config.go index d59849b96..a1ca0f0ae 100644 --- a/builder/openstack/run_config.go +++ b/builder/openstack/run_config.go @@ -20,6 +20,7 @@ type RunConfig struct { FloatingIpPool string `mapstructure:"floating_ip_pool"` FloatingIp string `mapstructure:"floating_ip"` SecurityGroups []string `mapstructure:"security_groups"` + Networks []string `mapstructure:"networks"` // Unexported fields that are calculated from others sshTimeout time.Duration diff --git a/builder/openstack/step_run_source_server.go b/builder/openstack/step_run_source_server.go index 09062b4e6..a9bd5433b 100644 --- a/builder/openstack/step_run_source_server.go +++ b/builder/openstack/step_run_source_server.go @@ -13,6 +13,7 @@ type StepRunSourceServer struct { Name string SourceImage string SecurityGroups []string + Networks []string server *gophercloud.Server } @@ -30,12 +31,18 @@ func (s *StepRunSourceServer) Run(state multistep.StateBag) multistep.StepAction securityGroups[i]["name"] = groupName } + networks := make([]gophercloud.NetworkConfig, len(s.Networks)) + for i, networkUuid := range s.Networks { + networks[i].Uuid = networkUuid + } + server := gophercloud.NewServer{ Name: s.Name, ImageRef: s.SourceImage, FlavorRef: s.Flavor, KeyPairName: keyName, SecurityGroup: securityGroups, + Networks: networks, } serverResp, err := csp.CreateServer(server) diff --git a/website/source/docs/builders/openstack.html.markdown b/website/source/docs/builders/openstack.html.markdown index 130c7a7d9..b144dffeb 100644 --- a/website/source/docs/builders/openstack.html.markdown +++ b/website/source/docs/builders/openstack.html.markdown @@ -89,6 +89,8 @@ each category, the available configuration keys are alphabetized. +* `networks` (array of strings) - A list of networks by UUID to attach + to this instance. * `security_groups` (array of strings) - A list of security groups by name to add to this instance. From d99eff49f7aed83ca8645cbd2b92618097f22eb5 Mon Sep 17 00:00:00 2001 From: Ian Delahorne Date: Sun, 15 Jun 2014 18:46:02 -0500 Subject: [PATCH 2/2] Reorder documentation into alphabetical order --- website/source/docs/builders/openstack.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/source/docs/builders/openstack.html.markdown b/website/source/docs/builders/openstack.html.markdown index b144dffeb..613e03ff0 100644 --- a/website/source/docs/builders/openstack.html.markdown +++ b/website/source/docs/builders/openstack.html.markdown @@ -69,6 +69,9 @@ each category, the available configuration keys are alphabetized. * `insecure` (boolean) - Whether or not the connection to OpenStack can be done over an insecure connection. By default this is false. +* `networks` (array of strings) - A list of networks by UUID to attach + to this instance. + * `openstack_provider` (string) -* `networks` (array of strings) - A list of networks by UUID to attach - to this instance. - * `security_groups` (array of strings) - A list of security groups by name to add to this instance.