-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
388 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule Lexdee.Networks do | ||
use Tesla | ||
|
||
@path "/1.0/networks" | ||
|
||
def base_path, do: @path | ||
|
||
def index(client, options \\ []), do: get(client, @path, options) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Lexdee.Networks.Leases do | ||
use Tesla | ||
alias Lexdee.Networks | ||
|
||
@path "/leases" | ||
|
||
@spec index(Tesla.Client.t(), binary(), Keyword.t()) :: | ||
{:error, any} | {:ok, Tesla.Env.t()} | ||
def index(client, id, opts \\ []) do | ||
path = | ||
[Networks.base_path(), id, @path] | ||
|> Path.join() | ||
|
||
get(client, path, opts) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule Lexdee.Networks.LeasesTest do | ||
use ExUnit.Case | ||
|
||
describe "list network leases" do | ||
setup do | ||
response = | ||
File.read!( | ||
"test/support/fixtures/responses/networks/leases/success.json" | ||
) | ||
|
||
bypass = Bypass.open() | ||
|
||
client = Lexdee.create_client("http://localhost:#{bypass.port}") | ||
|
||
{:ok, client: client, bypass: bypass, response: response} | ||
end | ||
|
||
test "return list of leases", %{ | ||
bypass: bypass, | ||
client: client, | ||
response: response | ||
} do | ||
Bypass.expect(bypass, "GET", "/1.0/networks/lxdfan0/leases", fn conn -> | ||
conn | ||
|> Plug.Conn.put_resp_header("content-type", "application/json") | ||
|> Plug.Conn.resp(200, response) | ||
end) | ||
|
||
assert {:ok, %{body: body}} = | ||
Lexdee.list_network_leases(client, "lxdfan0") | ||
|
||
assert Enum.count(body) == 2 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Lexdee.NetworksTest do | ||
use ExUnit.Case | ||
|
||
describe "list networks with recursive option" do | ||
setup do | ||
response = | ||
File.read!( | ||
"test/support/fixtures/responses/networks/index_recursive_one.json" | ||
) | ||
|
||
bypass = Bypass.open() | ||
|
||
client = Lexdee.create_client("http://localhost:#{bypass.port}") | ||
|
||
{:ok, bypass: bypass, response: response, client: client} | ||
end | ||
|
||
test "return list of networks", %{ | ||
bypass: bypass, | ||
client: client, | ||
response: response | ||
} do | ||
Bypass.expect(bypass, "GET", "/1.0/networks", fn conn -> | ||
assert %{"recursive" => "1"} = conn.query_params | ||
|
||
conn | ||
|> Plug.Conn.put_resp_header("content-type", "application/json") | ||
|> Plug.Conn.resp(200, response) | ||
end) | ||
|
||
assert {:ok, %{body: body}} = | ||
Lexdee.list_networks(client, query: [recursive: 1]) | ||
|
||
assert %{"name" => "lxdfan0"} = | ||
Enum.find(body, fn network -> | ||
network["managed"] | ||
end) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"type": "sync", | ||
"status": "Success", | ||
"status_code": 200, | ||
"operation": "", | ||
"error_code": 0, | ||
"error": "", | ||
"metadata": [ | ||
{ | ||
"config": { | ||
"bridge.mode": "fan", | ||
"fan.underlay_subnet": "10.130.0.0/16", | ||
"ipv4.nat": "true" | ||
}, | ||
"description": "", | ||
"name": "lxdfan0", | ||
"type": "bridge", | ||
"used_by": [ | ||
"/1.0/profiles/default", | ||
"/1.0/instances/artellectual-web-01", | ||
"/1.0/instances/helipad-web-test-01" | ||
], | ||
"managed": true, | ||
"status": "Created", | ||
"locations": [ | ||
"ubuntu-s-1vcpu-1gb-sgp1-01" | ||
] | ||
}, | ||
{ | ||
"config": {}, | ||
"description": "", | ||
"name": "lo", | ||
"type": "loopback", | ||
"used_by": [], | ||
"managed": false, | ||
"status": "", | ||
"locations": null | ||
}, | ||
{ | ||
"config": {}, | ||
"description": "", | ||
"name": "eth0", | ||
"type": "physical", | ||
"used_by": null, | ||
"managed": false, | ||
"status": "", | ||
"locations": null | ||
}, | ||
{ | ||
"config": {}, | ||
"description": "", | ||
"name": "eth1", | ||
"type": "physical", | ||
"used_by": null, | ||
"managed": false, | ||
"status": "", | ||
"locations": null | ||
}, | ||
{ | ||
"config": {}, | ||
"description": "", | ||
"name": "lxdfan0-mtu", | ||
"type": "unknown", | ||
"used_by": null, | ||
"managed": false, | ||
"status": "", | ||
"locations": null | ||
}, | ||
{ | ||
"config": {}, | ||
"description": "", | ||
"name": "lxdfan0-fan", | ||
"type": "unknown", | ||
"used_by": null, | ||
"managed": false, | ||
"status": "", | ||
"locations": null | ||
} | ||
] | ||
} |
80 changes: 80 additions & 0 deletions
80
test/support/fixtures/responses/networks/index_recursive_one.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"type": "sync", | ||
"status": "Success", | ||
"status_code": 200, | ||
"operation": "", | ||
"error_code": 0, | ||
"error": "", | ||
"metadata": [ | ||
{ | ||
"config": { | ||
"bridge.mode": "fan", | ||
"fan.underlay_subnet": "10.130.0.0/16", | ||
"ipv4.nat": "true" | ||
}, | ||
"description": "", | ||
"name": "lxdfan0", | ||
"type": "bridge", | ||
"used_by": [ | ||
"/1.0/profiles/default", | ||
"/1.0/instances/artellectual-web-01", | ||
"/1.0/instances/helipad-web-test-01" | ||
], | ||
"managed": true, | ||
"status": "Created", | ||
"locations": [ | ||
"ubuntu-s-1vcpu-1gb-sgp1-01" | ||
] | ||
}, | ||
{ | ||
"config": {}, | ||
"description": "", | ||
"name": "lo", | ||
"type": "loopback", | ||
"used_by": [], | ||
"managed": false, | ||
"status": "", | ||
"locations": null | ||
}, | ||
{ | ||
"config": {}, | ||
"description": "", | ||
"name": "eth0", | ||
"type": "physical", | ||
"used_by": null, | ||
"managed": false, | ||
"status": "", | ||
"locations": null | ||
}, | ||
{ | ||
"config": {}, | ||
"description": "", | ||
"name": "eth1", | ||
"type": "physical", | ||
"used_by": null, | ||
"managed": false, | ||
"status": "", | ||
"locations": null | ||
}, | ||
{ | ||
"config": {}, | ||
"description": "", | ||
"name": "lxdfan0-mtu", | ||
"type": "unknown", | ||
"used_by": null, | ||
"managed": false, | ||
"status": "", | ||
"locations": null | ||
}, | ||
{ | ||
"config": {}, | ||
"description": "", | ||
"name": "lxdfan0-fan", | ||
"type": "unknown", | ||
"used_by": null, | ||
"managed": false, | ||
"status": "", | ||
"locations": null | ||
} | ||
] | ||
} |
24 changes: 24 additions & 0 deletions
24
test/support/fixtures/responses/networks/leases/success.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"type": "sync", | ||
"status": "Success", | ||
"status_code": 200, | ||
"operation": "", | ||
"error_code": 0, | ||
"error": "", | ||
"metadata": [ | ||
{ | ||
"hostname": "helipad-web-test-01", | ||
"hwaddr": "00:16:3e:8c:10:7b", | ||
"address": "240.0.3.227", | ||
"type": "dynamic", | ||
"location": "ubuntu-s-1vcpu-1gb-sgp1-01" | ||
}, | ||
{ | ||
"hostname": "artellectual-web-01", | ||
"hwaddr": "00:16:3e:ec:13:2f", | ||
"address": "240.0.3.194", | ||
"type": "dynamic", | ||
"location": "ubuntu-s-1vcpu-1gb-sgp1-01" | ||
} | ||
] | ||
} |
Oops, something went wrong.