public VirtualMachine findVirtualMachine(string criteria)
        {
            try
            {
                var request = new RestRequest();
                request.Resource      = "/applications/" + applicationId + "/vms/" + criteria + ";deployment";
                request.Method        = Method.GET;
                request.RequestFormat = DataFormat.Json;

                var response = restClient.Execute(request);

                RestSharp.Deserializers.JsonDeserializer deserial = new RestSharp.Deserializers.JsonDeserializer();

                Console.WriteLine(response.ToString());

                RavelloVm vm = deserial.Deserialize <RavelloVm>(response);

                if (vm.id == null)
                {
                    throw new VirtualizationShimException("Machine not found with ID " + criteria);
                }

                RavelloVirtualMachine rvmTemp;
                rvmTemp = new RavelloVirtualMachine(restClient, vm.id + "", applicationId, vm.name);

                return(rvmTemp);
            }
            catch (SerializationException e)
            {
                throw new VirtualizationShimException("Cannot find Ravello machine with ID " + criteria);
            }
        }
        public void addVmToApplication(long applicationId, long baseVmId)
        {
            var request = new RestRequest();

            request.Resource      = "/applications/" + applicationId + "/vms";
            request.Method        = Method.POST;
            request.RequestFormat = DataFormat.Json;

            //Dictionary<string, long> addVm = new Dictionary<string, long>();
            RavelloVm addVm = new RavelloVm();

            addVm.baseVmId = baseVmId;

            request.AddJsonBody(addVm);

            var response = restClient.Execute(request);

            var body = request.Parameters.Where(p => p.Type == ParameterType.RequestBody).FirstOrDefault();

            if (body != null)
            {
                Console.WriteLine("add vm request body: {0}", body.Value);
            }
            Console.WriteLine("add vm to application response: " + response.Content);

            //var deserialized = JsonConvert.DeserializeObject<Application>( response.Content );
        }
示例#3
0
        private void update()
        {
            // todo
            // add a check here that determines how long it has been since the last update.
            // if below a threshold, simply return.

            var request = new RestRequest();

            request.Resource      = "/applications/" + applicationId + "/vms/" + vmId + ";deployment";
            request.Method        = Method.GET;
            request.RequestFormat = DataFormat.Json;

            var response = restClient.Execute(request);

            RestSharp.Deserializers.JsonDeserializer deserial = new RestSharp.Deserializers.JsonDeserializer();

            RavelloVm vm = deserial.Deserialize <RavelloVm>(response);

            switch (vm.state)
            {
            case "STARTING":
            case "STARTED":
                vmState = VirtualMachineState.POWERED_ON;
                break;

            case "STOPPING":
            case "STOPPED":
                vmState = VirtualMachineState.POWERED_OFF;
                break;

            default:
                vmState = VirtualMachineState.UNKNOWN;
                break;
            }
        }
        public Application createApplication(string name)
        {
            HardDrive hd = new HardDrive();

            //hd.baseDiskImageId = 78020621;
            hd.name              = "apc windows 2003 disk";
            hd.boot              = true;
            hd.controller        = "lsi53c1030";
            hd.controllerIndex   = 0;
            hd.controllerPciSlot = 1;
            hd.imageFetchMode    = "LAZY";


            Size vmMemSize = new Size();

            vmMemSize.unit  = SizeUnit.GB;
            vmMemSize.value = 2;

            RavelloVm vm = new RavelloVm();

            //vm.name = "babys first vm 001";
            vm.baseVmId = 79603141;
            //vm.description = "see name";
            //vm.loadingPercentage = 100;
            //vm.loadingStatus = LoadingStatus.DONE;
            //vm.vmOrderGroupId = 1;
            //vm.stopTimeOut = 600;
            //vm.powerOffOnStopTimeOut = true;
            //vm.memorySize = vmMemSize;
            //vm.numCpus = 1;
            //vm.hardDrives.Add( hd );

            VMOrderGroup vmOrderGroup = new VMOrderGroup();

            vmOrderGroup.id    = 1;
            vmOrderGroup.name  = "group1";
            vmOrderGroup.order = 0;
            vmOrderGroup.delay = 0;

            Design design = new Design();
            //design.vms.Add( vm );
            //design.vmOrderGroups.Add( vmOrderGroup );

            Application app = new Application();

            app.name        = "corndemo-" + name;
            app.description = "A lab deployment demo test.";
            app.design      = design;

            var request = new RestRequest();

            request.Resource      = "/applications";
            request.Method        = Method.POST;
            request.RequestFormat = DataFormat.Json;

            request.AddJsonBody(app);

            var response = restClient.Execute(request);

            Console.WriteLine("Application creation response: " + response.Content);

            var deserialized = JsonConvert.DeserializeObject <Application>(response.Content);

            Console.WriteLine("New application created. ID: " + deserialized.id);
            return(deserialized);
        }