Unified
Split
Showing
with
46 additions
and 9 deletions.
- +38 −1 apps/wiggle/src/wiggle_hypervisor_handler.erl
- +8 −8 apps/wiggle/src/wiggle_vm_handler.erl
| @@ -28,7 +28,10 @@ allowed_methods(_Version, _Token, [_Hypervisor, <<"characteristics">>|_]) -> | ||
| [<<"PUT">>, <<"DELETE">>]; | ||
|
|
||
| allowed_methods(_Version, _Token, [_Hypervisor, <<"metadata">>|_]) -> | ||
| [<<"PUT">>, <<"DELETE">>]. | ||
| [<<"PUT">>, <<"DELETE">>]; | ||
|
|
||
| allowed_methods(_Version, _Token, [_Hypervisor, <<"services">>]) -> | ||
| [<<"PUT">>, <<"GET">>]. | ||
|
|
||
| get(State = #state{path = [Hypervisor | _]}) -> | ||
| Start = now(), | ||
| @@ -57,6 +60,12 @@ permission_required(#state{method = <<"PUT">>, path = [Hypervisor, <<"characteri | ||
| permission_required(#state{method = <<"DELETE">>, path = [Hypervisor, <<"characteristics">> | _]}) -> | ||
| {ok, [<<"hypervisors">>, Hypervisor, <<"edit">>]}; | ||
|
|
||
| permission_required(#state{method = <<"GET">>, path = [Hypervisor, <<"services">>]}) -> | ||
| {ok, [<<"hypervisors">>, Hypervisor, <<"get">>]}; | ||
|
|
||
| permission_required(#state{method = <<"PUT">>, path = [Hypervisor, <<"services">>]}) -> | ||
| {ok, [<<"hypervisors">>, Hypervisor, <<"edit">>]}; | ||
|
|
||
| permission_required(_State) -> | ||
| undefined. | ||
|
|
||
| @@ -81,6 +90,16 @@ read(Req, State = #state{token = Token, path = [], full_list=FullList, full_list | ||
| end, | ||
| {Res1, Req, State}; | ||
|
|
||
| read(Req, State = #state{path = [_Hypervisor, <<"services">>], obj = Obj}) -> | ||
| Snaps = jsxd:fold(fun(UUID, Snap, Acc) -> | ||
| [jsxd:set(<<"uuid">>, UUID, Snap) | Acc] | ||
| end, [], jsxd:get(<<"services">>, [], Obj)), | ||
| {Snaps, Req, State}; | ||
|
|
||
| read(Req, State = #state{path = [_Hypervisor, <<"services">>, Service], | ||
| obj = Obj = [{_,_}|_]}) when is_binary(Service) -> | ||
| {jsxd:get([<<"services">>, Service], [{}], Obj), Req, State}; | ||
|
|
||
| read(Req, State = #state{path = [_Hypervisor], obj = Obj}) -> | ||
| {Obj, Req, State}. | ||
|
|
||
| @@ -108,6 +127,24 @@ write(Req, State = #state{path = [Hypervisor, <<"metadata">> | Path]}, [{K, V}]) | ||
| ?MSniffle(?P(State), Start), | ||
| {true, Req, State}; | ||
|
|
||
| write(Req, State = #state{path = [Hypervisor, <<"services">>]}, | ||
| [{<<"action">>, <<"enable">>}, | ||
| {<<"service">>, Service}]) -> | ||
| libsniffle:hypervisor_service_action(Hypervisor, enable, Service), | ||
| {true, Req, State}; | ||
|
|
||
| write(Req, State = #state{path = [Hypervisor, <<"services">>]}, | ||
| [{<<"action">>, <<"disable">>}, | ||
| {<<"service">>, Service}]) -> | ||
| libsniffle:hypervisor_service_action(Hypervisor, disable, Service), | ||
| {true, Req, State}; | ||
|
|
||
| write(Req, State = #state{path = [Hypervisor, <<"services">>]}, | ||
| [{<<"action">>, <<"clear">>}, | ||
| {<<"service">>, Service}]) -> | ||
| libsniffle:hypervisor_service_action(Hypervisor, clear, Service), | ||
| {true, Req, State}; | ||
|
|
||
| write(Req, State, _Body) -> | ||
| {false, Req, State}. | ||
|
|
||
| @@ -277,9 +277,9 @@ read(Req, State = #state{path = [_Vm, <<"backups">>, Snap], obj = Obj}) -> | ||
| {jsxd:set(<<"uuid">>, Snap, SnapObj), Req, State} | ||
| end; | ||
|
|
||
| read(Req, State = #state{path = [_Vm, <<"services">>, Snap], | ||
| obj = Obj = [{_,_}|_]}) when is_binary(Snap) -> | ||
| {jsxd:get([<<"services">>, Snap], [{}], Obj), Req, State}; | ||
| read(Req, State = #state{path = [_Vm, <<"services">>, Service], | ||
| obj = Obj = [{_,_}|_]}) when is_binary(Service) -> | ||
| {jsxd:get([<<"services">>, Service], [{}], Obj), Req, State}; | ||
|
|
||
| read(Req, State = #state{path = [_Vm], obj = Obj}) -> | ||
| {Obj, Req, State}. | ||
| @@ -299,11 +299,11 @@ create(Req, State = #state{path = [], version = Version, token = Token}, Decoded | ||
| Config1 = case libsnarl:allowed( | ||
| Token, | ||
| [<<"cloud">>, <<"vms">>, <<"advanced_create">>]) of | ||
| true -> | ||
| Config; | ||
| _ -> | ||
| jsxd:set(<<"requirements">>, [], Config) | ||
| end, | ||
| true -> | ||
| Config; | ||
| _ -> | ||
| jsxd:set(<<"requirements">>, [], Config) | ||
| end, | ||
| try | ||
| {ok, User} = libsnarl:user_get(Token), | ||
| {ok, Owner} = jsxd:get(<<"uuid">>, User), | ||