openstack-quantum-client 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. data/Gemfile +4 -0
  2. data/README.markdown +2 -0
  3. data/Rakefile +2 -0
  4. data/lib/openstack-quantum-client.rb +14 -0
  5. data/lib/openstack-quantum-client/l2l3.rb +70 -0
  6. data/lib/openstack-quantum-client/l2l3/attachment_detail.rb +24 -0
  7. data/lib/openstack-quantum-client/l2l3/dhcp.rb +22 -0
  8. data/lib/openstack-quantum-client/l2l3/dhcp_entry.rb +17 -0
  9. data/lib/openstack-quantum-client/l2l3/filter_rule.rb +31 -0
  10. data/lib/openstack-quantum-client/l2l3/filtered_range.rb +17 -0
  11. data/lib/openstack-quantum-client/l2l3/firewall.rb +22 -0
  12. data/lib/openstack-quantum-client/l2l3/network.rb +31 -0
  13. data/lib/openstack-quantum-client/l2l3/port.rb +35 -0
  14. data/lib/openstack-quantum-client/version.rb +5 -0
  15. data/openstack-quantum-client-0.1.2.gem +0 -0
  16. data/openstack-quantum-client.gemspec +19 -0
  17. data/spec/openstack-quantum-messager/l2l3/attachment_detail_spec.rb +40 -0
  18. data/spec/openstack-quantum-messager/l2l3/dhcp_entry_spec.rb +26 -0
  19. data/spec/openstack-quantum-messager/l2l3/dhcp_spec.rb +32 -0
  20. data/spec/openstack-quantum-messager/l2l3/filter_rule_spec.rb +61 -0
  21. data/spec/openstack-quantum-messager/l2l3/filtered_range_spec.rb +22 -0
  22. data/spec/openstack-quantum-messager/l2l3/firewall_spec.rb +32 -0
  23. data/spec/openstack-quantum-messager/l2l3/network_spec.rb +47 -0
  24. data/spec/openstack-quantum-messager/l2l3/port_spec.rb +46 -0
  25. data/spec/openstack-quantum-messager/l2l3_spec.rb +21 -0
  26. data/spec/openstack_quantum_messager_spec.rb +4 -0
  27. data/spec/spec_helper.rb +2 -0
  28. metadata +107 -0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in openstack-quantum-client.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ Openstack Quantum Client
