# -*- encoding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe Simplenet::Client::Interface do before(:all) do @conf = {:url => "http://localhost:8081"} @conn = Simplenet::Client::Connection.new(@conf) dcid = @conn.datacenters.create(random_name_for("datacenter"))["id"] zone = @conn.zones.create(dcid, random_name_for("zone"))["id"] vlan = @conn.vlans.create( zone, random_name_for("vlan"), random_name_for("vlan").sub(/[a-zA-Z]+/,"") )["id"] cidr = random_cidr sbnt = @conn.subnets.create(vlan, cidr)["id"] @ip = random_ip(cidr) @conn.ips.create(sbnt, @ip) @dedvlan = @conn.vlans.create( zone, random_name_for("vlan"), random_name_for("vlan").sub(/[a-zA-Z]+/,""), "dedicated_vlan" )["id"] end before do @name = random_name_for("interface") @mac = random_mac end subject { @conn.interfaces } it "creates a new interface" do resp = subject.create(@name, @mac) expect(resp["hostname"]).to eql(@name) end it "raises duplicated error when creating two interfaces" do pending "waiting for simplenet implementation" subject.create(@name, @mac) expect{ subject.create(@name, @mac) }.to raise_error Simplenet::Exception::DuplicatedEntryError end it "lists all interfaces" do subject.create(@name, @mac) list = subject.list.map{|dc| dc["hostname"]} expect(list).to include(@name) end it "shows a single interface by uuid" do resp = subject.create(@name, @mac) show = subject.show(resp["id"]) expect(show["hostname"]).to eql(@name) end it "deletes a interface" do id = subject.create(random_name_for("interface"), @mac)["id"] subject.delete(id) list = subject.list.map{|dc| dc["hostname"]} expect(list).to_not include(@name) end context "for interface attachments" do it "attaches an ip to an interface" do iface = subject.create(random_name_for("interface"), @mac) expect(iface["ips"]).to be_empty subject.attach_ip(iface["id"], @ip) iface = subject.show(iface["id"]) expect(iface["ips"]).to_not be_empty expect(iface["ips"].first).to eql(@ip) end it "detaches an ip from an interface" do iface = subject.create(random_name_for("interface"), @mac) id = iface["id"] subject.attach_ip(id, @ip) iface = subject.show(id) expect(iface["ips"]).to_not be_empty subject.detach_ip(id, @ip) iface = subject.show(id) expect(iface["ips"]).to be_empty end it "raises error when detaching an non existant ip from an interface" do iface = subject.create(random_name_for("interface"), @mac) id = iface["id"] expect { subject.detach_ip(id, "284.284.284.284") }.to raise_error(Simplenet::Exception::EntityNotFoundError) end it "attaches a vlan to an interface" do iface = subject.create(random_name_for("interface"), @mac) expect(iface["vlan_id"]).to be_nil subject.attach_vlan(iface["id"], @dedvlan) iface = subject.show(iface["id"]) expect(iface["vlan_id"]).to_not be_nil expect(iface["vlan_id"]).to eql(@dedvlan) end it "detaches a vlan from an interface" do iface = subject.create(random_name_for("interface"), @mac) id = iface["id"] subject.attach_vlan(id, @dedvlan) iface = subject.show(id) expect(iface["vlan_id"]).to_not be_nil subject.detach_vlan(id, @dedvlan) iface = subject.show(id) expect(iface["vlan_id"]).to be_nil end end end