public async Task <HttpResponseData> CreateNode([HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "testhooks/nodeOperations/node")] HttpRequestData req)
        {
            _log.Info("create node");

            var query = UriExtension.GetQueryComponents(req.Url);

            Guid   poolId    = Guid.Parse(query["poolId"]);
            string poolName  = query["poolName"];
            Guid   machineId = Guid.Parse(query["machineId"]);

            Guid?scaleSetId = default;

            if (query.ContainsKey("scaleSetId"))
            {
                scaleSetId = Guid.Parse(query["scaleSetId"]);
            }

            string version = query["version"];

            bool isNew = UriExtension.GetBoolValue("isNew", query, false);

            var node = await _nodeOps.Create(poolId, poolName, machineId, scaleSetId, version, isNew);

            var resp = req.CreateResponse(HttpStatusCode.OK);
            await resp.WriteAsJsonAsync(JsonSerializer.Serialize(node, EntityConverter.GetJsonSerializerOptions()));

            return(resp);
        }
        public async Task <HttpResponseData> SearchStates([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "testhooks/nodeOperations/searchStates")] HttpRequestData req)
        {
            _log.Info("search states");

            var query = UriExtension.GetQueryComponents(req.Url);

            Guid?poolId = default;

            if (query.ContainsKey("poolId"))
            {
                poolId = Guid.Parse(query["poolId"]);
            }

            Guid?scaleSetId = default;

            if (query.ContainsKey("scaleSetId"))
            {
                scaleSetId = Guid.Parse(query["scaleSetId"]);
            }

            List <NodeState>?states = default;

            if (query.ContainsKey("states"))
            {
                states = query["states"].Split('-').Select(s => Enum.Parse <NodeState>(s)).ToList();
            }

            string?poolName = default;

            if (query.ContainsKey("poolName"))
            {
                poolName = query["poolName"];
            }

            var excludeUpdateScheduled = UriExtension.GetBoolValue("excludeUpdateScheduled", query, false);
            int?numResults             = default;

            if (query.ContainsKey("numResults"))
            {
                numResults = int.Parse(query["numResults"]);
            }
            var r = _nodeOps.SearchStates(poolId, scaleSetId, states, poolName, excludeUpdateScheduled, numResults);


            var json = JsonSerializer.Serialize(await r.ToListAsync(), EntityConverter.GetJsonSerializerOptions());
            var resp = req.CreateResponse(HttpStatusCode.OK);
            await resp.WriteStringAsync(json);

            return(resp);
        }
        public async Task <HttpResponseData> ToReimage([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "testhooks/nodeOperations/toReimage")] HttpRequestData req)
        {
            _log.Info("to reimage");

            var query = UriExtension.GetQueryComponents(req.Url);
            var done  = UriExtension.GetBoolValue("done", query, false);

            var s = await req.ReadAsStringAsync();

            var node = JsonSerializer.Deserialize <Node>(s !, EntityConverter.GetJsonSerializerOptions());

            var r    = _nodeOps.ToReimage(node !, done);
            var resp = req.CreateResponse(HttpStatusCode.OK);
            await resp.WriteAsJsonAsync(r);

            return(resp);
        }