2
+ ========================
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require "httparty"
3
+ require "json"
4
+ require "openstack-quantum-client/version"
5
+ require "openstack-quantum-client/l2l3"
6
+ require "openstack-quantum-client/l2l3/attachment_detail"
7
+ require "openstack-quantum-client/l2l3/dhcp"
8
+ require "openstack-quantum-client/l2l3/dhcp_entry"
9
+ require "openstack-quantum-client/l2l3/firewall"
10
+ require "openstack-quantum-client/l2l3/filter_rule"
11
+ require "openstack-quantum-client/l2l3/filtered_range"
12
+ require "openstack-quantum-client/l2l3/network"
13
+ require "openstack-quantum-client/l2l3/port"
14
+
@@ -0,0 +1,70 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumClient
4
+ class L2l3
5
+ attr_reader :quantum_url
6
+ attr_reader :quantum_extension_url
7
+
8
+ # The initialize l2l3 class should be initialized passing a hash
9
+ # with url and tenant:
10
+ # Example:
11
+ #
12
+ # {:url => "http://localhost:9696", :tenant => "XYZ"}
13
+ def initialize(config)
14
+ @quantum_extension_url = "#{config[:url]}/v1.0/extensions/l2l3/tenants/#{config[:tenant]}"
15
+ @quantum_url = "#{config[:url]}/v1.0/tenants/#{config[:tenant]}"
16
+ end
17
+
18
+ def attachment_detail
19
+ @attachment_detail ||= AttachmentDetail.new(@quantum_extension_url)
20
+ end
21
+
22
+ def firewall
23
+ @firewall ||= Firewall.new(@quantum_extension_url)
24
+ end
25
+
26
+ def filtered_range
27
+ @filtered_range ||= FilteredRange.new(@quantum_extension_url)
28
+ end
29
+
30
+ def filter_rule
31
+ @filter_rule ||= FilterRule.new(@quantum_extension_url)
32
+ end
33
+
34
+ def dhcp
35
+ @dhcp ||= Dhcp.new(@quantum_extension_url)
36
+ end
37
+
38
+ def dhcp_entry
39
+ @dhcp_entry ||= DhcpEntry.new(@quantum_extension_url)
40
+ end
41
+
42
+ def port
43
+ @port ||= Port.new(@quantum_url)
44
+ end
45
+
46
+ def network
47
+ @network ||= Network.new(@quantum_url)
48
+ end
49
+
50
+ protected
51
+ def post_to_quantum(post_url, info)
52
+ send_to_quantum("post", post_url, info)
53
+ end
54
+
55
+ def put_to_quantum(post_url, info)
56
+ send_to_quantum("put", post_url, info)
57
+ end
58
+
59
+ def send_to_quantum(http_method, post_url, info)
60
+ response = HTTParty.send(
61
+ http_method,
62
+ post_url,
63
+ :body => info.to_json,
64
+ :headers => {"Content-Type" => "application/json"}
65
+ )
66
+ response
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumClient
4
+ class AttachmentDetail < L2l3
5
+ def initialize(quantum_extension_url)
6
+ @quantum_extension_url = quantum_extension_url
7
+ end
8
+
9
+ def list(filters={})
10
+ HTTParty.get("#{quantum_extension_url}/attachment_details.json", :query => filters)
11
+ end
12
+
13
+ def create(mac, ip)
14
+ url = "#{quantum_extension_url}/attachment_details.json"
15
+ post_to_quantum(url, {"attachment_detail" => {"interface_id" => mac, "ip" => ip}})
16
+ end
17
+
18
+ def delete(id)
19
+ url = "#{quantum_extension_url}/attachment_details/#{id}.json"
20
+ HTTParty.delete(url)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumClient
4
+ class Dhcp < L2l3
5
+ def initialize(quantum_url)
6
+ @quantum_url = "#{quantum_url}/dhcps.json"
7
+ end
8
+
9
+ def create(name, address)
10
+ post_to_quantum(
11
+ @quantum_url,
12
+ {"dhcp" => {"name" => name, "address" => address}}
13
+ )
14
+ end
15
+
16
+ def list
17
+ response = HTTParty.get(@quantum_url)
18
+ JSON.parse(response.body)["dhcps"] if response
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumClient
4
+ class DhcpEntry < L2l3
5
+ def initialize(quantum_url)
6
+ @quantum_url = "#{quantum_url}/dhcp_entries.json"
7
+ end
8
+
9
+ def create(address, mac)
10
+ post_to_quantum(
11
+ @quantum_url,
12
+ {"dhcp_entry" => {"mac" => mac, "address" => address}}
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumClient
4
+ class FilterRule < L2l3
5
+ def initialize(quantum_url)
6
+ @quantum_url = quantum_url
7
+ end
8
+
9
+ def create(src, dst, dst_port, proto)
10
+ full_url = "#{@quantum_url}/filter_rules.json"
11
+ post_hash = {
12
+ "filter_rule" => {
13
+ "src" => src,
14
+ "dst" => dst,
15
+ "dst_port" => dst_port,
16
+ "proto" => proto
17
+ }
18
+ }
19
+ post_to_quantum(full_url, post_hash)
20
+ end
21
+
22
+ def delete(id)
23
+ HTTParty.delete("#{@quantum_url}/filter_rules/#{id}.json" )
24
+ end
25
+
26
+ def show(id)
27
+ HTTParty.get("#{@quantum_url}/filter_rules/#{id}.json" )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumClient
4
+ class FilteredRange < L2l3
5
+ def initialize(quantum_url)
6
+ @quantum_url = "#{quantum_url}/firewalls/%s/filtered_ranges.json"
7
+ end
8
+
9
+ def create(firewall_uuid, address, mask)
10
+ post_to_quantum(
11
+ @quantum_url % firewall_uuid.to_s,
12
+ {"filtered_range" => {"address" => address, "mask" => mask}}
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumClient
4
+ class Firewall < L2l3
5
+ def initialize(quantum_url)
6
+ @quantum_url = "#{quantum_url}/firewalls.json"
7
+ end
8
+
9
+ def create(name, address)
10
+ post_to_quantum(
11
+ @quantum_url,
12
+ {"firewall" => {"name" => name, "address" => address}}
13
+ )
14
+ end
15
+
16
+ def list
17
+ response = HTTParty.get(@quantum_url)
18
+ JSON.parse(response.body)["firewalls"] if response
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumClient
4
+ class Network < L2l3
5
+ def initialize(quantum_url)
6
+ @quantum_url = quantum_url
7
+ end
8
+
9
+ def create(name)
10
+ full_url = "#{@quantum_url}/networks.json"
11
+ post_to_quantum(full_url, {"network" => {"name" => name}})
12
+ end
13
+
14
+ def list(filters={})
15
+ HTTParty.get("#{@quantum_url}/networks.json", :query => filters)
16
+ end
17
+
18
+ def show(id)
19
+ HTTParty.get("#{@quantum_url}/networks/#{id}.json")
20
+ end
21
+
22
+ def find_or_create_by_name(network_name)
23
+ networks = list(:name => network_name)["networks"]
24
+ if networks.empty?
25
+ create(network_name)
26
+ end
27
+ list(:name => network_name)["networks"].last
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumClient
4
+ class Port < L2l3
5
+ def initialize(quantum_url)
6
+ @quantum_url = quantum_url
7
+ end
8
+
9
+ def create(network_id)
10
+ full_url = "#{@quantum_url}/networks/#{network_id}/ports.json"
11
+ post_to_quantum(full_url, nil)
12
+ end
13
+
14
+ def plug(network_id, id, interface_id)
15
+ full_url = "#{@quantum_url}/networks/#{network_id}/ports/#{id}/attachment.json"
16
+ response = put_to_quantum(full_url, {"attachment" => {"id" => interface_id}})
17
+ response.code < 300
18
+ end
19
+
20
+ def unplug(network_id, id)
21
+ full_url = "#{@quantum_url}/networks/#{network_id}/ports/#{id}/attachment.json"
22
+ response = HTTParty.delete(full_url)
23
+ response.code < 300
24
+ end
25
+
26
+ def delete(network_id, id)
27
+ HTTParty.delete("#{@quantum_url}/networks/#{network_id}/ports/#{id}.json")
28
+ end
29
+
30
+ def list(network_id, filters={})
31
+ HTTParty.get("#{@quantum_url}/networks/#{network_id}/ports.json", :query => filters)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Openstack
2
+ module QuantumClient
3
+ VERSION = "0.1.3"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/openstack-quantum-client/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "openstack-quantum-client"
6
+ gem.version = Openstack::QuantumClient::VERSION
7
+ gem.authors = ["PotHix", "Morellon"]
8
+ gem.email = ["pothix@pothix.com", "morellon@gmail.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,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Openstack::QuantumClient::AttachmentDetail do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @client = Openstack::QuantumClient::L2l3.new(config)
8
+ @attachment_detail = {"attachment_detail" => {"interface_id" => "a4:ba:db:05:6e:f8", "ip" => "192.168.3.4"}}
9
+ end
10
+
11
+ it "should generate the correct json syntax for attachment_detail creation" do
12
+ url = "http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ/attachment_details.json"
13
+ HTTParty.should_receive(:post).with(
14
+ url,
15
+ :body => @attachment_detail.to_json,
16
+ :headers => {"Content-Type" => "application/json"}
17
+ )
18
+ @client.attachment_detail.create("a4:ba:db:05:6e:f8", "192.168.3.4")
19
+ end
20
+
21
+ it "should return the attachment_detail uuid" do
22
+ attachment_detail = @client.attachment_detail.create("a4:ba:db:05:6e:f8", "192.168.3.4")
23
+ attachment_detail.should_not be_nil
24
+ attachment_detail["id"].should match(/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/)
25
+ end
26
+
27
+ it "should delete the attachment_detail" do
28
+ attachment_detail = @client.attachment_detail.create("a4:ba:db:05:6e:f8", "192.168.3.4")
29
+ response_code = @client.attachment_detail.delete(attachment_detail["id"]).code
30
+ response_code.should == 200
31
+ end
32
+
33
+ it "should list the attachment_details" do
34
+ mac = "a4:ba:db:05:6e:f9"
35
+ @client.attachment_detail.create(mac, "192.168.3.4")
36
+ attachment_details = @client.attachment_detail.list(:attachment => mac)["attachment_details"]
37
+ attachment_details.size.should == 1
38
+ attachment_details.first["interface_id"].should == mac
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Openstack::QuantumClient::DhcpEntry do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @client = Openstack::QuantumClient::L2l3.new(config)
8
+ @dhcp_entry_info = {"dhcp_entry" => {"mac" => "a4:ba:db:05:6e:f8", "address" => "192.168.3.4"}}
9
+ end
10
+
11
+ it "should generate the correct json syntax for dhcp inclusion" do
12
+ url = "http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ/dhcp_entries.json"
13
+ HTTParty.should_receive(:post).with(
14
+ url,
15
+ :body => @dhcp_entry_info.to_json,
16
+ :headers => {"Content-Type" => "application/json"}
17
+ )
18
+ @client.dhcp_entry.create("192.168.3.4", "a4:ba:db:05:6e:f8")
19
+ end
20
+
21
+ it "should return the dhcp uuid" do
22
+ dhcp_entry_info = @client.dhcp.create("dhcp1", "192.168.3.4")
23
+ dhcp_entry_info.should_not be_nil
24
+ dhcp_entry_info["id"].should match(/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/)
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Openstack::QuantumClient::Dhcp do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @client = Openstack::QuantumClient::L2l3.new(config)
8
+ @dhcp_info = {"dhcp" => {"name" => "dhcp1", "address" => "192.168.1.1"} }
9
+ end
10
+
11
+ it "should generate the correct json syntax for dhcp inclusion" do
12
+ url = "http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ/dhcps.json"
13
+ HTTParty.should_receive(:post).with(
14
+ url,
15
+ :body => @dhcp_info.to_json,
16
+ :headers => {"Content-Type" => "application/json"}
17
+ )
18
+ @client.dhcp.create("dhcp1", "192.168.1.1")
19
+ end
20
+
21
+ it "should return the dhcp uuid" do
22
+ dhcp_info = @client.dhcp.create("dhcp1", "192.168.1.1")
23
+ dhcp_info.should_not be_nil
24
+ dhcp_info["id"].should match(/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/)
25
+ end
26
+
27
+ it "should return a dhcps array" do
28
+ dhcp_info = @client.dhcp.list
29
+ dhcp_info.should_not be_nil
30
+ dhcp_info.should be_instance_of(Array)
31
+ end
32
+ end
@@ -0,0 +1,61 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Openstack::QuantumClient::FilterRule do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @client = Openstack::QuantumClient::L2l3.new(config)
8
+ @filter_rule_info = {
9
+ "filter_rule" => {
10
+ "src" => "192.168.1.1/32",
11
+ "dst" => "10.0.0.1",
12
+ "dst_port" => 22,
13
+ "proto" => "tcp"
14
+ }
15
+ }
16
+ end
17
+
18
+ it "should generate the correct json syntax for filter_rule inclusion" do
19
+ url = "http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ/filter_rules.json"
20
+ HTTParty.should_receive(:post).with(
21
+ url,
22
+ :body => @filter_rule_info.to_json,
23
+ :headers => {"Content-Type" => "application/json"}
24
+ )
25
+ @client.filter_rule.create("192.168.1.1/32","10.0.0.1",22,"tcp")
26
+ end
27
+
28
+ it "should return the filter_rule uuid" do
29
+ filter_rule_info = @client.filter_rule.create("192.168.1.1/32","10.0.0.1",22,"tcp")
30
+ filter_rule_info.should_not be_nil
31
+ filter_rule_info["id"].should match(/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/)
32
+ end
33
+
34
+ context "when using rule uuid" do
35
+ it "should delete the filter_rule by uuid" do
36
+ rule = @client.filter_rule.create("192.168.1.1/32","10.0.0.1",22,"tcp")
37
+
38
+ filter_rule_info = @client.filter_rule.delete(rule["id"])
39
+ filter_rule_info.should_not be_nil
40
+ filter_rule_info["id"].should match(rule["id"])
41
+ end
42
+
43
+ it "should get the filter_rule by uuid" do
44
+ rule = @client.filter_rule.create("192.168.1.1/32","10.0.0.1",22,"tcp")
45
+
46
+ filter_rule_info = @client.filter_rule.show(rule["id"])
47
+ filter_rule_info.should_not be_nil
48
+ filter_rule_info["id"].should match(rule["id"])
49
+ filter_rule_info["src"].should match(rule["src"])
50
+ end
51
+
52
+ it "should get the filter_rule status" do
53
+ firewall = @client.firewall.create("firewall1", "192.168.1.1")
54
+ filtered_range = @client.filtered_range.create(firewall["id"], "10.0.0.1", "26")
55
+ rule = @client.filter_rule.create("192.168.1.1/32","10.0.0.1",22,"tcp")
56
+
57
+ filter_rule_info = @client.filter_rule.show(rule["id"])
58
+ filter_rule_info["status"].should match("INSERTING")
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Openstack::QuantumClient::FilteredRange do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @client = Openstack::QuantumClient::L2l3.new(config)
8
+ @filtered_range_info = {"filtered_range" => {"address" => "192.168.1.1", "mask" => "26"}}
9
+
10
+ @firewall = @client.firewall.create("firewall1", "192.168.1.1")
11
+ end
12
+
13
+ it "should generate the correct json syntax for firewall inclusion" do
14
+ url = "http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ/firewalls/%s/filtered_ranges.json"
15
+ HTTParty.should_receive(:post).with(
16
+ url % @firewall["uuid"],
17
+ :body => @filtered_range_info.to_json,
18
+ :headers => {"Content-Type" => "application/json"}
19
+ )
20
+ @client.filtered_range.create(@firewall["uuid"], "192.168.1.1", "26")
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Openstack::QuantumClient::Firewall do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @client = Openstack::QuantumClient::L2l3.new(config)
8
+ @firewall_info = {"firewall" => {"name" => "firewall1", "address" => "192.168.1.1"} }
9
+ end
10
+
11
+ it "should generate the correct json syntax for firewall inclusion" do
12
+ url = "http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ/firewalls.json"
13
+ HTTParty.should_receive(:post).with(
14
+ url,
15
+ :body => @firewall_info.to_json,
16
+ :headers => {"Content-Type" => "application/json"}
17
+ )
18
+ @client.firewall.create("firewall1", "192.168.1.1")
19
+ end
20
+
21
+ it "should return the firewall uuid" do
22
+ firewall_info = @client.firewall.create("firewall1", "192.168.1.1")
23
+ firewall_info.should_not be_nil
24
+ firewall_info["id"].should match(/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/)
25
+ end
26
+
27
+ it "should return a firewalls array" do
28
+ firewall_info = @client.firewall.list
29
+ firewall_info.should_not be_nil
30
+ firewall_info.should be_instance_of(Array)
31
+ end
32
+ end
@@ -0,0 +1,47 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Openstack::QuantumClient::Network do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @client = Openstack::QuantumClient::L2l3.new(config)
8
+ @network_info = {"network" => {"name" => "network1"}}
9
+ end
10
+
11
+ it "should generate the correct json syntax for network inclusion" do
12
+ url = "http://localhost:9696/v1.0/tenants/XYZ/networks.json"
13
+ HTTParty.should_receive(:post).with(
14
+ url,
15
+ :body => @network_info.to_json,
16
+ :headers => {"Content-Type" => "application/json"}
17
+ )
18
+ @client.network.create("network1")
19
+ end
20
+
21
+ it "should return the network uuid" do
22
+ network_info = @client.network.create("network1")["network"]
23
+ network_info.should_not be_nil
24
+ network_info["id"].should match(/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/)
25
+ end
26
+
27
+ it "should list networks filtered" do
28
+ @client.network.create("network1")
29
+ @client.network.create("network2")
30
+ network_list = @client.network.list(:name => "network2")["networks"]
31
+ network_list.size.should == 1
32
+ network_info = @client.network.show(network_list.first["id"])["network"]
33
+ network_info["name"].should == "network2"
34
+ end
35
+
36
+ it "should return the last network created by name" do
37
+ network_id = @client.network.create("network1")
38
+ network = @client.network.find_or_create_by_name("network1")
39
+ network["id"].should eql(network_id["network"]["id"])
40
+ end
41
+
42
+ it "should create a network if can't find it" do
43
+ network = "new_network"
44
+ @client.network.list(:name => network)["networks"].should be_empty
45
+ @client.network.find_or_create_by_name(network).should_not be_nil
46
+ end
47
+ end
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Openstack::QuantumClient::Port do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @client = Openstack::QuantumClient::L2l3.new(config)
8
+ @port_info = {}
9
+ @network_id = @client.network.create("net")["network"]["id"]
10
+ end
11
+
12
+ it "should generate the correct json syntax for port inclusion" do
13
+ url = "http://localhost:9696/v1.0/tenants/XYZ/networks/#{@network_id}/ports.json"
14
+ HTTParty.should_receive(:post).with(
15
+ url,
16
+ :body => "null",
17
+ :headers => {"Content-Type" => "application/json"}
18
+ )
19
+ @client.port.create(@network_id)
20
+ end
21
+
22
+ it "should return the port uuid" do
23
+ port_info = @client.port.create(@network_id)["port"]
24
+ port_info.should_not be_nil
25
+ port_info["id"].should match(/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/)
26
+ end
27
+
28
+ it "should plug an interface" do
29
+ mac = "4a:94:c4:98:38:57"
30
+ port_info = @client.port.create(@network_id)["port"]
31
+ @client.port.plug(@network_id, port_info["id"], mac).should be_true
32
+ new_port_info = @client.port.list(@network_id, :attachment => mac)["ports"].first
33
+ new_port_info["id"].should == port_info["id"]
34
+ end
35
+
36
+ it "should unplug an interface" do
37
+ mac = "4a:94:c4:98:38:57"
38
+ port_info = @client.port.create(@network_id)["port"]
39
+ @client.port.unplug(@network_id, port_info["id"]).should be_true
40
+ end
41
+
42
+ it "should delete the port" do
43
+ port_info = @client.port.create(@network_id)["port"]
44
+ @client.port.delete(@network_id, port_info["id"]).code.should == 204
45
+ end
46
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ describe Openstack::QuantumClient::L2l3 do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @client = Openstack::QuantumClient::L2l3.new(config)
8
+ end
9
+
10
+ it "should generate the correct url" do
11
+ @client.quantum_extension_url.should eql("http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ")
12
+ end
13
+
14
+ it "should create a new instance of dhcp" do
15
+ @client.dhcp.should be_instance_of(Openstack::QuantumClient::Dhcp)
16
+ end
17
+
18
+ it "should create a new instance of dhcp entry" do
19
+ @client.dhcp_entry.should be_instance_of(Openstack::QuantumClient::DhcpEntry)
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "" do
4
+ end
@@ -0,0 +1,2 @@
1
+ require "openstack-quantum-client"
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + "/support")
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openstack-quantum-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - PotHix
9
+ - Morellon
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-01-31 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ requirement: &17179240 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *17179240
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &17178820 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *17178820
37
+ - !ruby/object:Gem::Dependency
38
+ name: fakeweb
39
+ requirement: &17178400 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *17178400
48
+ description: A simple gem to deal with openstack quantum
49
+ email:
50
+ - pothix@pothix.com
51
+ - morellon@gmail.com
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - ./openstack-quantum-client.gemspec
57
+ - ./README.markdown
58
+ - ./openstack-quantum-client-0.1.2.gem
59
+ - ./spec/spec_helper.rb
60
+ - ./spec/openstack_quantum_messager_spec.rb
61
+ - ./spec/openstack-quantum-messager/l2l3_spec.rb
62
+ - ./spec/openstack-quantum-messager/l2l3/dhcp_entry_spec.rb
63
+ - ./spec/openstack-quantum-messager/l2l3/filtered_range_spec.rb
64
+ - ./spec/openstack-quantum-messager/l2l3/network_spec.rb
65
+ - ./spec/openstack-quantum-messager/l2l3/firewall_spec.rb
66
+ - ./spec/openstack-quantum-messager/l2l3/filter_rule_spec.rb
67
+ - ./spec/openstack-quantum-messager/l2l3/dhcp_spec.rb
68
+ - ./spec/openstack-quantum-messager/l2l3/port_spec.rb
69
+ - ./spec/openstack-quantum-messager/l2l3/attachment_detail_spec.rb
70
+ - ./Gemfile
71
+ - ./Rakefile
72
+ - ./lib/openstack-quantum-client.rb
73
+ - ./lib/openstack-quantum-client/version.rb
74
+ - ./lib/openstack-quantum-client/l2l3.rb
75
+ - ./lib/openstack-quantum-client/l2l3/dhcp_entry.rb
76
+ - ./lib/openstack-quantum-client/l2l3/attachment_detail.rb
77
+ - ./lib/openstack-quantum-client/l2l3/firewall.rb
78
+ - ./lib/openstack-quantum-client/l2l3/network.rb
79
+ - ./lib/openstack-quantum-client/l2l3/filter_rule.rb
80
+ - ./lib/openstack-quantum-client/l2l3/filtered_range.rb
81
+ - ./lib/openstack-quantum-client/l2l3/port.rb
82
+ - ./lib/openstack-quantum-client/l2l3/dhcp.rb
83
+ homepage: http://www.locaweb.com.br
84
+ licenses: []
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.10
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: The main objective of this gem is to deal easily with openstack quantum
107
+ test_files: []