openstack-quantum-messager 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/openstack-quantum-messager.rb +5 -0
- data/lib/openstack-quantum-messager/l2l3.rb +30 -0
- data/lib/openstack-quantum-messager/version.rb +5 -0
- data/openstack-quantum-messager.gemspec +19 -0
- data/spec/openstack-quantum-messager/l2l3_spec.rb +55 -0
- data/spec/openstack_quantum_messager_spec.rb +4 -0
- data/spec/spec_helper.rb +2 -0
- metadata +87 -0
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
module Openstack
|
3
|
+
module QuantumMessager
|
4
|
+
class L2l3
|
5
|
+
def initialize(quantum_url)
|
6
|
+
@quantum_url = quantum_url
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_dhcp(name, address)
|
10
|
+
dhcp_info = {"dhcp" => {"name" => name, "address" => address}}
|
11
|
+
post_to_quantum(dhcp_info, "/dhcps.json")
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_dhcp_entry(address, mac)
|
15
|
+
dhcp_entry_info = {"dhcp_entry" => {"mac" => mac, "address" => address}}
|
16
|
+
post_to_quantum(dhcp_entry_info, "/dhcp_entries.json")
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def post_to_quantum(info, url_suffix)
|
21
|
+
response = HTTParty.post(
|
22
|
+
@quantum_url + url_suffix,
|
23
|
+
:body => info.to_json,
|
24
|
+
:headers => {"Content-Type" => "application/json"}
|
25
|
+
)
|
26
|
+
response.body if response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/openstack-quantum-messager/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "openstack-quantum-messager"
|
6
|
+
gem.version = Openstack::QuantumMessager::VERSION
|
7
|
+
gem.authors = ["PotHix"]
|
8
|
+
gem.email = ["pothix@pothix.com"]
|
9
|
+
gem.description = %q{A simple gem to deal with openstack quantum}
|
10
|
+
gem.summary = %q{The main objective of this gem is to deal easily with openstack quantum}
|
11
|
+
gem.homepage = "http://www.locaweb.com.br"
|
12
|
+
|
13
|
+
gem.files = Dir["./**/*"].reject {|file| file =~ /\.git|pkg/}
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
|
16
|
+
gem.add_dependency "httparty"
|
17
|
+
gem.add_development_dependency "rspec"
|
18
|
+
gem.add_development_dependency "fakeweb"
|
19
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
|
+
|
4
|
+
describe Openstack::QuantumMessager::L2l3 do
|
5
|
+
before do
|
6
|
+
@quantum_url = "http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ"
|
7
|
+
@messager = Openstack::QuantumMessager::L2l3.new(@quantum_url)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when dealing with dhcps" do
|
11
|
+
before do
|
12
|
+
@dhcp_info = {"dhcp" => {"name" => "dhcp1", "address" => "192.168.1.1"} }
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should generate the correct json syntax for dhcp inclusion" do
|
16
|
+
url = "http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ/dhcps.json"
|
17
|
+
HTTParty.should_receive(:post).with(
|
18
|
+
url,
|
19
|
+
:body => @dhcp_info.to_json,
|
20
|
+
:headers => {"Content-Type" => "application/json"}
|
21
|
+
)
|
22
|
+
@messager.add_dhcp("dhcp1", "192.168.1.1")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return the dhcp uuid" do
|
26
|
+
dhcp_info = @messager.add_dhcp("dhcp1", "192.168.1.1")
|
27
|
+
dhcp_info.should_not be_nil
|
28
|
+
JSON.parse(dhcp_info)["id"].should match(/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when dealing with dhcps entrys" do
|
34
|
+
before do
|
35
|
+
@dhcp_entry_info = {"dhcp_entry" => {"mac" => "a4:ba:db:05:6e:f8", "address" => "192.168.3.4"}}
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should generate the correct json syntax for dhcp inclusion" do
|
39
|
+
url = "http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ/dhcp_entries.json"
|
40
|
+
HTTParty.should_receive(:post).with(
|
41
|
+
url,
|
42
|
+
:body => @dhcp_entry_info.to_json,
|
43
|
+
:headers => {"Content-Type" => "application/json"}
|
44
|
+
)
|
45
|
+
@messager.add_dhcp_entry("192.168.3.4", "a4:ba:db:05:6e:f8")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return the dhcp uuid" do
|
49
|
+
dhcp_entry_info = @messager.add_dhcp_entry("dhcp1", "192.168.3.4")
|
50
|
+
dhcp_entry_info.should_not be_nil
|
51
|
+
JSON.parse(dhcp_entry_info)["id"].should match(/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openstack-quantum-messager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- PotHix
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: &12600300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *12600300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &12599320 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *12599320
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: fakeweb
|
38
|
+
requirement: &12597680 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *12597680
|
47
|
+
description: A simple gem to deal with openstack quantum
|
48
|
+
email:
|
49
|
+
- pothix@pothix.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- ./openstack-quantum-messager.gemspec
|
55
|
+
- ./spec/spec_helper.rb
|
56
|
+
- ./spec/openstack_quantum_messager_spec.rb
|
57
|
+
- ./spec/openstack-quantum-messager/l2l3_spec.rb
|
58
|
+
- ./Gemfile
|
59
|
+
- ./Rakefile
|
60
|
+
- ./lib/openstack-quantum-messager.rb
|
61
|
+
- ./lib/openstack-quantum-messager/version.rb
|
62
|
+
- ./lib/openstack-quantum-messager/l2l3.rb
|
63
|
+
homepage: http://www.locaweb.com.br
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.10
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: The main objective of this gem is to deal easily with openstack quantum
|
87
|
+
test_files: []
|