private VirtualMachine DoOperation(string operation, Guid id, out Guid?jobId)
        {
            var cloud   = CloudOperations.ReadFirstCloud(this.webClientFactory);
            var stampId = cloud.StampId;

            var vm = new VirtualMachine {
                ID = id, StampId = stampId, Operation = operation
            };

            return(this.Update(vm, out jobId));
        }
예제 #2
0
        /// <summary>
        /// Reads the list of clouds and returns the first one.
        /// This is a helper function for other operations classes which sometimes need cloudId and/or stampId to do their jos.
        /// It is okay to blindly take the first cloud because WAP subscriptions are currently limited to one cloud and one stamp.
        /// i.e., there should only be one cloud available anyway.
        /// </summary>
        /// <returns></returns>
        public static Cloud ReadFirstCloud(WebClientFactory webClientFactory)
        {
            var ops       = new CloudOperations(webClientFactory);
            var cloudList = ops.Read();

            if (cloudList.Count <= 0)
            {
                throw new WAPackOperationException(Resources.NoCloudsAvailable);
            }

            return(cloudList[0]);
        }
예제 #3
0
        public override void Delete(Guid id, out Guid?jobId)
        {
            var  cloud   = CloudOperations.ReadFirstCloud(this.webClientFactory);
            Guid stampId = cloud.StampId;

            var client = this.webClientFactory.CreateClient(this.uriSuffix + String.Format("(ID=guid'{0}',StampId=guid'{1}')", id, stampId));

            WebHeaderCollection outHeaders;

            client.Delete <StaticIPAddressPool>(out outHeaders);

            jobId = TryGetJobIdFromHeaders(outHeaders);
        }
        public override VirtualMachine Create(VirtualMachine vmToCreate, out Guid?jobId)
        {
            // CloudId and StampId are required parameters. Since we are assumed to be working with a WAP subscription,
            // we can just take the first cloud and its StampId. WAP subscriptions are associated with only ONE cloud and only ONE stamp.
            var cloud = CloudOperations.ReadFirstCloud(this.webClientFactory);

            vmToCreate.CloudId = cloud.ID;
            vmToCreate.StampId = cloud.StampId;

            var client = this.webClientFactory.CreateClient(this.uriSuffix);

            WebHeaderCollection outHeaders;
            var resultList = client.Create <VirtualMachine>(vmToCreate, out outHeaders);

            if (resultList.Count <= 0)
            {
                throw new WAPackOperationException(Resources.ErrorCreatingVirtualMachine);
            }

            jobId = TryGetJobIdFromHeaders(outHeaders);

            return(resultList[0]);
        }