示例#1
0
 public override Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth, NodeOptions options)
 {
     LinodeNodeOptions ops = options as LinodeNodeOptions;
     if (ops == null && options != null)
         throw new Exception ("Only LinodeNodeOptions can be used as NodeOptions for creating Linode Nodes.");
     else if (ops == null)
         ops = new LinodeNodeOptions ();
     return API.CreateNode (name, size, image, location, auth, ops);
 }
示例#2
0
        public Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth, LinodeNodeOptions options)
        {
            int rsize = size.Disk - options.SwapSize;

            string kernel = FindKernel (options);

            LinodeRequest request = new LinodeRequest ("linode.create", new Dictionary<string,object> {
                {"DatacenterID", location.Id}, {"PlanID", size.Id},
                {"PaymentTerm", (int) options.PaymentTerm}});
            LinodeResponse response = Execute (request);

            JObject node = response.Data [0];
            string id = node ["LinodeID"].ToString ();

            string root_pass;
            if (auth.Type == NodeAuthType.Password)
                root_pass = auth.Secret;
            else
                root_pass = GenerateRandomPassword ();

            request = new LinodeRequest ("linode.disk.createfromdistribution", new Dictionary<string,object> {
                {"LinodeID", id}, {"DistributionID", image.Id}, {"Label", name}, {"Size", rsize},
                {"rootPass", root_pass}});

            if (auth.Type == NodeAuthType.SSHKey)
                request.Parameters.Add ("rootSSHKey", auth.Secret);

            response = Execute (request);

            JObject distro = response.Data [0];
            string root_disk = distro ["DiskID"].ToString ();

            request = new LinodeRequest ("linode.disk.create", new Dictionary<string,object> {
                {"LinodeID", id}, {"Label", "Swap"}, {"Type", "swap"}, {"Size", options.SwapSize}});
            response = Execute (request);

            string swap_disk = response.Data [0] ["DiskID"].ToString ();
            string disks = String.Format ("{0},{1},,,,,,,", root_disk, swap_disk);

            request = new LinodeRequest ("linode.config.create", new Dictionary<string,object> {
                {"LinodeID", id}, {"KernelID", kernel}, {"Label", "mcloud config"}, {"DiskList", disks}});
            response = Execute (request);

            string config = response.Data [0]["ConfigID"].ToString ();

            request = new LinodeRequest ("linode.boot", new Dictionary<string,object> {
                {"LinodeID", id}, {"ConfigID", config}});
            response = Execute (request);

            request = new LinodeRequest ("linode.list", new Dictionary<string,object> {{"LinodeID", id}});
            response = Execute (request);

            return LinodeNode.FromData (response.Data [0], driver);
        }
示例#3
0
        public Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, int swap=128)
        {
            int rsize = size.Disk - swap;

            string kernel = FindKernel ();

            Console.WriteLine ("USING KERNEL:  {0}", kernel);

            LinodeRequest request = new LinodeRequest ("linode.create", new Dictionary<string,object> {
                {"DatacenterID", location.Id}, {"PlanID", size.Id},
                {"PaymentTerm", (int) driver.PaymentTerm}});
            LinodeResponse response = Execute (request);

            JObject node = response.Data [0];
            string id = node ["LinodeID"].ToString ();

            request = new LinodeRequest ("linode.disk.createfromdistribution", new Dictionary<string,object> {
                {"LinodeID", id}, {"DistributionID", image.Id}, {"Label", name}, {"Size", size.Disk},
                {"rootPass", "F23444sd"}});

            response = Execute (request);

            JObject distro = response.Data [0];
            string root_disk = distro ["DiskID"].ToString ();

            request = new LinodeRequest ("linode.disk.create", new Dictionary<string,object> {
                {"LinodeID", id}, {"Label", "Swap"}, {"Type", "swap"}, {"Size", swap}});
            response = Execute (request);

            string swap_disk = response.Data [0] ["DiskID"].ToString ();
            string disks = String.Format ("{0},{1},,,,,,,", root_disk, swap_disk);

            request = new LinodeRequest ("linode.config.create", new Dictionary<string,object> {
                {"LinodeID", id}, {"KernelID", kernel}, {"Label", "mcloud config"}, {"DiskList", disks}});
            response = Execute (request);

            string config = response.Data [0]["ConfigID"].ToString ();

            request = new LinodeRequest ("linode.boot", new Dictionary<string,object> {
                {"LinodeID", id}, {"ConfigID", config}});
            response = Execute (request);

            return null;
        }
示例#4
0
        public override Node CreateNode(string name, NodeSize size, NodeImage image, NodeLocation location, NodeAuth auth, NodeOptions options)
        {
            EC2NodeOptions ops = options as EC2NodeOptions;
            if (ops == null && options != null)
                throw new Exception ("Only EC2NodeOptions can be used as NodeOptions for creating EC2 Nodes.");
            else if (ops == null)
                ops = new EC2NodeOptions ();

            RunInstancesRequest request = new RunInstancesRequest () {
                InstanceType = size.Id,
                ImageId = image.Id,
                MinCount = 1,
                MaxCount = 1,
                KeyName = auth.UserName,
            };
            RunInstancesResponse response = Client.RunInstances (request);

            foreach (var i in response.RunInstancesResult.Reservation.RunningInstance) {
                return EC2Node.FromRunningInstance (i, this);
            }

            return null;
        }
示例#5
0
 public Selector Selector(NodeList<Element> elements, NodeLocation location)
 {
     return new Selector(elements) { Location = location };
 }
示例#6
0
 public MixinCall MixinCall(NodeList <Element> elements, List <NamedArgument> arguments, bool important, NodeLocation location)
 {
     return(new MixinCall(elements, arguments, important)
     {
         Location = location
     });
 }
示例#7
0
 public Script Script(string script, NodeLocation location)
 {
     return new Script(script) { Location = location };
 }
示例#8
0
 public Element Element(Combinator combinator, Node value, NodeLocation location)
 {
     return new Element(combinator, value) { Location = location };
 }
示例#9
0
 public Keyword Keyword(string value, NodeLocation location)
 {
     return new Keyword(value) { Location = location };
 }
示例#10
0
 public Assignment Assignment(string key, Node value, NodeLocation location)
 {
     return new Assignment(key, value);
 }
示例#11
0
 public Comment Comment(string value, NodeLocation location)
 {
     return new Comment(value) { Location = location };
 }
示例#12
0
 public LuaJITLongLiteral(NodeLocation location)
     : base(location)
 {
 }
示例#13
0
 public TableAccess(NodeLocation location)
     : base(location)
 {
 }
示例#14
0
 public StringLiteral(NodeLocation location)
     : base(location)
 {
 }
示例#15
0
 public NumberLiteral(NodeLocation location)
     : base(location)
 {
 }
示例#16
0
 protected Node(NodeLocation location)
 {
     this.CurrentIndex  = location.CurrentIndex;
     this.CurrentLine   = location.CurrentLine;
     this.CurrentColumn = location.CurrentColumn;
 }
示例#17
0
 public UnaryOp(OpType type, IExpression expr, NodeLocation location)
     : base(location)
 {
     Type       = type;
     Expression = expr;
 }
示例#18
0
 public BoolLiteral(NodeLocation location)
     : base(location)
 {
 }
示例#19
0
 public TextNode TextNode(string contents, NodeLocation location)
 {
     return new TextNode(contents) { Location = location };
 }
示例#20
0
 public FunctionCall(NodeLocation location)
     : base(location)
 {
 }
示例#21
0
 public Value Value(IEnumerable<Node> values, string important, NodeLocation location)
 {
     return new Value(values, important) { Location = location };
 }
示例#22
0
 public Entry(NodeLocation location)
     : base(location)
 {
 }
示例#23
0
 public Color Color(string rgb, NodeLocation location)
 {
     return new Color(rgb) { Location = location };
 }
示例#24
0
 public TableConstructor(NodeLocation location)
     : base(location)
 {
 }
示例#25
0
 public Directive Directive(string name, string identifier, NodeList rules, NodeLocation location)
 {
     return new Directive(name, identifier, rules) { Location = location };
 }
示例#26
0
 public Break(NodeLocation location)
     : base(location)
 {
 }
示例#27
0
 public Import Import(Quoted path, IImporter importer, Value features, bool isOnce, NodeLocation location)
 {
     return new Import(path, importer, features, isOnce) { Location = location };
 }
示例#28
0
 public Return(NodeLocation location)
     : base(location)
 {
 }
示例#29
0
 public MixinCall MixinCall(NodeList<Element> elements, List<NamedArgument> arguments, bool important, NodeLocation location)
 {
     return new MixinCall(elements, arguments, important) { Location = location };
 }
示例#30
0
 public Block(NodeLocation location)
     : base(location)
 {
 }
示例#31
0
 public GenericFor(NodeLocation location) : base(location)
 {
 }
示例#32
0
        public static void ExpectNodeToBeOneOf <TExpected1, TExpected2>(Node actual, object @in, NodeLocation location) where TExpected1 : Node where TExpected2 : Node
        {
            if (actual is TExpected1 || actual is TExpected2)
            {
                return;
            }

            var expected1 = typeof(TExpected1).Name.ToLowerInvariant();
            var expected2 = typeof(TExpected2).Name.ToLowerInvariant();

            var message = string.Format("Expected {0} or {1} in {2}, found {3}", expected1, expected2, @in, actual.ToCSS(new Env(null)));

            throw new ParsingException(message, location);
        }
示例#33
0
 public Alpha Alpha(Node value, NodeLocation location)
 {
     return new Alpha(value) { Location = location };
 }
示例#34
0
 public static List <TExpected> ExpectAllNodes <TExpected>(IEnumerable <Node> actual, object @in, NodeLocation location) where TExpected : Node
 {
     return(actual.Select(node => ExpectNode <TExpected>(node, @in, location)).ToList());
 }
示例#35
0
 public Shorthand Shorthand(Node first, Node second, NodeLocation location)
 {
     return new Shorthand(first, second) { Location = location };
 }
示例#36
0
 /// <summary>
 /// Initializes a new instance of the ServiceTaskDispatcherInfo class
 /// </summary>
 /// <param name="jobId">indicating the job id</param>
 /// <param name="taskId">indicating the task id</param>
 /// <param name="capacity">indicating the capacity</param>
 /// <param name="machineName">indicating the machine name</param>
 /// <param name="machineVirtualName">indicating the machine virtual name for Azure cluster</param>
 /// <param name="firstCoreId">indicating the first core id</param>
 /// <param name="networkPrefix">indicating the network prefix</param>
 /// <param name="location">indicating target resource location, OnPremise or Azure</param>
 /// <param name="isHttp">indicating whether the service task is opening an HTTP service host</param>
 public ServiceTaskDispatcherInfo(string jobId, string taskId, int capacity, string machineName, string machineVirtualName, int firstCoreId, string networkPrefix, NodeLocation location, bool isHttp)
     : base(taskId, capacity, machineName, machineVirtualName, location)
 {
     this.jobId         = jobId;
     this.taskId        = taskId;
     this.firstCoreId   = firstCoreId;
     this.networkPrefix = networkPrefix;
     this.isHttp        = isHttp;
 }
示例#37
0
 public Url Url(Node value, IImporter importer, NodeLocation location)
 {
     return new Url(value, importer) { Location = location };
 }
示例#38
0
 public ParsingException(string message, NodeLocation location, NodeLocation callLocation) : this(message, null, location, callLocation)
 {
 }
示例#39
0
 public Variable Variable(string name, NodeLocation location)
 {
     return new Variable(name) { Location = location };
 }
示例#40
0
 public ParsingException(Exception innerException, NodeLocation location) : this(innerException, location, null)
 {
 }
示例#41
0
 public Call Call(string name, NodeList<Node> arguments, NodeLocation location)
 {
     return new Call(name, arguments) { Location = location };
 }
示例#42
0
 public ParsingException(Exception innerException, NodeLocation location, NodeLocation callLocation) : this(innerException.Message, innerException, location, callLocation)
 {
 }
示例#43
0
 public Combinator Combinator(string value, NodeLocation location)
 {
     return new Combinator(value) { Location = location };
 }
示例#44
0
 public ParsingException(string message, Exception innerException, NodeLocation location) : this(message, innerException, location, null)
 {
 }
示例#45
0
 public Condition Condition(Node left, string operation, Node right, bool negate, NodeLocation location)
 {
     return new Condition(left, operation, right, negate) { Location = location };
 }
示例#46
0
 public ParsingException(string message, Exception innerException, NodeLocation location, NodeLocation callLocation)
     : base(message, innerException)
 {
     Location     = location;
     CallLocation = callLocation;
 }
示例#47
0
 public Directive Directive(string name, Node value, NodeLocation location)
 {
     return new Directive(name, value) { Location = location };
 }
示例#48
0
 public static NodeLocation GetReverseDirection(this NodeLocation nodeLocation)
 {
     return(nodeLocation + ((int)nodeLocation > DirectionDifference ? -1 : 1) * DirectionDifference);
 }
示例#49
0
 public Expression Expression(NodeList expression, NodeLocation location)
 {
     return new Expression(expression) { Location = location };
 }
示例#50
0
 public NodeInfo(NodeLocation nodeLocation, int docCount, string urlPart)
 {
     mNodeLocation = nodeLocation;
     mDocCount     = docCount;
     mUrlPart      = urlPart;
 }
示例#51
0
 public KeyFrame KeyFrame(string identifier, NodeList rules, NodeLocation location)
 {
     return new KeyFrame(identifier, rules) { Location = location };
 }
示例#52
0
 public override List<NodeImage> ListImages(NodeLocation location)
 {
     return API.ListImages (location);
 }
示例#53
0
 public Media Media(NodeList rules, Value features, NodeLocation location)
 {
     return new Media(features, rules) { Location = location };
 }
示例#54
0
 public VarargsLiteral(NodeLocation location)
     : base(location)
 {
 }
示例#55
0
 public MixinDefinition MixinDefinition(string name, NodeList<Rule> parameters, NodeList rules, Condition condition, bool variadic, NodeLocation location)
 {
     return new MixinDefinition(name, parameters, rules, condition, variadic) { Location = location };
 }
示例#56
0
        static void SearchPath(
            object node,
            RouteRequestBuilder currentMatchedPath,
            string[] segments,
            List <RouteRequestBuilder> possibleRoutePaths,
            int depthToStart,
            int myDepth = -1,
            NodeLocation currentLocation = null,
            bool ignoreGlobalRoutes      = true)
        {
            if (node is GlobalRouteItem && ignoreGlobalRoutes)
            {
                return;
            }

            ++myDepth;
            currentLocation = currentLocation ?? new NodeLocation();
            currentLocation.SetNode(node);

            IEnumerable items = null;

            if (depthToStart > myDepth)
            {
                items = GetItems(node);
                if (items == null)
                {
                    return;
                }

                foreach (var nextNode in items)
                {
                    SearchPath(nextNode, null, segments, possibleRoutePaths, depthToStart, myDepth, currentLocation, ignoreGlobalRoutes);
                }
                return;
            }

            string shellSegment = GetRoute(node);
            string userSegment  = null;

            if (currentMatchedPath == null)
            {
                userSegment = segments[0];
            }
            else
            {
                userSegment = currentMatchedPath.NextSegment;
            }

            if (userSegment == null)
            {
                return;
            }

            RouteRequestBuilder builder = null;

            if (shellSegment == userSegment || Routing.IsImplicit(shellSegment))
            {
                if (currentMatchedPath == null)
                {
                    builder = new RouteRequestBuilder(shellSegment, userSegment, node, segments);
                }
                else
                {
                    builder = new RouteRequestBuilder(currentMatchedPath);
                    builder.AddMatch(shellSegment, userSegment, node);
                }

                if (!Routing.IsImplicit(shellSegment) || shellSegment == userSegment)
                {
                    possibleRoutePaths.Add(builder);
                }
            }

            items = GetItems(node);
            if (items == null)
            {
                return;
            }

            foreach (var nextNode in items)
            {
                SearchPath(nextNode, builder, segments, possibleRoutePaths, depthToStart, myDepth, currentLocation, ignoreGlobalRoutes);
            }
        }
示例#57
0
        internal static List <RouteRequestBuilder> GenerateRoutePaths(Shell shell, Uri request, Uri originalRequest, bool enableRelativeShellRoutes)
        {
            var routeKeys = Routing.GetRouteKeys();

            for (int i = 0; i < routeKeys.Length; i++)
            {
                if (routeKeys[i] == originalRequest.OriginalString)
                {
                    var builder = new RouteRequestBuilder(routeKeys[i], routeKeys[i], null, new string[] { routeKeys[i] });
                    return(new List <RouteRequestBuilder> {
                        builder
                    });
                }
                routeKeys[i] = FormatUri(routeKeys[i]);
            }

            request         = FormatUri(request, shell);
            originalRequest = FormatUri(originalRequest, shell);

            List <RouteRequestBuilder> possibleRoutePaths = new List <RouteRequestBuilder>();

            if (!request.IsAbsoluteUri)
            {
                request = ConvertToStandardFormat(shell, request);
            }

            string localPath = request.LocalPath;

            bool relativeMatch = false;

            if (!originalRequest.IsAbsoluteUri &&
                !originalRequest.OriginalString.StartsWith("//", StringComparison.Ordinal))
            {
                relativeMatch = true;
            }

            var segments = localPath.Split(_pathSeparator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            if (!relativeMatch)
            {
                for (int i = 0; i < routeKeys.Length; i++)
                {
                    var route = routeKeys[i];
                    var uri   = ConvertToStandardFormat(shell, CreateUri(route));
                    if (uri.Equals(request))
                    {
                        throw new Exception($"Global routes currently cannot be the only page on the stack, so absolute routing to global routes is not supported. For now, just navigate to: {originalRequest.OriginalString.Replace("//", "")}");
                        //var builder = new RouteRequestBuilder(route, route, null, segments);
                        //return new List<RouteRequestBuilder> { builder };
                    }
                }
            }

            var depthStart = 0;

            if (segments[0] == shell?.Route)
            {
                segments   = segments.Skip(1).ToArray();
                depthStart = 1;
            }
            else
            {
                depthStart = 0;
            }

            if (relativeMatch && shell?.CurrentItem != null)
            {
                // retrieve current location
                var currentLocation = NodeLocation.Create(shell);

                while (currentLocation.Shell != null)
                {
                    var pureRoutesMatch       = new List <RouteRequestBuilder>();
                    var pureGlobalRoutesMatch = new List <RouteRequestBuilder>();

                    //currently relative routes to shell routes isn't supported as we aren't creating navigation stacks
                    if (enableRelativeShellRoutes)
                    {
                        SearchPath(currentLocation.LowestChild, null, segments, pureRoutesMatch, 0);
                        ExpandOutGlobalRoutes(pureRoutesMatch, routeKeys);
                        pureRoutesMatch = GetBestMatches(pureRoutesMatch);
                        if (pureRoutesMatch.Count > 0)
                        {
                            return(pureRoutesMatch);
                        }
                    }


                    SearchPath(currentLocation.LowestChild, null, segments, pureGlobalRoutesMatch, 0, ignoreGlobalRoutes: false);
                    ExpandOutGlobalRoutes(pureGlobalRoutesMatch, routeKeys);
                    pureGlobalRoutesMatch = GetBestMatches(pureGlobalRoutesMatch);
                    if (pureGlobalRoutesMatch.Count > 0)
                    {
                        // currently relative routes to shell routes isn't supported as we aren't creating navigation stacks
                        // So right now we will just throw an exception so that once this is implemented
                        // GotoAsync doesn't start acting inconsistently and all of a suddent starts creating routes
                        if (!enableRelativeShellRoutes && pureGlobalRoutesMatch[0].SegmentsMatched.Count > 0)
                        {
                            throw new Exception($"Relative routing to shell elements is currently not supported. Try prefixing your uri with ///: ///{originalRequest}");
                        }

                        return(pureGlobalRoutesMatch);
                    }

                    currentLocation.Pop();
                }

                string searchPath = String.Join(_pathSeparator, segments);

                if (routeKeys.Contains(searchPath))
                {
                    return(new List <RouteRequestBuilder> {
                        new RouteRequestBuilder(searchPath, searchPath, null, segments)
                    });
                }

                RouteRequestBuilder builder = null;
                foreach (var segment in segments)
                {
                    if (routeKeys.Contains(segment))
                    {
                        if (builder == null)
                        {
                            builder = new RouteRequestBuilder(segment, segment, null, segments);
                        }
                        else
                        {
                            builder.AddGlobalRoute(segment, segment);
                        }
                    }
                }

                if (builder != null && builder.IsFullMatch)
                {
                    return new List <RouteRequestBuilder> {
                               builder
                    }
                }
                ;
            }
            else
            {
                possibleRoutePaths.Clear();
                SearchPath(shell, null, segments, possibleRoutePaths, depthStart);

                var bestMatches = GetBestMatches(possibleRoutePaths);
                if (bestMatches.Count > 0)
                {
                    return(bestMatches);
                }

                bestMatches.Clear();
                ExpandOutGlobalRoutes(possibleRoutePaths, routeKeys);
            }

            possibleRoutePaths = GetBestMatches(possibleRoutePaths);
            return(possibleRoutePaths);
        }
示例#58
0
 public NumericFor(NodeLocation location) : base(location)
 {
 }
示例#59
0
 public override List<NodeSize> ListSizes(NodeLocation location)
 {
     return API.ListSizes (location);
 }
示例#60
0
        static List <RouteRequestBuilder> ProcessRelativeRoute(
            Shell shell,
            string[] routeKeys,
            string[] segments,
            bool enableRelativeShellRoutes,
            Uri originalRequest)
        {
            // retrieve current location
            var currentLocation = NodeLocation.Create(shell);

            while (currentLocation.Shell != null)
            {
                var pureRoutesMatch       = new List <RouteRequestBuilder>();
                var pureGlobalRoutesMatch = new List <RouteRequestBuilder>();

                //currently relative routes to shell routes isn't supported as we aren't creating navigation stacks
                if (enableRelativeShellRoutes)
                {
                    SearchPath(currentLocation.LowestChild, null, segments, pureRoutesMatch, 0);
                    ExpandOutGlobalRoutes(pureRoutesMatch, routeKeys);
                    pureRoutesMatch = GetBestMatches(pureRoutesMatch);
                    if (pureRoutesMatch.Count > 0)
                    {
                        return(pureRoutesMatch);
                    }
                }

                SearchPath(currentLocation.LowestChild, null, segments, pureGlobalRoutesMatch, 0, ignoreGlobalRoutes: false);
                ExpandOutGlobalRoutes(pureGlobalRoutesMatch, routeKeys);

                if (currentLocation.Content != null && pureGlobalRoutesMatch.Count == 0)
                {
                    var matches = SearchForGlobalRoutes(segments, shell.CurrentState.FullLocation, currentLocation, routeKeys);
                    pureGlobalRoutesMatch.AddRange(matches);
                }

                pureGlobalRoutesMatch = GetBestMatches(pureGlobalRoutesMatch);
                if (pureGlobalRoutesMatch.Count > 0)
                {
                    // currently relative routes to shell routes isn't supported as we aren't creating navigation stacks
                    // So right now we will just throw an exception so that once this is implemented
                    // GotoAsync doesn't start acting inconsistently and all of a sudden starts creating routes

                    int shellElementsMatched =
                        pureGlobalRoutesMatch[0].SegmentsMatched.Count -
                        pureGlobalRoutesMatch[0].GlobalRouteMatches.Count;

                    if (!enableRelativeShellRoutes && shellElementsMatched > 0)
                    {
                        throw new Exception($"Relative routing to shell elements is currently not supported. Try prefixing your uri with ///: ///{originalRequest}");
                    }

                    return(pureGlobalRoutesMatch);
                }

                currentLocation.Pop();
            }

            string searchPath = String.Join(_pathSeparator, segments);

            if (routeKeys.Contains(searchPath))
            {
                return(new List <RouteRequestBuilder> {
                    new RouteRequestBuilder(searchPath, searchPath, null, segments)
                });
            }

            RouteRequestBuilder builder = null;

            foreach (var segment in segments)
            {
                if (routeKeys.Contains(segment))
                {
                    if (builder == null)
                    {
                        builder = new RouteRequestBuilder(segment, segment, null, segments);
                    }
                    else
                    {
                        builder.AddGlobalRoute(segment, segment);
                    }
                }
            }

            if (builder != null && builder.IsFullMatch)
            {
                return new List <RouteRequestBuilder> {
                           builder
                }
            }
            ;

            return(new List <RouteRequestBuilder>());
        }