File: basics.rb

package info (click to toggle)
ruby-fog-openstack 1.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,784 kB
  • sloc: ruby: 47,937; makefile: 5; sh: 4
file content (68 lines) | stat: -rw-r--r-- 1,776 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'fog/openstack'
require 'pp'

#
# Creates a share network and a share
#
# Needs to be in an environment where keystone v3 is available
#
# You will need to source OpenStack credentials since the script
# reads the following envionment variables:
#
#  OS_AUTH_URL
#  OS_PASSWORD
#  OS_USERNAME
#  OS_USER_DOMAIN_NAME
#  OS_PROJECT_NAME
#  OS_REGION_NAME
#
#  optionally disable SSL verification
#  SSL_VERIFY=false

auth_options = {
  :openstack_auth_url     => "#{ENV['OS_AUTH_URL']}/auth/tokens",
  :openstack_api_key      => ENV['OS_PASSWORD'],
  :openstack_username     => ENV['OS_USERNAME'],
  :openstack_domain_name  => ENV['OS_USER_DOMAIN_NAME'],
  :openstack_project_name => ENV['OS_PROJECT_NAME'],
  :openstack_region       => ENV['OS_REGION_NAME'],
  :connection_options     => {:ssl_verify_peer => ENV['SSL_VERIFY'] != 'false'}
}

network_service = Fog::OpenStack::Network.new(auth_options)
share_service   = Fog::OpenStack::SharedFileSystem.new(auth_options)

net = network_service.networks.first
raise 'no network exists' if net.nil?

puts "Create share network in #{net.name}"
share_network = share_service.networks.create(
  :neutron_net_id    => net.id,
  :neutron_subnet_id => net.subnets.first.id,
  :name              => 'fog_share_net'
)

pp share_network

puts 'Create share'
example_share = share_service.shares.create(
  :share_proto      => 'NFS',
  :size             => 1,
  :name             => 'fog_share',
  :share_network_id => share_network.id
)

pp example_share

puts 'Create snapshot'
example_snap = share_service.snapshots.create(
  :share_id => example_share.id,
  :name     => 'fog_share_snapshot'
)

pp example_snap

puts 'Removing snapshot, share and share network'
example_snap.destroy
example_share.destroy
share_network.destroy