openstack-quantum-messager 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,3 +3,12 @@ require "httparty"
3
3
  require "json"
4
4
  require "openstack-quantum-messager/version"
5
5
  require "openstack-quantum-messager/l2l3"
6
+ require "openstack-quantum-messager/l2l3/attachment_detail"
7
+ require "openstack-quantum-messager/l2l3/dhcp"
8
+ require "openstack-quantum-messager/l2l3/dhcp_entry"
9
+ require "openstack-quantum-messager/l2l3/firewall"
10
+ require "openstack-quantum-messager/l2l3/filter_rule"
11
+ require "openstack-quantum-messager/l2l3/filtered_range"
12
+ require "openstack-quantum-messager/l2l3/network"
13
+ require "openstack-quantum-messager/l2l3/port"
14
+
@@ -2,28 +2,68 @@
2
2
  module Openstack
3
3
  module QuantumMessager
4
4
  class L2l3
5
- def initialize(quantum_url)
6
- @quantum_url = quantum_url
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, @quantum_extension_url)
44
+ end
45
+
46
+ def network
47
+ @network ||= Network.new(@quantum_url, @quantum_extension_url)
7
48
  end
8
49
 
9
- def add_dhcp(name, address)
10
- dhcp_info = {"dhcp" => {"name" => name, "address" => address}}
11
- post_to_quantum(dhcp_info, "/dhcps.json")
50
+ protected
51
+ def post_to_quantum(post_url, info)
52
+ send_to_quantum("post", post_url, info)
12
53
  end
13
54
 
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")
55
+ def put_to_quantum(post_url, info)
56
+ send_to_quantum("put", post_url, info)
17
57
  end
18
58
 
