Last active
December 16, 2015 10:19
-
-
Save arekinath/5419243 to your computer and use it in GitHub Desktop.
Choose a random hypervisor for sniffle
This file contains hidden or 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
diff --git a/apps/sniffle/src/sniffle_create_fsm.erl b/apps/sniffle/src/sniffle_create_fsm.erl | |
index f72ce59..2e94fb9 100644 | |
--- a/apps/sniffle/src/sniffle_create_fsm.erl | |
+++ b/apps/sniffle/src/sniffle_create_fsm.erl | |
@@ -99,6 +99,7 @@ create(UUID, Package, Dataset, Config) -> | |
%%-------------------------------------------------------------------- | |
init([UUID, Package, Dataset, Config]) -> | |
process_flag(trap_exit, true), | |
+ random:seed(now()), | |
Config1 = jsxd:from_list(Config), | |
%% We're transforming the networks map {nic -> networkid} into | |
%% an array that is close to what it will look after the VM was | |
@@ -258,7 +259,11 @@ get_server(_Event, State = #state{ | |
{UUID, Config, Conditions} = eplugin:fold('create:conditions', {UUID, Config, Conditions2}), | |
CondB = list_to_binary(io_lib:format("~p", [Conditions])), | |
sniffle_vm:log(UUID, <<"Finding hypervisor ", CondB/binary>>), | |
- {ok, [{HypervisorID, _} | _]} = sniffle_hypervisor:list(Conditions), | |
+ {ok, AllCandidates} = sniffle_hypervisor:list(Conditions), | |
+ [{_, TopWeight} | _] = AllCandidates, | |
+ Candidates = lists:keytake(TopWeight, 2, AllCandidates), | |
+ HypIndex = random:uniform(length(Candidates)), | |
+ {HypervisorID, _} = lists:nth(HypIndex, Candidates), | |
sniffle_vm:log(UUID, <<"Deploying on hypervisor ", HypervisorID/binary>>), | |
{ok, H} = sniffle_hypervisor:get(HypervisorID), | |
{ok, Port} = jsxd:get(<<"port">>, H), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment