api-site/firstapp/samples/fog/getting_started.rb
Christian Berendt 61b94863ba [firstapp] use meaningful filennames instead of sectionX.rst
Change-Id: I33e506e3e26d7e55287cb48a348b1b9de5f32231
2015-05-04 13:48:12 +02:00

56 lines
1.2 KiB
Ruby

# step-1
require 'fog'
auth_username = 'your_auth_username'
auth_password = 'your_auth_password'
auth_url = 'http://controller:5000'
project_name = 'your_project_name_or_id'
region_name = 'your_region_name'
conn = Fog::Compute.new({
:provider => 'openstack',
:openstack_auth_url => auth_url + '/v2.0/tokens',
:openstack_username => auth_username
:openstack_tenant => project_name
:openstack_api_key => auth_password
})
# step-2
images = conn.list_images
print images.body
# step-3
flavors = conn.list_flavors
print flavors.body
# step-4
image_id = '2cccbea0-cea9-4f86-a3ed-065c652adda5'
image = conn.images.get image_id
print image
# step-5
flavor_id = '3'
image = conn.flavor.get flavor_id
print flavor
# step-6
instance_name = 'testing'
testing_instance = conn.servers.create(:name => instance_name, :flavor_ref => flavor.id, :image_ref => image.id)
# step-7
conn.servers
# step-8
testing_instance.destroy
# step-9
# step-10
all_in_one_security_group = conn.create_security_group 'all-in-one' 'network access for all-in-one application.'
conn.create_security_group_rule all_in_one_security_group 'TCP' 80 80
conn.create_security_group_rule all_in_one_security_group 'TCP' 22 22
# step-11
# step-12
# step-13