19
- private
20
- def post_to_quantum(info, url_suffix)
21
- response = HTTParty.post(
22
- @quantum_url + url_suffix,
59
+ def send_to_quantum(http_method, post_url, info)
60
+ response = HTTParty.send(
61
+ http_method,
62
+ post_url,
23
63
  :body => info.to_json,
24
64
  :headers => {"Content-Type" => "application/json"}
25
65
  )
26
- response.body if response
66
+ response
27
67
  end
28
68
  end
29
69
  end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumMessager
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 QuantumMessager
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 QuantumMessager
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 QuantumMessager
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 QuantumMessager
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 QuantumMessager
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,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumMessager
4
+ class Network < L2l3
5
+ def initialize(quantum_url, quantum_extension_url)
6
+ @quantum_url = quantum_url
7
+ @quantum_extension_url = quantum_extension_url
8
+ end
9
+
10
+ def create(name)
11
+ full_url = "#{@quantum_url}/networks.json"
12
+ post_to_quantum(full_url, {"network" => {"name" => name}})
13
+ end
14
+
15
+ def list(filters={})
16
+ HTTParty.get("#{@quantum_extension_url}/networks.json", :query => filters)
17
+ end
18
+
19
+ def show(id)
20
+ HTTParty.get("#{@quantum_url}/networks/#{id}.json")
21
+ end
22
+
23
+ def find_or_create_by_name(network_name)
24
+ networks = list(:name => network_name)
25
+ if networks.empty?
26
+ create(network_name)
27
+ end
28
+ list(:name => network_name)["networks"].last
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Openstack
3
+ module QuantumMessager
4
+ class Port < L2l3
5
+ def initialize(quantum_url, quantum_extension_url)
6
+ @quantum_url = quantum_url
7
+ @quantum_extension_url = quantum_extension_url
8
+ end
9
+
10
+ def create(network_id)
11
+ full_url = "#{@quantum_url}/networks/#{network_id}/ports.json"
12
+ post_to_quantum(full_url, nil)
13
+ end
14
+
15
+ def plug(network_id, id, interface_id)
16
+ full_url = "#{@quantum_url}/networks/#{network_id}/ports/#{id}/attachment.json"
17
+ response = put_to_quantum(full_url, {"attachment" => {"id" => interface_id}})
18
+ response.code < 300
19
+ end
20
+
21
+ def unplug(network_id, id)
22
+ full_url = "#{@quantum_url}/networks/#{network_id}/ports/#{id}/attachment.json"
23
+ response = HTTParty.delete(full_url)
24
+ response.code < 300
25
+ end
26
+
27
+ def delete(network_id, id)
28
+ HTTParty.delete("#{@quantum_url}/networks/#{network_id}/ports/#{id}.json")
29
+ end
30
+
31
+ def list(network_id, filters={})
32
+ HTTParty.get("#{@quantum_extension_url}/networks/#{network_id}/ports.json", :query => filters)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,5 @@
1
1
  module Openstack
2
2
  module QuantumMessager
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Openstack::QuantumMessager::AttachmentDetail do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @messager = Openstack::QuantumMessager::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
+ @messager.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 = @messager.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 = @messager.attachment_detail.create("a4:ba:db:05:6e:f8", "192.168.3.4")
29
+ response_code = @messager.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
+ @messager.attachment_detail.create(mac, "192.168.3.4")
36
+ attachment_details = @messager.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::QuantumMessager::DhcpEntry do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @messager = Openstack::QuantumMessager::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
+ @messager.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 = @messager.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::QuantumMessager::Dhcp do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @messager = Openstack::QuantumMessager::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
+ @messager.dhcp.create("dhcp1", "192.168.1.1")
19
+ end
20
+
21
+ it "should return the dhcp uuid" do
22
+ dhcp_info = @messager.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 = @messager.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::QuantumMessager::FilterRule do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @messager = Openstack::QuantumMessager::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
+ @messager.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 = @messager.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 = @messager.filter_rule.create("192.168.1.1/32","10.0.0.1",22,"tcp")
37
+
38
+ filter_rule_info = @messager.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 = @messager.filter_rule.create("192.168.1.1/32","10.0.0.1",22,"tcp")
45
+
46
+ filter_rule_info = @messager.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 = @messager.firewall.create("firewall1", "192.168.1.1")
54
+ filtered_range = @messager.filtered_range.create(firewall["id"], "10.0.0.1", "26")
55
+ rule = @messager.filter_rule.create("192.168.1.1/32","10.0.0.1",22,"tcp")
56
+
57
+ filter_rule_info = @messager.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::QuantumMessager::FilteredRange do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @messager = Openstack::QuantumMessager::L2l3.new(config)
8
+ @filtered_range_info = {"filtered_range" => {"address" => "192.168.1.1", "mask" => "26"}}
9
+
10
+ @firewall = @messager.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
+ @messager.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::QuantumMessager::Firewall do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @messager = Openstack::QuantumMessager::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
+ @messager.firewall.create("firewall1", "192.168.1.1")
19
+ end
20
+
21
+ it "should return the firewall uuid" do
22
+ firewall_info = @messager.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 = @messager.firewall.list
29
+ firewall_info.should_not be_nil
30
+ firewall_info.should be_instance_of(Array)
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Openstack::QuantumMessager::Network do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @messager = Openstack::QuantumMessager::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
+ @messager.network.create("network1")
19
+ end
20
+
21
+ it "should return the network uuid" do
22
+ network_info = @messager.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
+ @messager.network.create("network1")
29
+ @messager.network.create("network2")
30
+ network_list = @messager.network.list(:name => "network2")["networks"]
31
+ network_list.size.should == 1
32
+ network_info = @messager.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 = @messager.network.create("network1")
38
+ network = @messager.network.find_or_create_by_name("network1")
39
+ network["id"].should eql(network_id["network"]["id"])
40
+ end
41
+ end
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Openstack::QuantumMessager::Port do
5
+ before do
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @messager = Openstack::QuantumMessager::L2l3.new(config)
8
+ @port_info = {}
9
+ @network_id = @messager.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
+ @messager.port.create(@network_id)
20
+ end
21
+
22
+ it "should return the port uuid" do
23
+ port_info = @messager.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 = @messager.port.create(@network_id)["port"]
31
+ @messager.port.plug(@network_id, port_info["id"], mac).should be_true
32
+ new_port_info = @messager.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 = @messager.port.create(@network_id)["port"]
39
+ @messager.port.unplug(@network_id, port_info["id"]).should be_true
40
+ end
41
+
42
+ it "should delete the port" do
43
+ port_info = @messager.port.create(@network_id)["port"]
44
+ @messager.port.delete(@network_id, port_info["id"]).code.should == 204
45
+ end
46
+ end
@@ -3,53 +3,19 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
 
4
4
  describe Openstack::QuantumMessager::L2l3 do
5
5
  before do
6
- @quantum_url = "http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ"
7
- @messager = Openstack::QuantumMessager::L2l3.new(@quantum_url)
6
+ config = {:url => "http://localhost:9696", :tenant => "XYZ"}
7
+ @messager = Openstack::QuantumMessager::L2l3.new(config)
8
8
  end
9
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
-
10
+ it "should generate the correct url" do
11
+ @messager.quantum_extension_url.should eql("http://localhost:9696/v1.0/extensions/l2l3/tenants/XYZ")
31
12
  end
32
13
 
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
14
+ it "should create a new instance of dhcp" do
15
+ @messager.dhcp.should be_instance_of(Openstack::QuantumMessager::Dhcp)
16
+ end
53
17
 
18
+ it "should create a new instance of dhcp entry" do
19
+ @messager.dhcp_entry.should be_instance_of(Openstack::QuantumMessager::DhcpEntry)
54
20
  end
55
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstack-quantum-messager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-02 00:00:00.000000000 Z
12
+ date: 2012-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &12600300 !ruby/object:Gem::Requirement
16
+ requirement: &16042640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12600300
24
+ version_requirements: *16042640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &12599320 !ruby/object:Gem::Requirement
27
+ requirement: &16042220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *12599320
35
+ version_requirements: *16042220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fakeweb
38
- requirement: &12597680 !ruby/object:Gem::Requirement
38
+ requirement: &16041800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *12597680
46
+ version_requirements: *16041800
47
47
  description: A simple gem to deal with openstack quantum
48
48
  email:
49
49
  - pothix@pothix.com
@@ -55,11 +55,27 @@ files:
55
55
  - ./spec/spec_helper.rb
56
56
  - ./spec/openstack_quantum_messager_spec.rb
57
57
  - ./spec/openstack-quantum-messager/l2l3_spec.rb
58
+ - ./spec/openstack-quantum-messager/l2l3/dhcp_entry_spec.rb
59
+ - ./spec/openstack-quantum-messager/l2l3/filtered_range_spec.rb
60
+ - ./spec/openstack-quantum-messager/l2l3/network_spec.rb
61
+ - ./spec/openstack-quantum-messager/l2l3/firewall_spec.rb
62
+ - ./spec/openstack-quantum-messager/l2l3/filter_rule_spec.rb
63
+ - ./spec/openstack-quantum-messager/l2l3/dhcp_spec.rb
64
+ - ./spec/openstack-quantum-messager/l2l3/port_spec.rb
65
+ - ./spec/openstack-quantum-messager/l2l3/attachment_detail_spec.rb
58
66
  - ./Gemfile
59
67
  - ./Rakefile
60
68
  - ./lib/openstack-quantum-messager.rb
61
69
  - ./lib/openstack-quantum-messager/version.rb
62
70
  - ./lib/openstack-quantum-messager/l2l3.rb
71
+ - ./lib/openstack-quantum-messager/l2l3/dhcp_entry.rb
72
+ - ./lib/openstack-quantum-messager/l2l3/attachment_detail.rb
73
+ - ./lib/openstack-quantum-messager/l2l3/firewall.rb
74
+ - ./lib/openstack-quantum-messager/l2l3/network.rb
75
+ - ./lib/openstack-quantum-messager/l2l3/filter_rule.rb
76
+ - ./lib/openstack-quantum-messager/l2l3/filtered_range.rb
77
+ - ./lib/openstack-quantum-messager/l2l3/port.rb
78
+ - ./lib/openstack-quantum-messager/l2l3/dhcp.rb
63
79
  homepage: http://www.locaweb.com.br
64
80
  licenses: []
65
81
  post_install_message: