Ruby styling/organization fixes.
Change-Id: I8db03eae74abe72077813a18f8dafec91519eb5f Signed-off-by: Sean Handley <sean.handley@gmail.com>
This commit is contained in:
parent
f7adfac071
commit
c0d164ce19
@ -1,64 +1,56 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
require 'fog'
|
require 'fog/openstack'
|
||||||
|
|
||||||
# step-1
|
# step-1
|
||||||
auth_username = "your_auth_username"
|
auth_username = "your_auth_username"
|
||||||
auth_password = "your_auth_password"
|
auth_password = "your_auth_password"
|
||||||
auth_url = "http://controller:5000"
|
auth_url = "http://controller:5000"
|
||||||
project_name = "your_project_name_or_id"
|
project_name = "your_project_name_or_id"
|
||||||
|
|
||||||
conn = Fog::Compute::OpenStack.new({
|
conn = Fog::Compute::OpenStack.new openstack_auth_url: auth_url + "/v3/auth/tokens",
|
||||||
openstack_auth_url: auth_url + "/v3/auth/tokens",
|
openstack_domain_id: "default",
|
||||||
openstack_domain_id: "default",
|
openstack_username: auth_username,
|
||||||
openstack_username: auth_username,
|
openstack_api_key: auth_password,
|
||||||
openstack_api_key: auth_password,
|
openstack_project_name: project_name
|
||||||
openstack_project_name: project_name
|
|
||||||
})
|
|
||||||
|
|
||||||
# step-2
|
# step-2
|
||||||
volume = conn.volumes.create({
|
volume = conn.volumes.create name: "test",
|
||||||
name: "test",
|
description: "",
|
||||||
description: "",
|
size: 1
|
||||||
size: 1
|
|
||||||
})
|
|
||||||
p volume
|
p volume
|
||||||
|
|
||||||
# step-3
|
# step-3
|
||||||
p conn.volumes.summary
|
p conn.volumes.summary
|
||||||
|
|
||||||
# step-4
|
# step-4
|
||||||
db_group = conn.security_groups.create({
|
db_group = conn.security_groups.create name: "database",
|
||||||
name: "database",
|
description: "for database service"
|
||||||
description: "for database service"
|
|
||||||
})
|
conn.security_group_rules.create parent_group_id: db_group.id,
|
||||||
conn.security_group_rules.create({
|
ip_protocol: "tcp",
|
||||||
parent_group_id: db_group.id,
|
from_port: 3306,
|
||||||
ip_protocol: "tcp",
|
to_port: 3306
|
||||||
from_port: 3306,
|
|
||||||
to_port: 3306
|
instance = conn.servers.create name: "app-database",
|
||||||
})
|
image_ref: image.id,
|
||||||
instance = conn.servers.create({
|
flavor_ref: flavor.id,
|
||||||
name: "app-database",
|
key_name: key_pair.name,
|
||||||
image_ref: image.id,
|
security_groups: db_group
|
||||||
flavor_ref: flavor.id,
|
|
||||||
key_name: key_pair.name,
|
Fog.wait_for { instance.ready? }
|
||||||
security_groups: db_group
|
|
||||||
})
|
|
||||||
Fog.wait_for {instance.ready?}
|
|
||||||
|
|
||||||
# step-5
|
# step-5
|
||||||
volume = conn.volumes.get("755ab026-b5f2-4f53-b34a-6d082fb36689")
|
volume = conn.volumes.get "755ab026-b5f2-4f53-b34a-6d082fb36689"
|
||||||
instance.attach_volume(volume.id, "/dev/vdb")
|
instance.attach_volume volume.id, "/dev/vdb"
|
||||||
|
|
||||||
# step-6
|
# step-6
|
||||||
instance.detach_volume(volume.id)
|
instance.detach_volume volume.id
|
||||||
volume.destroy
|
volume.destroy
|
||||||
|
|
||||||
# step-7
|
# step-7
|
||||||
conn.snapshots.create({
|
conn.snapshots.create volume_id: volume.id,
|
||||||
volume_id: volume.id,
|
name: "test_backup_1",
|
||||||
name: "test_backup_1",
|
description: "test"
|
||||||
description: "test"
|
|
||||||
})
|
|
||||||
|
|
||||||
# step-8
|
# step-8
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
require 'fog'
|
require 'fog/openstack'
|
||||||
require 'digest/md5'
|
require 'digest/md5'
|
||||||
require 'net/http'
|
require 'net/http'
|
||||||
require 'json'
|
require 'json'
|
||||||
@ -7,41 +7,36 @@ require 'json'
|
|||||||
# step-1
|
# step-1
|
||||||
auth_username = "your_auth_username"
|
auth_username = "your_auth_username"
|
||||||
auth_password = "your_auth_password"
|
auth_password = "your_auth_password"
|
||||||
auth_url = "http://controller:5000"
|
auth_url = "http://controller:5000"
|
||||||
project_name = "your_project_name_or_id"
|
project_name = "your_project_name_or_id"
|
||||||
|
|
||||||
swift = Fog::Storage::OpenStack.new({
|
swift = Fog::Storage::OpenStack.new openstack_auth_url: auth_url + "/v3/auth/tokens",
|
||||||
openstack_auth_url: auth_url + "/v3/auth/tokens",
|
openstack_domain_id: "default",
|
||||||
openstack_domain_id: "default",
|
openstack_username: auth_username,
|
||||||
openstack_username: auth_username,
|
openstack_api_key: auth_password,
|
||||||
openstack_api_key: auth_password,
|
openstack_project_name: project_name
|
||||||
openstack_project_name: project_name
|
|
||||||
})
|
|
||||||
|
|
||||||
# step-2
|
# step-2
|
||||||
container_name = "fractals"
|
container_name = "fractals"
|
||||||
container = swift.directories.create({
|
container = swift.directories.create key: container_name
|
||||||
key: container_name
|
|
||||||
})
|
|
||||||
p container
|
p container
|
||||||
|
|
||||||
# step-3
|
# step-3
|
||||||
p swift.directories.all
|
p swift.directories.all
|
||||||
|
|
||||||
# step-4
|
# step-4
|
||||||
file_path = "goat.jpg"
|
file_path = "goat.jpg"
|
||||||
object_name = "an amazing goat"
|
object_name = "an amazing goat"
|
||||||
container = swift.direcories.get(container_name)
|
container = swift.direcories.get container_name
|
||||||
object = container.files.create({
|
object = container.files.create body: File.read(File.expand_path(file_path)),
|
||||||
body: File.read(File.expand_path(file_path)),
|
key: object_name
|
||||||
key: object_name
|
|
||||||
})
|
|
||||||
|
|
||||||
# step-5
|
# step-5
|
||||||
p container.files.all
|
p container.files.all
|
||||||
|
|
||||||
# step-6
|
# step-6
|
||||||
p container.files.get(object_name)
|
p container.files.get object_name
|
||||||
|
|
||||||
# step-7
|
# step-7
|
||||||
puts Digest::MD5.hexdigest(File.read(File.expand_path(file_path)))
|
puts Digest::MD5.hexdigest(File.read(File.expand_path(file_path)))
|
||||||
@ -55,12 +50,11 @@ p container.files.all
|
|||||||
# step-10
|
# step-10
|
||||||
|
|
||||||
# step-11
|
# step-11
|
||||||
endpoint = "http://IP_API_1"
|
endpoint = "http://IP_API_1"
|
||||||
uri = URI("#{endpoint}/v1/fractal")
|
uri = URI("#{endpoint}/v1/fractal")
|
||||||
uri.query = URI.encode_www_form({
|
uri.query = URI.encode_www_form results_per_page: -1
|
||||||
results_per_page: -1
|
data = JSON.parse(Net::HTTP.get_response(uri).body)
|
||||||
})
|
|
||||||
data = JSON.parse(Net::HTTP.get_response(uri).body)
|
|
||||||
data["objects"].each do |fractal|
|
data["objects"].each do |fractal|
|
||||||
uri = URI("#{endpoint}/fractal/#{fractal["uuid"]}")
|
uri = URI("#{endpoint}/fractal/#{fractal["uuid"]}")
|
||||||
#TBC
|
#TBC
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
require 'fog'
|
require 'fog/openstack'
|
||||||
|
|
||||||
# step-1
|
# step-1
|
||||||
auth_username = "your_auth_username"
|
auth_username = "your_auth_username"
|
||||||
auth_password = "your_auth_password"
|
auth_password = "your_auth_password"
|
||||||
auth_url = "http://controller:5000"
|
auth_url = "http://controller:5000"
|
||||||
project_name = "your_project_name_or_id"
|
project_name = "your_project_name_or_id"
|
||||||
|
|
||||||
conn = Fog::Compute::OpenStack.new({
|
conn = Fog::Compute::OpenStack.new openstack_auth_url: auth_url + "/v3/auth/tokens",
|
||||||
openstack_auth_url: auth_url + "/v3/auth/tokens",
|
openstack_domain_id: "default",
|
||||||
openstack_domain_id: "default",
|
openstack_username: auth_username,
|
||||||
openstack_username: auth_username,
|
openstack_api_key: auth_password,
|
||||||
openstack_api_key: auth_password,
|
openstack_project_name: project_name
|
||||||
openstack_project_name: project_name
|
|
||||||
})
|
|
||||||
|
|
||||||
# step-2
|
# step-2
|
||||||
p conn.images.summary
|
p conn.images.summary
|
||||||
@ -22,20 +20,19 @@ p conn.images.summary
|
|||||||
p conn.flavors.summary
|
p conn.flavors.summary
|
||||||
|
|
||||||
# step-4
|
# step-4
|
||||||
image = conn.images.get("2cccbea0-cea9-4f86-a3ed-065c652adda5")
|
image = conn.images.get "2cccbea0-cea9-4f86-a3ed-065c652adda5"
|
||||||
p image
|
p image
|
||||||
|
|
||||||
# step-5
|
# step-5
|
||||||
flavor = conn.flavors.get("2")
|
flavor = conn.flavors.get "2"
|
||||||
p flavor
|
p flavor
|
||||||
|
|
||||||
# step-6
|
# step-6
|
||||||
instance_name = "testing"
|
instance_name = "testing"
|
||||||
testing_instance = conn.servers.create({
|
testing_instance = conn.servers.create name: instance_name,
|
||||||
name: instance_name,
|
image_ref: image.id,
|
||||||
image_ref: image.id,
|
flavor_ref: flavor.id
|
||||||
flavor_ref: flavor.id
|
|
||||||
})
|
|
||||||
Fog.wait_for {testing_instance.ready?}
|
Fog.wait_for {testing_instance.ready?}
|
||||||
|
|
||||||
p testing_instance
|
p testing_instance
|
||||||
@ -48,17 +45,15 @@ testing_instance.destroy
|
|||||||
|
|
||||||
# step-9
|
# step-9
|
||||||
puts "Checking for existing SSH key pair..."
|
puts "Checking for existing SSH key pair..."
|
||||||
key_pair_name = "demokey"
|
key_pair_name = "demokey"
|
||||||
pub_key_file_path = "~/.ssh/id_rsa.pub"
|
pub_key_file_path = "~/.ssh/id_rsa.pub"
|
||||||
|
|
||||||
if key_pair = conn.key_pairs.get(key_pair_name)
|
if key_pair = conn.key_pairs.get(key_pair_name)
|
||||||
puts "Keypair #{key_pair_name} already exists. Skipping import."
|
puts "Keypair #{key_pair_name} already exists. Skipping import."
|
||||||
else
|
else
|
||||||
puts "adding keypair..."
|
puts "adding keypair..."
|
||||||
key_pair = conn.key_pairs.create({
|
key_pair = conn.key_pairs.create name: key_pair_name,
|
||||||
name: key_pair_name,
|
public_key: File.read(File.expand_path(pub_key_file_path))
|
||||||
public_key: File.read(File.expand_path(pub_key_file_path))
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
p conn.key_pairs.all
|
p conn.key_pairs.all
|
||||||
@ -67,25 +62,26 @@ p conn.key_pairs.all
|
|||||||
puts "Checking for existing security group..."
|
puts "Checking for existing security group..."
|
||||||
security_group_name = "all-in-one"
|
security_group_name = "all-in-one"
|
||||||
|
|
||||||
if all_in_one_security_group = conn.security_groups.find {|security_group| security_group.name == security_group_name}
|
all_in_one_security_group = conn.security_groups.find do |security_group|
|
||||||
|
security_group.name == security_group_name
|
||||||
|
end
|
||||||
|
|
||||||
|
if all_in_one_security_group
|
||||||
puts "Security Group #{security_group_name} already exists. Skipping creation."
|
puts "Security Group #{security_group_name} already exists. Skipping creation."
|
||||||
else
|
else
|
||||||
all_in_one_security_group = conn.security_groups.create({
|
all_in_one_security_group = conn.security_groups.create name: security_group_name,
|
||||||
name: security_group_name,
|
description: "network access for all-in-one application."
|
||||||
description: "network access for all-in-one application."
|
|
||||||
})
|
conn.security_group_rules.create parent_group_id: all_in_one_security_group.id,
|
||||||
conn.security_group_rules.create({
|
ip_protocol: "tcp",
|
||||||
parent_group_id: all_in_one_security_group.id,
|
from_port: 80,
|
||||||
ip_protocol: "tcp",
|
to_port: 80
|
||||||
from_port: 80,
|
|
||||||
to_port: 80
|
conn.security_group_rules.create parent_group_id: all_in_one_security_group.id,
|
||||||
})
|
ip_protocol: "tcp",
|
||||||
conn.security_group_rules.create({
|
from_port: 22,
|
||||||
parent_group_id: all_in_one_security_group.id,
|
to_port: 22
|
||||||
ip_protocol: "tcp",
|
|
||||||
from_port: 22,
|
|
||||||
to_port: 22
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
p conn.security_groups.all
|
p conn.security_groups.all
|
||||||
@ -104,33 +100,30 @@ instance_name = "all-in-one"
|
|||||||
if testing_instance = conn.servers.find {|instance| instance.name == instance_name}
|
if testing_instance = conn.servers.find {|instance| instance.name == instance_name}
|
||||||
puts "Instance #{instance_name} already exists. Skipping creation."
|
puts "Instance #{instance_name} already exists. Skipping creation."
|
||||||
else
|
else
|
||||||
testing_instance = conn.servers.create({
|
testing_instance = conn.servers.create name: instance_name,
|
||||||
name: instance_name,
|
image_ref: image.id,
|
||||||
image_ref: image.id,
|
flavor_ref: flavor.id,
|
||||||
flavor_ref: flavor.id,
|
key_name: key_pair.name,
|
||||||
key_name: key_pair.name,
|
user_data: user_data,
|
||||||
user_data: user_data,
|
security_groups: all_in_one_security_group
|
||||||
security_groups: all_in_one_security_group
|
|
||||||
})
|
|
||||||
Fog.wait_for {testing_instance.ready?}
|
Fog.wait_for {testing_instance.ready?}
|
||||||
end
|
end
|
||||||
|
|
||||||
p conn.servers.summary
|
p conn.servers.summary
|
||||||
|
|
||||||
# step-13
|
# step-13
|
||||||
puts "Private IP found: #{private_ip_address}" if private_ip_address ||= testing_instance.private_ip_address
|
puts "Private IP found: #{private_ip_address}" if private_ip_address = testing_instance.private_ip_address
|
||||||
|
|
||||||
# step-14
|
# step-14
|
||||||
puts "Public IP found: #{floating_ip_address}" if floating_ip_address ||= testing_instance.floating_ip_address
|
puts "Public IP found: #{floating_ip_address}" if floating_ip_address = testing_instance.floating_ip_address
|
||||||
|
|
||||||
# step-15
|
# step-15
|
||||||
puts "Checking for unused Floating IP..."
|
puts "Checking for unused Floating IP..."
|
||||||
unless unused_floating_ip_address = conn.addresses.find {|address| address.instance_id.nil?}
|
unless unused_floating_ip_address = conn.addresses.find {|address| address.instance_id.nil?}
|
||||||
pool_name = conn.addresses.get_address_pools[0]["name"]
|
pool_name = conn.addresses.get_address_pools[0]["name"]
|
||||||
puts "Allocating new Floating IP from pool: #{pool_name}"
|
puts "Allocating new Floating IP from pool: #{pool_name}"
|
||||||
unused_floating_ip_address = conn.addresses.create({
|
unused_floating_ip_address = conn.addresses.create pool: pool_name
|
||||||
pool: pool_name
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# step-16
|
# step-16
|
||||||
|
@ -5,15 +5,14 @@ curl -L -s http://git.openstack.org/cgit/openstack/faafo/plain/contrib/install.s
|
|||||||
-i faafo -i messaging -r api -r worker -r demo
|
-i faafo -i messaging -r api -r worker -r demo
|
||||||
END
|
END
|
||||||
|
|
||||||
instance_name = "all-in-one"
|
instance_name = "all-in-one"
|
||||||
testing_instance = conn.servers.create({
|
testing_instance = conn.servers.create name: instance_name,
|
||||||
name: instance_name,
|
image_ref: image.id,
|
||||||
image_ref: image.id,
|
flavor_ref: flavor.id,
|
||||||
flavor_ref: flavor.id,
|
key_name: key_pair.name,
|
||||||
key_name: key_pair.name,
|
user_data: user_data,
|
||||||
user_data: user_data,
|
security_groups: all_in_one_security_group
|
||||||
security_groups: all_in_one_security_group
|
|
||||||
})
|
|
||||||
Fog.wait_for {testing_instance.ready?}
|
Fog.wait_for {testing_instance.ready?}
|
||||||
|
|
||||||
# step-2
|
# step-2
|
||||||
@ -24,22 +23,18 @@ curl -L -s http://git.openstack.org/cgit/openstack/faafo/plain/contrib/install.s
|
|||||||
END
|
END
|
||||||
|
|
||||||
# step-3
|
# step-3
|
||||||
all_in_one_security_group = conn.security_groups.create({
|
all_in_one_security_group = conn.security_groups.create name: "all-in-one",
|
||||||
name: "all-in-one",
|
description: "network access for all-in-one application."
|
||||||
description: "network access for all-in-one application."
|
|
||||||
})
|
conn.security_group_rules.create parent_group_id: all_in_one_security_group.id,
|
||||||
conn.security_group_rules.create({
|
ip_protocol: "tcp",
|
||||||
parent_group_id: all_in_one_security_group.id,
|
from_port: 80,
|
||||||
ip_protocol: "tcp",
|
to_port: 80
|
||||||
from_port: 80,
|
|
||||||
to_port: 80
|
conn.security_group_rules.create parent_group_id: all_in_one_security_group.id,
|
||||||
})
|
ip_protocol: "tcp",
|
||||||
conn.security_group_rules.create({
|
from_port: 22,
|
||||||
parent_group_id: all_in_one_security_group.id,
|
to_port: 22
|
||||||
ip_protocol: "tcp",
|
|
||||||
from_port: 22,
|
|
||||||
to_port: 22
|
|
||||||
})
|
|
||||||
|
|
||||||
# step-4
|
# step-4
|
||||||
conn.security_groups.all
|
conn.security_groups.all
|
||||||
@ -58,48 +53,38 @@ puts "Found an unused Floating IP: #{unused_floating_ip_address.ip}" if unused_f
|
|||||||
pool_name = conn.addresses.get_address_pools[0]["name"]
|
pool_name = conn.addresses.get_address_pools[0]["name"]
|
||||||
|
|
||||||
# step-9
|
# step-9
|
||||||
unused_floating_ip_address = conn.addresses.create({
|
unused_floating_ip_address = conn.addresses.create pool: pool_name
|
||||||
pool: pool_name
|
|
||||||
})
|
|
||||||
|
|
||||||
# step-10
|
# step-10
|
||||||
unused_floating_ip_address.server = instance
|
unused_floating_ip_address.server = instance
|
||||||
|
|
||||||
# step-11
|
# step-11
|
||||||
worker_group = conn.security_groups.create({
|
worker_group = conn.security_groups.create name: "worker",
|
||||||
name: "worker",
|
description: "for services that run on a worker node"
|
||||||
description: "for services that run on a worker node"
|
|
||||||
})
|
|
||||||
conn.security_group_rules.create({
|
|
||||||
parent_group_id: worker_group.id,
|
|
||||||
ip_protocol: "tcp",
|
|
||||||
from_port: 22,
|
|
||||||
to_port: 22
|
|
||||||
})
|
|
||||||
|
|
||||||
controller_group = conn.security_groups.create({
|
conn.security_group_rules.create parent_group_id: worker_group.id,
|
||||||
name: "control",
|
ip_protocol: "tcp",
|
||||||
description: "for services that run on a control node"
|
from_port: 22,
|
||||||
})
|
to_port: 22
|
||||||
conn.security_group_rules.create({
|
|
||||||
parent_group_id: controller_group.id,
|
controller_group = conn.security_groups.create name: "control",
|
||||||
ip_protocol: "tcp",
|
description: "for services that run on a control node"
|
||||||
from_port: 22,
|
|
||||||
to_port: 22
|
conn.security_group_rules.create parent_group_id: controller_group.id,
|
||||||
})
|
ip_protocol: "tcp",
|
||||||
conn.security_group_rules.create({
|
from_port: 22,
|
||||||
parent_group_id: controller_group.id,
|
to_port: 22
|
||||||
ip_protocol: "tcp",
|
|
||||||
from_port: 80,
|
conn.security_group_rules.create parent_group_id: controller_group.id,
|
||||||
to_port: 80
|
ip_protocol: "tcp",
|
||||||
})
|
from_port: 80,
|
||||||
conn.security_group_rules.create({
|
to_port: 80
|
||||||
parent_group_id: controller_group.id,
|
|
||||||
ip_protocol: "tcp",
|
conn.security_group_rules.create parent_group_id: controller_group.id,
|
||||||
from_port: 5672,
|
ip_protocol: "tcp",
|
||||||
to_port: 5672,
|
from_port: 5672,
|
||||||
group: worker_group.id
|
to_port: 5672,
|
||||||
})
|
group: worker_group.id
|
||||||
|
|
||||||
user_data = <<END
|
user_data = <<END
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
@ -107,23 +92,20 @@ curl -L -s http://git.openstack.org/cgit/openstack/faafo/plain/contrib/install.s
|
|||||||
-i messaging -i faafo -r api
|
-i messaging -i faafo -r api
|
||||||
END
|
END
|
||||||
|
|
||||||
instance_controller_1 = conn.servers.create({
|
instance_controller_1 = conn.servers.create name: "app-controller",
|
||||||
name: "app-controller",
|
image_ref: image.id,
|
||||||
image_ref: image.id,
|
flavor_ref: flavor.id,
|
||||||
flavor_ref: flavor.id,
|
key_name: "demokey",
|
||||||
key_name: "demokey",
|
user_data: user_data,
|
||||||
user_data: user_data,
|
security_groups: controller_group
|
||||||
security_groups: controller_group
|
|
||||||
})
|
|
||||||
Fog.wait_for {instance_controller_1.ready?}
|
Fog.wait_for {instance_controller_1.ready?}
|
||||||
|
|
||||||
puts "Checking for unused Floating IP..."
|
puts "Checking for unused Floating IP..."
|
||||||
unless unused_floating_ip_address = conn.addresses.find {|address| address.instance_id.nil?}
|
unless unused_floating_ip_address = conn.addresses.find {|address| address.instance_id.nil?}
|
||||||
pool_name = conn.addresses.get_address_pools[0]["name"]
|
pool_name = conn.addresses.get_address_pools[0]["name"]
|
||||||
puts "Allocating new Floating IP from pool: #{pool_name}"
|
puts "Allocating new Floating IP from pool: #{pool_name}"
|
||||||
unused_floating_ip_address = conn.addresses.create({
|
unused_floating_ip_address = conn.addresses.create pool: pool_name
|
||||||
pool: pool_name
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
unused_floating_ip_address.server = instance_controller_1
|
unused_floating_ip_address.server = instance_controller_1
|
||||||
@ -131,7 +113,7 @@ puts "Application will be deployed to http://#{unused_floating_ip_address.ip}"
|
|||||||
|
|
||||||
# step-12
|
# step-12
|
||||||
instance_controller_1 = conn.servers.get(instance_controller_1.id)
|
instance_controller_1 = conn.servers.get(instance_controller_1.id)
|
||||||
ip_controller = instance_controller_1.floating_ip_address ? instance_controller_1.private_ip_address : instance_controller_1.floating_ip_address
|
ip_controller = instance_controller_1.private_ip_address || instance_controller_1.floating_ip_address
|
||||||
|
|
||||||
user_data = <<END
|
user_data = <<END
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
@ -139,23 +121,20 @@ curl -L -s http://git.openstack.org/cgit/openstack/faafo/plain/contrib/install.s
|
|||||||
-i faafo -r worker -e "http://#{ip_controller}" -m "amqp://guest:guest@#{ip_controller}:5672/"
|
-i faafo -r worker -e "http://#{ip_controller}" -m "amqp://guest:guest@#{ip_controller}:5672/"
|
||||||
END
|
END
|
||||||
|
|
||||||
instance_worker_1 = conn.servers.create({
|
instance_worker_1 = conn.servers.create name: "app-worker-1",
|
||||||
name: "app-worker-1",
|
image_ref: image.id,
|
||||||
image_ref: image.id,
|
flavor_ref: flavor.id,
|
||||||
flavor_ref: flavor.id,
|
key_name: "demokey",
|
||||||
key_name: "demokey",
|
user_data: user_data,
|
||||||
user_data: user_data,
|
security_groups: worker_group
|
||||||
security_groups: worker_group
|
|
||||||
})
|
|
||||||
Fog.wait_for {instance_worker_1.ready?}
|
Fog.wait_for {instance_worker_1.ready?}
|
||||||
|
|
||||||
puts "Checking for unused Floating IP..."
|
puts "Checking for unused Floating IP..."
|
||||||
unless unused_floating_ip_address = conn.addresses.find {|address| address.instance_id.nil?}
|
unless unused_floating_ip_address = conn.addresses.find {|address| address.instance_id.nil?}
|
||||||
pool_name = conn.addresses.get_address_pools[0]["name"]
|
pool_name = conn.addresses.get_address_pools[0]["name"]
|
||||||
puts "Allocating new Floating IP from pool: #{pool_name}"
|
puts "Allocating new Floating IP from pool: #{pool_name}"
|
||||||
unused_floating_ip_address = conn.addresses.create({
|
unused_floating_ip_address = conn.addresses.create pool: pool_name
|
||||||
pool: pool_name
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
unused_floating_ip_address.server = instance_worker_1
|
unused_floating_ip_address.server = instance_worker_1
|
||||||
|
@ -1,107 +1,105 @@
|
|||||||
# step-1
|
# step-1
|
||||||
conn.servers.select {|instance| ["all-in-one","app-worker-1", "app-worker-2", "app-controller"].include?(instance.name)}.each do |instance|
|
instance_names = ["all-in-one","app-worker-1", "app-worker-2", "app-controller"]
|
||||||
|
|
||||||
|
conn.servers.select {|instance| instance_names.include?(instance.name)}.each do |instance|
|
||||||
puts "Destroying Instance: #{instance.name}"
|
puts "Destroying Instance: #{instance.name}"
|
||||||
instance.destroy
|
instance.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
conn.security_groups.select {|security_group| ["control", "worker", "api", "services"].include?(security_group.name)}.each do |security_group|
|
security_group_names = ["control", "worker", "api", "services"]
|
||||||
|
|
||||||
|
conn.security_groups.select {|security_group| security_group_names.include?(security_group.name)}.each do |security_group|
|
||||||
puts "Deleting security group: #{security_group.name}"
|
puts "Deleting security group: #{security_group.name}"
|
||||||
security_group.destroy
|
security_group.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
# step-2
|
# step-2
|
||||||
api_group = conn.security_groups.create({
|
api_group = conn.security_groups.create name: "api",
|
||||||
name: "api",
|
description: "for API services only"
|
||||||
description: "for API services only"
|
|
||||||
})
|
|
||||||
conn.security_group_rules.create({
|
|
||||||
parent_group_id: api_group.id,
|
|
||||||
ip_protocol: "tcp",
|
|
||||||
from_port: 80,
|
|
||||||
to_port: 80
|
|
||||||
})
|
|
||||||
conn.security_group_rules.create({
|
|
||||||
parent_group_id: api_group.id,
|
|
||||||
ip_protocol: "tcp",
|
|
||||||
from_port: 22,
|
|
||||||
to_port: 22
|
|
||||||
})
|
|
||||||
|
|
||||||
worker_group = conn.security_groups.create({
|
worker_group = conn.security_groups.create name: "worker",
|
||||||
name: "worker",
|
description: "for services that run on a worker node"
|
||||||
description: "for services that run on a worker node"
|
|
||||||
})
|
|
||||||
conn.security_group_rules.create({
|
|
||||||
parent_group_id: worker_group.id,
|
|
||||||
ip_protocol: "tcp",
|
|
||||||
from_port: 22,
|
|
||||||
to_port: 22
|
|
||||||
})
|
|
||||||
|
|
||||||
controller_group = conn.security_groups.create({
|
controller_group = conn.security_groups.create name: "control",
|
||||||
name: "control",
|
description: "for services that run on a control node"
|
||||||
description: "for services that run on a control node"
|
|
||||||
})
|
|
||||||
conn.security_group_rules.create({
|
|
||||||
parent_group_id: controller_group.id,
|
|
||||||
ip_protocol: "tcp",
|
|
||||||
from_port: 22,
|
|
||||||
to_port: 22
|
|
||||||
})
|
|
||||||
conn.security_group_rules.create({
|
|
||||||
parent_group_id: controller_group.id,
|
|
||||||
ip_protocol: "tcp",
|
|
||||||
from_port: 80,
|
|
||||||
to_port: 80
|
|
||||||
})
|
|
||||||
conn.security_group_rules.create({
|
|
||||||
parent_group_id: controller_group.id,
|
|
||||||
ip_protocol: "tcp",
|
|
||||||
from_port: 5672,
|
|
||||||
to_port: 5672,
|
|
||||||
group: worker_group.id
|
|
||||||
})
|
|
||||||
|
|
||||||
services_group = conn.security_groups.create({
|
services_group = conn.security_groups.create name: "services",
|
||||||
name: "services",
|
|
||||||
description: "for DB and AMQP services only"
|
description: "for DB and AMQP services only"
|
||||||
})
|
|
||||||
conn.security_group_rules.create({
|
rules = [
|
||||||
parent_group_id: services_group.id,
|
{
|
||||||
ip_protocol: "tcp",
|
parent_group_id: api_group.id,
|
||||||
from_port: 22,
|
ip_protocol: "tcp",
|
||||||
to_port: 22
|
from_port: 80,
|
||||||
})
|
to_port: 80
|
||||||
conn.security_group_rules.create({
|
},
|
||||||
parent_group_id: services_group.id,
|
{
|
||||||
ip_protocol: "tcp",
|
parent_group_id: api_group.id,
|
||||||
from_port: 3306,
|
ip_protocol: "tcp",
|
||||||
to_port: 3306,
|
from_port: 22,
|
||||||
group: api_group.id
|
to_port: 22
|
||||||
})
|
},
|
||||||
conn.security_group_rules.create({
|
{
|
||||||
parent_group_id: services_group.id,
|
parent_group_id: worker_group.id,
|
||||||
ip_protocol: "tcp",
|
ip_protocol: "tcp",
|
||||||
from_port: 5672,
|
from_port: 22,
|
||||||
to_port: 5672,
|
to_port: 22
|
||||||
group: worker_group.id
|
},
|
||||||
})
|
{
|
||||||
conn.security_group_rules.create({
|
parent_group_id: controller_group.id,
|
||||||
parent_group_id: services_group.id,
|
ip_protocol: "tcp",
|
||||||
ip_protocol: "tcp",
|
from_port: 22,
|
||||||
from_port: 5672,
|
to_port: 22
|
||||||
to_port: 5672,
|
},
|
||||||
group: api_group.id
|
{
|
||||||
})
|
parent_group_id: controller_group.id,
|
||||||
|
ip_protocol: "tcp",
|
||||||
|
from_port: 80,
|
||||||
|
to_port: 80
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parent_group_id: controller_group.id,
|
||||||
|
ip_protocol: "tcp",
|
||||||
|
from_port: 5672,
|
||||||
|
to_port: 5672,
|
||||||
|
group: worker_group.id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parent_group_id: services_group.id,
|
||||||
|
ip_protocol: "tcp",
|
||||||
|
from_port: 22,
|
||||||
|
to_port: 22
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parent_group_id: services_group.id,
|
||||||
|
ip_protocol: "tcp",
|
||||||
|
from_port: 3306,
|
||||||
|
to_port: 3306,
|
||||||
|
group: api_group.id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parent_group_id: services_group.id,
|
||||||
|
ip_protocol: "tcp",
|
||||||
|
from_port: 5672,
|
||||||
|
to_port: 5672,
|
||||||
|
group: worker_group.id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parent_group_id: services_group.id,
|
||||||
|
ip_protocol: "tcp",
|
||||||
|
from_port: 5672,
|
||||||
|
to_port: 5672,
|
||||||
|
group: api_group.id
|
||||||
|
}
|
||||||
|
]
|
||||||
|
rules.each {|rule| conn.security_group_rules.create rule }
|
||||||
|
|
||||||
# step-3
|
# step-3
|
||||||
def get_floating_ip_address(conn)
|
def get_floating_ip_address(conn)
|
||||||
unless unused_floating_ip_address = conn.addresses.find {|address| address.instance_id.nil?}
|
unless unused_floating_ip_address = conn.addresses.find {|address| address.instance_id.nil?}
|
||||||
pool_name = conn.addresses.get_address_pools[0]["name"]
|
pool_name = conn.addresses.get_address_pools[0]["name"]
|
||||||
puts "Allocating new Floating IP from pool: #{pool_name}"
|
puts "Allocating new Floating IP from pool: #{pool_name}"
|
||||||
unused_floating_ip_address = conn.addresses.create({
|
unused_floating_ip_address = conn.addresses.create pool: pool_name
|
||||||
pool: pool_name
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
unused_floating_ip_address
|
unused_floating_ip_address
|
||||||
@ -114,14 +112,13 @@ curl -L -s http://git.openstack.org/cgit/openstack/faafo/plain/contrib/install.s
|
|||||||
-i database -i messaging
|
-i database -i messaging
|
||||||
END
|
END
|
||||||
|
|
||||||
instance_services = conn.servers.create({
|
instance_services = conn.servers.create name: "app-services",
|
||||||
name: "app-services",
|
image_ref: image.id,
|
||||||
image_ref: image.id,
|
flavor_ref: flavor.id,
|
||||||
flavor_ref: flavor.id,
|
key_name: "demokey",
|
||||||
key_name: "demokey",
|
user_data: user_data,
|
||||||
user_data: user_data,
|
security_groups: services_group
|
||||||
security_groups: services_group
|
|
||||||
})
|
|
||||||
Fog.wait_for {instance_services.ready?}
|
Fog.wait_for {instance_services.ready?}
|
||||||
services_ip_address = instance_services.private_ip_address
|
services_ip_address = instance_services.private_ip_address
|
||||||
|
|
||||||
@ -132,29 +129,27 @@ curl -L -s http://git.openstack.org/cgit/openstack/faafo/plain/contrib/install.s
|
|||||||
-i faafo -r api -m "amqp://guest:guest@#{services_ip_address}:5672/" -d "mysql+pymysql://faafo:password@#{services_ip_address}:3306/faafo"
|
-i faafo -r api -m "amqp://guest:guest@#{services_ip_address}:5672/" -d "mysql+pymysql://faafo:password@#{services_ip_address}:3306/faafo"
|
||||||
END
|
END
|
||||||
|
|
||||||
instance_api_1 = conn.servers.create({
|
instance_api_1 = conn.servers.create name: "app-api-1",
|
||||||
name: "app-api-1",
|
image_ref: image.id,
|
||||||
image_ref: image.id,
|
flavor_ref: flavor.id,
|
||||||
flavor_ref: flavor.id,
|
key_name: "demokey",
|
||||||
key_name: "demokey",
|
user_data: user_data,
|
||||||
user_data: user_data,
|
security_groups: api_group
|
||||||
security_groups: api_group
|
|
||||||
})
|
instance_api_2 = conn.servers.create name: "app-api-2",
|
||||||
instance_api_2 = conn.servers.create({
|
image_ref: image.id,
|
||||||
name: "app-api-2",
|
flavor_ref: flavor.id,
|
||||||
image_ref: image.id,
|
key_name: "demokey",
|
||||||
flavor_ref: flavor.id,
|
user_data: user_data,
|
||||||
key_name: "demokey",
|
security_groups: api_group
|
||||||
user_data: user_data,
|
|
||||||
security_groups: api_group
|
|
||||||
})
|
|
||||||
Fog.wait_for {instance_api_1.ready?}
|
Fog.wait_for {instance_api_1.ready?}
|
||||||
api_1_ip_address = instance_api_1.private_ip_address
|
api_1_ip_address = instance_api_1.private_ip_address
|
||||||
Fog.wait_for {instance_api_2.ready?}
|
Fog.wait_for {instance_api_2.ready?}
|
||||||
api_2_ip_address = instance_api_2.private_ip_address
|
api_2_ip_address = instance_api_2.private_ip_address
|
||||||
|
|
||||||
[instance_api_1, instance_api_2].each do |instance|
|
[instance_api_1, instance_api_2].each do |instance|
|
||||||
floating_ip_address = get_floating_ip_address(conn)
|
floating_ip_address = get_floating_ip_address(conn)
|
||||||
floating_ip_address.server = instance
|
floating_ip_address.server = instance
|
||||||
puts "allocated #{floating_ip_address.ip} to #{instance.name}"
|
puts "allocated #{floating_ip_address.ip} to #{instance.name}"
|
||||||
end
|
end
|
||||||
@ -166,29 +161,25 @@ curl -L -s http://git.openstack.org/cgit/openstack/faafo/plain/contrib/install.s
|
|||||||
-i faafo -r worker -e "http://#{api_1_ip_address}" -m "amqp://guest:guest@#{services_ip_address}:5672/"
|
-i faafo -r worker -e "http://#{api_1_ip_address}" -m "amqp://guest:guest@#{services_ip_address}:5672/"
|
||||||
END
|
END
|
||||||
|
|
||||||
instance_worker_1 = conn.servers.create({
|
instance_worker_1 = conn.servers.create name: "app-worker-1",
|
||||||
name: "app-worker-1",
|
image_ref: image.id,
|
||||||
image_ref: image.id,
|
flavor_ref: flavor.id,
|
||||||
flavor_ref: flavor.id,
|
key_name: "demokey",
|
||||||
key_name: "demokey",
|
user_data: user_data,
|
||||||
user_data: user_data,
|
security_groups: worker_group
|
||||||
security_groups: worker_group
|
|
||||||
})
|
instance_worker_2 = conn.servers.create name: "app-worker-2",
|
||||||
instance_worker_2 = conn.servers.create({
|
image_ref: image.id,
|
||||||
name: "app-worker-2",
|
flavor_ref: flavor.id,
|
||||||
image_ref: image.id,
|
key_name: "demokey",
|
||||||
flavor_ref: flavor.id,
|
user_data: user_data,
|
||||||
key_name: "demokey",
|
security_groups: worker_group
|
||||||
user_data: user_data,
|
|
||||||
security_groups: worker_group
|
instance_worker_3 = conn.servers.create name: "app-worker-3",
|
||||||
})
|
image_ref: image.id,
|
||||||
instance_worker_3 = conn.servers.create({
|
flavor_ref: flavor.id,
|
||||||
name: "app-worker-3",
|
key_name: "demokey",
|
||||||
image_ref: image.id,
|
user_data: user_data,
|
||||||
flavor_ref: flavor.id,
|
security_groups: worker_group
|
||||||
key_name: "demokey",
|
|
||||||
user_data: user_data,
|
|
||||||
security_groups: worker_group
|
|
||||||
})
|
|
||||||
|
|
||||||
# step-7
|
# step-7
|
||||||
|
@ -80,7 +80,7 @@ and toolkits with the OpenStack cloud:
|
|||||||
- `fog <http://fog.io/>`_
|
- `fog <http://fog.io/>`_
|
||||||
- A Ruby-based SDK.
|
- A Ruby-based SDK.
|
||||||
Use it to work with multiple clouds.
|
Use it to work with multiple clouds.
|
||||||
- https://github.com/fog/fog/blob/master/lib/fog/openstack/docs/getting_started.md
|
- https://github.com/fog/fog-openstack/blob/master/lib/fog/openstack/docs/getting_started.md
|
||||||
* - node.js
|
* - node.js
|
||||||
- `pkgcloud <https://github.com/pkgcloud/pkgcloud>`_
|
- `pkgcloud <https://github.com/pkgcloud/pkgcloud>`_
|
||||||
- A Node.js-based SDK.
|
- A Node.js-based SDK.
|
||||||
|
@ -59,7 +59,7 @@ http://docs.openstack.org/cli-reference/common/cli_set_environment_variables_usi
|
|||||||
.. only:: fog
|
.. only:: fog
|
||||||
|
|
||||||
.. note:: fog `does support OpenStack Orchestration
|
.. note:: fog `does support OpenStack Orchestration
|
||||||
<https://github.com/fog/fog/tree/master/lib/fog/openstack/models/orchestration>`_.
|
<https://github.com/fog/fog-openstack/tree/master/lib/fog/openstack/models/orchestration>`_.
|
||||||
|
|
||||||
.. only:: jclouds
|
.. only:: jclouds
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@
|
|||||||
Docs and resources
|
Docs and resources
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<a class="link" href="https://github.com/fog/fog/blob/master/lib/fog/openstack/docs/getting_started.md" target="_top">
|
<a class="link" href="https://github.com/fog/fog-openstack/blob/master/lib/fog/openstack/docs/getting_started.md" target="_top">
|
||||||
Getting Started with Fog and OpenStack
|
Getting Started with Fog and OpenStack
|
||||||
</a>
|
</a>
|
||||||
</dd>
|
</dd>
|
||||||
@ -356,7 +356,7 @@
|
|||||||
<strong>
|
<strong>
|
||||||
Issues:
|
Issues:
|
||||||
</strong>
|
</strong>
|
||||||
<a href="https://github.com/fog/fog/issues">
|
<a href="https://github.com/fog/fog-openstack/issues">
|
||||||
fog/fog Issues
|
fog/fog Issues
|
||||||
</a>
|
</a>
|
||||||
</dd>
|
</dd>
|
||||||
|
Loading…
Reference in New Issue
Block a user