Skip to content

add environment parameter to stack #389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions samples/10_heat_stack_with_environment/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure('2') do |config|

config.vm.provider :openstack do |os, ov|
os.openstack_auth_url = ENV['OS_AUTH_URL']
os.tenant_name = ENV['OS_TENANT_NAME']
os.username = ENV['OS_USERNAME']
os.password = ENV['OS_PASSWORD']
os.floating_ip_pool = ENV['OS_FLOATING_IP_POOL']
os.flavor = ENV['OS_FLAVOR']
os.image = ENV['OS_IMAGE']
os.security_groups = ['sg']
os.networks << 'heat-net'
os.stacks << {name: 'vagrant', template: "#{File.dirname(__FILE__)}/stack.yml", environment: "#{File.dirname(__FILE__)}/environment.json" }

ov.nfs.functional = false
end

config.vm.define 'server-1' do |s|
s.vm.provider :openstack do |os, override|
os.server_name = '10_heat_stack_with_environment'
override.ssh.username = ENV['OS_SSH_USERNAME']
end
end
end
6 changes: 6 additions & 0 deletions samples/10_heat_stack_with_environment/environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parameters": {
"external_network_id": "ext-net",
"network_name": "my-great-network"
}
}
57 changes: 57 additions & 0 deletions samples/10_heat_stack_with_environment/stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
heat_template_version: 2013-05-23

description: >
Create a minimal infrastructure to spawn an instance

parameters:

external_network_id:
type: string
label: External network id
description: External network to connect the router
default: 5cccfde8-ddae-4feb-9a97-ca6532d1577f
network_name:
type: string
label: Network name
description: Network name
default: heat-net

resources:

security_group:
type: OS::Neutron::SecurityGroup
properties:
name: sg
description: Add security group rules for server
rules:
- remote_ip_prefix: 0.0.0.0/0
direction: ingress
- remote_ip_prefix: 0.0.0.0/0
direction: egress

network:
type: OS::Neutron::Net
properties:
name: { get_param: network_name }
subnet:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: network }
cidr: 10.0.0.0/24
allocation_pools:
- { start: 10.0.0.100, end: 10.0.0.250 }

router:
type: OS::Neutron::Router
properties:
name: router
router-gateway:
type: OS::Neutron::RouterGateway
properties:
router_id: { get_resource: router }
network_id: { get_param: external_network_id }
router-dataplane-int:
type: OS::Neutron::RouterInterface
properties:
router_id: { get_resource: router }
subnet_id: { get_resource: subnet }
5 changes: 4 additions & 1 deletion source/lib/vagrant-openstack-provider/action/create_stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'timeout'
require 'sshkey'
require 'yaml'
require 'json'

require 'vagrant-openstack-provider/config_resolver'
require 'vagrant-openstack-provider/utils'
Expand Down Expand Up @@ -36,10 +37,12 @@ def execute(env)
env[:ui].info(I18n.t('vagrant_openstack.create_stack'))
env[:ui].info(" -- Stack Name : #{stack[:name]}")
env[:ui].info(" -- Template : #{stack[:template]}")
env[:ui].info(" -- Environment : #{stack[:environment]}")

create_opts = {
name: stack[:name],
template: YAML.load_file(stack[:template])
template: YAML.load_file(stack[:template]),
environment: stack[:environment] ? JSON.parse(File.read(stack[:environment])) : nil
}

stack_id = heat.create_stack(env, create_opts)
Expand Down
1 change: 1 addition & 0 deletions source/lib/vagrant-openstack-provider/client/heat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def create_stack(env, options)
stack = {}.tap do |s|
s['stack_name'] = options[:name] if options[:name]
s['template'] = options[:template]
s['environment'] = options[:environment]
end
stack_res = post(env, "#{@session.endpoints[:orchestration]}/stacks", stack.to_json)
JSON.parse(stack_res)['stack']['id']
Expand Down