fix network
This commit is contained in:
parent
217674b3dd
commit
c89091c205
@ -15,6 +15,8 @@
|
||||
-export([get_all_networks/0, get_network/1]).
|
||||
-export([auth_token/3, node_online/3, node_offline/2, flow_report/5, network_forward_report/2, auth_network_code/3]).
|
||||
|
||||
-export([assign_ip_address/5]).
|
||||
|
||||
-spec get_all_networks() -> {ok, [NetworkId :: integer()]} | {error, Reason :: any()}.
|
||||
get_all_networks() ->
|
||||
case catch do_get("get_all_networks", []) of
|
||||
@ -75,6 +77,27 @@ auth_network_code(ClientId, NetworkCode, Version) when is_binary(ClientId), is_b
|
||||
Error
|
||||
end.
|
||||
|
||||
%% 请求ip地址的分配
|
||||
assign_ip_address(NetworkId, ClientId, Mac, RetainIp, HostName) when is_integer(NetworkId), is_binary(ClientId), is_binary(Mac), is_integer(RetainIp), is_binary(HostName) ->
|
||||
Params = #{
|
||||
<<"network_id">> => NetworkId,
|
||||
<<"client_id">> => ClientId,
|
||||
<<"mac">> => Mac,
|
||||
<<"retain_ip">> => RetainIp,
|
||||
<<"host_name">> => HostName
|
||||
},
|
||||
case catch do_post("assign_ip_address", Params) of
|
||||
{ok, Resp} ->
|
||||
case catch jiffy:decode(Resp, [return_maps]) of
|
||||
Result when is_map(Result) ->
|
||||
{ok, Result};
|
||||
{error, Reason} ->
|
||||
{error, Reason}
|
||||
end;
|
||||
Error ->
|
||||
Error
|
||||
end.
|
||||
|
||||
-spec node_online(ClientId :: binary(), NetworkId :: integer(), IpAddr :: binary()) -> {ok, Resp :: map()} | {error, Reason :: any()}.
|
||||
node_online(ClientId, NetworkId, IpAddr) when is_binary(ClientId), is_integer(NetworkId), is_binary(IpAddr) ->
|
||||
case catch do_post("set_node_status", #{<<"client_id">> => ClientId, <<"network_id">> => NetworkId, <<"ip_addr">> => IpAddr, <<"status">> => 1}) of
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
-author("anlicheng").
|
||||
|
||||
%% API
|
||||
-export([init/0, lookup/1, insert/2]).
|
||||
-export([init/0, lookup/1, insert/2, insert/3]).
|
||||
|
||||
-define(TABLE, sdlan_hostname_regedit).
|
||||
|
||||
@ -26,6 +26,13 @@ lookup(FullHostname) when is_binary(FullHostname) ->
|
||||
error
|
||||
end.
|
||||
|
||||
-spec insert(any(), Domain :: binary(), Ip :: integer()) -> no_return().
|
||||
insert(<<>>, _Domain, _Ip) ->
|
||||
ok;
|
||||
insert(HostName, Domain, Ip) when is_integer(HostName), is_binary(Domain), is_integer(Ip) ->
|
||||
FullHostname = <<HostName/binary, ".", Domain/binary>>,
|
||||
insert(FullHostname, Ip).
|
||||
|
||||
-spec insert(FullHostname :: binary(), Ip :: integer()) -> no_return().
|
||||
insert(FullHostname, Ip) when is_binary(FullHostname), is_integer(Ip) ->
|
||||
<<Ip0, Ip1, Ip2, Ip3>> = <<Ip:32>>,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user