Permalink
Browse files

Merge branch 'dev'

  • Loading branch information...
2 parents 3fcab84 + 50eab25 commit d40c94d5fcbe595066565c0265dbaa6ad107b96e @Licenser Licenser committed Nov 13, 2013
View
@@ -2,7 +2,16 @@ REBAR = $(shell pwd)/rebar
.PHONY: deps rel stagedevrel version
-all: deps compile
+all: cp-hooks deps compile
+
+cp-hooks:
+ cp hooks/* .git/hooks
+
+quick-xref:
+ $(REBAR) xref skip_deps=true
+
+quick-test:
+ $(REBAR) skip_deps=true eunit
version:
echo "$(shell git symbolic-ref HEAD 2> /dev/null | cut -b 12-)-$(shell git log --pretty=format:'%h, %ad' -1)" > wiggle.version
@@ -28,6 +37,7 @@ test: all
$(REBAR) skip_deps=true eunit
rel: all zabbix
+ -rm -r rel/wiggle/share
$(REBAR) generate
relclean:
@@ -1,7 +1,7 @@
{application, wiggle,
[
{description, ""},
- {vsn, "0.5.0"},
+ {vsn, "0.5.1"},
{registered, []},
{applications, [
kernel,
@@ -13,7 +13,13 @@ start(_StartType, _StartArgs) ->
{ok, Port} = application:get_env(wiggle, port),
{ok, Acceptors} = application:get_env(wiggle, acceptors),
+ case (catch eplugin:wait_for_init()) of
+ {'EXIT', Why} -> lager:warning("Error waiting for eplugin init: ~p", [Why]),
+ lager:warning("Your plugins are probably taking too long to load, and some wiggle:dispatchs hooks may not run.");
+ ok -> ok
+ end,
PluginDispatchs = eplugin:fold('wiggle:dispatchs', []),
+
Dispatch = cowboy_router:compile(
[{'_', [{<<"/api/:version/users/[...]">>,
wiggle_rest_handler, [wiggle_user_handler]},
@@ -23,7 +23,15 @@ e(Code, Msg, Req) ->
{shutdown, Req1}.
websocket_init(_Any, Req, []) ->
- {ID, Req1} = cowboy_req:binding(uuid, Req),
+ Req0 = case cowboy_req:parse_header(<<"sec-websocket-protocol">>, Req) of
+ {undefined, _, ReqR} ->
+ ReqR;
+ {ok, [], ReqR} ->
+ ReqR;
+ {ok, [P |_], ReqR} ->
+ cowboy_req:set_resp_header(<<"sec-websocket-protocol">>, P, ReqR)
+ end,
+ {ID, Req1} = cowboy_req:binding(uuid, Req0),
Req2 = wiggle_handler:set_access_header(Req1),
case wiggle_handler:get_token(Req2) of
{undefined, Req3} ->
@@ -126,7 +126,17 @@ delete(Req, State = #state{path = [Dataset, <<"metadata">> | Path]}) ->
{true, Req, State};
delete(Req, State = #state{path = [Dataset]}) ->
- Start = now(),
- ok = libsniffle:dataset_delete(Dataset),
- ?MSniffle(?P(State), Start),
- {true, Req, State}.
+ case libsniffle:dataset_get(Dataset) of
+ {ok, D} ->
+ case jsxd:get(<<"imported">>, D) of
+ {ok, 1} ->
+ Start = now(),
+ ok = libsniffle:dataset_delete(Dataset),
+ ?MSniffle(?P(State), Start),
+ {true, Req, State};
+ _ ->
+ {409, Req, State}
+ end;
+ _ ->
+ {404, Req, State}
+ end.
@@ -21,6 +21,9 @@ allowed_methods(_Version, _Token, []) ->
allowed_methods(_Version, _Token, [_Hypervisor]) ->
[<<"GET">>];
+allowed_methods(_Version, _Token, [_Hypervisor, <<"config">>|_]) ->
+ [<<"PUT">>];
+
allowed_methods(_Version, _Token, [_Hypervisor, <<"characteristics">>|_]) ->
[<<"PUT">>, <<"DELETE">>];
@@ -39,6 +42,9 @@ permission_required(#state{path = []}) ->
permission_required(#state{method = <<"GET">>, path = [Hypervisor]}) ->
{ok, [<<"hypervisors">>, Hypervisor, <<"get">>]};
+permission_required(#state{method = <<"PUT">>, path = [Hypervisor, <<"config">> | _]}) ->
+ {ok, [<<"hypervisors">>, Hypervisor, <<"edit">>]};
+
permission_required(#state{method = <<"PUT">>, path = [Hypervisor, <<"metadata">> | _]}) ->
{ok, [<<"hypervisors">>, Hypervisor, <<"edit">>]};
@@ -75,6 +81,13 @@ read(Req, State = #state{path = [_Hypervisor], obj = Obj}) ->
%% PUT
%%--------------------------------------------------------------------
+write(Req, State = #state{path = [Hypervisor, <<"config">>]},
+ [{<<"alias">>, V}]) when is_binary(V)->
+ Start = now(),
+ libsniffle:hypervisor_set(Hypervisor, [<<"alias">>], V),
+ ?MSniffle(?P(State), Start),
+ {true, Req, State};
+
write(Req, State = #state{path = [Hypervisor, <<"characteristics">> | Path]}, [{K, V}]) ->
Start = now(),
libsniffle:hypervisor_set(Hypervisor, [<<"characteristics">> | Path] ++ [K], jsxd:from_list(V)),
@@ -125,7 +125,7 @@ write(Req, State = #state{method = <<"POST">>, path = []}, _) ->
write(Req, State = #state{path = [Network, <<"metadata">> | Path]}, [{K, V}]) ->
Start = now(),
- libsniffle:network_set(Network, [<<"metadata">> | Path] ++ [K], jsxd:from_list(V)),
+ libsniffle:network_set(Network, Path ++ [K], jsxd:from_list(V)),
?MSniffle(?P(State), Start),
{true, Req, State};
@@ -138,7 +138,7 @@ write(Req, State, _Body) ->
delete(Req, State = #state{path = [Network, <<"metadata">> | Path]}) ->
Start = now(),
- libsniffle:network_set(Network, [<<"metadata">> | Path], delete),
+ libsniffle:network_set(Network, Path, delete),
?MSniffle(?P(State), Start),
{true, Req, State};
@@ -80,7 +80,8 @@ read(Req, State = #state{path = [_Package], obj = Obj}) ->
%%--------------------------------------------------------------------
create(Req, State = #state{path = [], version = Version}, Data) ->
- Data1 = jsxd:select([<<"cpu_cap">>,<<"quota">>, <<"ram">>, <<"requirements">>], Data),
+ Data1 = jsxd:select([<<"cpu_cap">>, <<"quota">>, <<"ram">>,
+ <<"requirements">>, <<"zfs_io_priority">>], Data),
{ok, Package} = jsxd:get(<<"name">>, Data),
case libsniffle:package_create(Package) of
{ok, UUID} ->
@@ -182,7 +182,23 @@ write(Req, State = #state{module = M, body = Data}) ->
delete_resource(Req, State = #state{module = M, body = undefined}) ->
{ok, Data, Req1} = wiggle_handler:decode(Req),
- M:delete(Req1, State#state{body = Data});
+ case M:delete(Req1, State#state{body = Data}) of
+ {N, Req2, State1} when is_number(N) ->
+ lager:info("Delete failed with ~p.", [N]),
+ {ok, Req3} = cowboy_req:reply(N, Req2),
+ {false, Req3, State1};
+ {N, _, _} = R ->
+ lager:info("Delete succeeded with ~p.", [N]),
+ R
+ end;
delete_resource(Req, State = #state{module = M}) ->
- M:delete(Req, State).
+ case M:delete(Req, State) of
+ {N, Req1, State1} when is_number(N) ->
+ lager:info("Delete failed with ~p.", [N]),
+ {ok, Req2} = cowboy_req:reply(N, Req1),
+ {false, Req2, State1};
+ {N, _, _} = R ->
+ lager:info("Delete succeeded with ~p.", [N]),
+ R
+ end.
@@ -66,9 +66,10 @@ create(Req, State = #state{path = [], version = Version}, Decoded) ->
Req1 = cowboy_req:set_resp_cookie(<<"x-snarl-token">>, UUID,
[{max_age, 364*24*60*60}], Req),
Req2 = cowboy_req:set_resp_header(<<"x-snarl-token">>, UUID, Req1),
- {{true, <<"/api/", Version/binary, "/sessions/", UUID/binary>>}, Req2, State#state{body = Decoded}};
+ {{true, <<"/api/", Version/binary, "/sessions/", UUID/binary>>},
+ Req2, State#state{body = Decoded}};
_ ->
- {ok, Req1} = cowboy_req:reply(403, [], <<"Forbidden!">>, Req),
+ {ok, Req1} = cowboy_req:reply(401, [], <<"Forbidden!">>, Req),
{halt, Req1, State}
end.
@@ -220,9 +220,18 @@ create(Req, State = #state{path = [Vm, <<"snapshots">>], version = Version}, Dec
create(Req, State = #state{path = [Vm, <<"nics">>], version = Version}, Decoded) ->
{ok, Network} = jsxd:get(<<"network">>, Decoded),
Start = now(),
- R = ok =:= libsniffle:vm_add_nic(Vm, Network),
- ?MSniffle(?P(State), Start),
- {{R, <<"/api/", Version/binary, "/vms/", Vm/binary>>}, Req, State#state{body = Decoded}}.
+ case libsniffle:vm_add_nic(Vm, Network) of
+ ok ->
+ ?MSniffle(?P(State), Start),
+ {{true, <<"/api/", Version/binary, "/vms/", Vm/binary>>},
+ Req, State#state{body = Decoded}};
+ E ->
+ ?MSniffle(?P(State), Start),
+ lager:error("Error adding nic to VM(~p) on network(~p) / ~p", [Vm, Network, E]),
+ {ok, Req1} = cowboy_req:reply(500, Req),
+ lager:error("Could not add nic: ~P"),
+ {halt, Req1, State}
+ end.
write(Req, State = #state{path = [_, <<"nics">>]}, _Body) ->
@@ -22,37 +22,52 @@ e(Code, Msg, Req) ->
{shutdown, Req1}.
websocket_init(_Any, Req, []) ->
- {ID, Req1} = cowboy_req:binding(uuid, Req),
- Req2 = wiggle_handler:set_access_header(Req1),
- case wiggle_handler:get_token(Req2) of
- {undefined, Req3} ->
- e(401, Req3);
- {Token, Req3} ->
- case libsnarl:allowed({token, Token}, [<<"vms">>, ID, <<"console">>]) of
- true ->
- case libsniffle:vm_get(ID) of
- {ok, VM} ->
- case {jsxd:get([<<"info">>, <<"vnc">>, <<"host">>], VM),
- jsxd:get([<<"info">>, <<"vnc">>, <<"port">>], VM)} of
- {{ok, Host}, {ok, Port}} when is_binary(Host),
- is_integer(Port)->
- case gen_tcp:connect(binary_to_list(Host), Port,
- [binary,{nodelay, true}, {packet, 0}]) of
- {ok, Socket} ->
- gen_tcp:controlling_process(Socket, self()),
- Req4 = cowboy_req:compact(Req3),
- {ok, Req4, {Socket}, hibernate};
- E ->
- list_to_binary(io_lib:format("~p", [E]))
+ Req0 = case cowboy_req:parse_header(<<"sec-websocket-protocol">>, Req) of
+ {undefined, _, ReqR} -> ReqR;
+ {ok, List, ReqR} ->
+ case lists:member(<<"base64">>, List) of
+ true ->
+ cowboy_req:set_resp_header(<<"sec-websocket-protocol">>, <<"base64">>, ReqR);
+ _ ->
+ {stop, ReqR}
+ end
+ end,
+ case Req0 of
+ {stop, ReqR1} ->
+ e(400, ReqR1);
+ _ ->
+ {ID, Req1} = cowboy_req:binding(uuid, Req0),
+ Req2 = wiggle_handler:set_access_header(Req1),
+ case wiggle_handler:get_token(Req2) of
+ {undefined, Req3} ->
+ e(401, Req3);
+ {Token, Req3} ->
+ case libsnarl:allowed({token, Token}, [<<"vms">>, ID, <<"console">>]) of
+ true ->
+ case libsniffle:vm_get(ID) of
+ {ok, VM} ->
+ case {jsxd:get([<<"info">>, <<"vnc">>, <<"host">>], VM),
+ jsxd:get([<<"info">>, <<"vnc">>, <<"port">>], VM)} of
+ {{ok, Host}, {ok, Port}} when is_binary(Host),
+ is_integer(Port)->
+ case gen_tcp:connect(binary_to_list(Host), Port,
+ [binary,{nodelay, true}, {packet, 0}]) of
+ {ok, Socket} ->
+ gen_tcp:controlling_process(Socket, self()),
+ Req4 = cowboy_req:compact(Req3),
+ {ok, Req4, {Socket}, hibernate};
+ E ->
+ list_to_binary(io_lib:format("~p", [E]))
+ end;
+ _ ->
+ e(404, <<"could not find vnc">>, Req3)
end;
- _ ->
- e(404, <<"could not find vnc">>, Req3)
+ E ->
+ e(404, list_to_binary(io_lib:format("~p", [E])), Req3)
end;
- E ->
- e(404, list_to_binary(io_lib:format("~p", [E])), Req3)
- end;
- false ->
- e(401, Req3)
+ false ->
+ e(401, Req3)
+ end
end
end.
View
@@ -8,3 +8,4 @@
^newrelic.erl
^glc_code.erl:
^lager.erl
+^msgpack.erl:185
@@ -1,4 +1,4 @@
-cat <<EOF > wiggle_template.xml
+cat <<EOF > share/wiggle_template.xml
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
View
@@ -0,0 +1,32 @@
+#!/bin/sh
+#
+# An example hook script to verify what is about to be committed.
+# Called by "git commit" with no arguments. The hook should
+# exit with non-zero status after issuing an appropriate message if
+# it wants to stop the commit.
+#
+# To enable this hook, rename this file to "pre-commit".
+
+if git rev-parse --verify HEAD >/dev/null 2>&1
+then
+ against=HEAD
+else
+ # Initial commit: diff against an empty tree object
+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
+fi
+
+make quick-xref
+RETVAL=$?
+if [ $RETVAL -ne 0 ]
+then
+ echo "XRef failed."
+ exit 1
+fi
+
+make quick-test
+RETVAL=$?
+if [ $RETVAL -ne 0 ]
+then
+ echo "Test failed."
+ exit 1
+fi
View
@@ -10,14 +10,14 @@
{edoc_opts, [{dir, "../../doc"}]}.
{deps,
[
- {lager, ".*", {git, "git://github.com/basho/lager.git", {tag, "2.0.0"}}},
+ {lager, ".*", {git, "https://github.com/basho/lager.git", {tag, "2.0.0"}}},
{newrelic, ".*", {git, "https://github.com/wooga/newrelic-erlang.git", {tag, "master"}}},
- {jsx, ".*", {git, "http://github.com/talentdeficit/jsx.git", {tag, "v1.4.2"}}},
+ {jsx, ".*", {git, "http://github.com/talentdeficit/jsx.git", {tag, "v1.4.3"}}},
{mimetypes, ".*", {git, "http://github.com/spawngrid/mimetypes.git", {tag, "1.0"}}},
{cowboy, ".*", {git, "https://github.com/extend/cowboy.git", {tag, "0.8.6"}}},
- {eplugin, ".*", {git, "http://github.com/Licenser/eplugin.git", {tag, "0.1.1"}}},
+ {eplugin, ".*", {git, "http://github.com/Licenser/eplugin.git", {tag, "0.1.2"}}},
+ {msgpack, ".*", {git, "https://github.com/project-fifo/msgpack-erlang.git", {tag, "0.2.3-dialyzer"}}},
{statman, ".*", {git, "https://github.com/Licenser/statman.git", {tag, "master"}}},
- {msgpack, ".*", {git, "git://github.com/msgpack/msgpack-erlang.git", {tag, "0.1.2"}}},
{jsxd, ".*", {git, "https://github.com/Licenser/jsxd.git", {tag, "0.1.6"}}},
{fifo_spec, ".*", {git, "https://github.com/project-fifo/fifo_spec.git", {tag, "0.1.3"}}},
{libchunter, ".*", {git, "http://github.com/project-fifo/libchunter.git", {tag, "0.1.9"}}},
View
@@ -1,11 +1,12 @@
-VERSION=0.5.0
-COMPONENT=wiggle
+VERSION=0.5.1
+COMPONENT_INTERNAL=wiggle
+COMPONENT=fifo-wiggle
.PHONY: build_info package package_list
package_list:
echo "@pkgdep erlang>=15.1.1" > packlist
- (cd ../$(COMPONENT); find * -type f | sort) >> packlist
+ (cd ../$(COMPONENT_INTERNAL); find * -type f | sort) >> packlist
build_info:
pkg_info -X pkg_install | egrep '^(MACHINE_ARCH|OPSYS|OS_VERSION|PKGTOOLS_VERSION)' >build-info
echo "CATEGORIES=fifo" >>build-info
@@ -15,4 +16,4 @@ clean:
-rm *.tgz build-info packlist
package: package_list build_info
- pkg_create -i install.sh -k deinstall.sh -D displayfile -B build-info -c comment -d description -f packlist -I /opt/local/$(COMPONENT) -p ../$(COMPONENT) -U $(COMPONENT)-$(VERSION)$(SUFFIX).tgz
+ pkg_create -i install.sh -k deinstall.sh -D displayfile -B build-info -c comment -d description -f packlist -I /opt/local/$(COMPONENT) -p ../$(COMPONENT_INTERNAL) -U $(COMPONENT)-$(VERSION)$(SUFFIX).tgz
View
@@ -5,11 +5,11 @@
| |
| Please have a look at the configuraiton files: |
| |
-| * /opt/local/wiggle/etc/app.config |
+| * /opt/local/fifo-wiggle/etc/app.config |
| * You can change the listening port." |
| * You can change the number of acceptors to spawn. |
| |
-| * /opt/local/wiggle/etc/vm.args |
+| * /opt/local/fifo-wiggle/etc/vm.args |
| * You will need to change the IP in the nodename to either a resolvable |
| hostname or the IP in the controll network. |
| |
Oops, something went wrong.

0 comments on commit d40c94d

Please sign in to comment.