public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var provisionResult = new ProvisionAddOnResult("")
            {
                IsSuccess = false
            };
            var manifest            = request.Manifest;
            var developerParameters = request.DeveloperParameters;
            var developerOptions    = GoogleCloudDeveloperOptions.Parse(developerParameters);

            try
            {
                //add instance
                var op = new InstanceOperations(manifest, developerOptions);
                op.AddInstance();
                provisionResult.IsSuccess      = true;
                provisionResult.ConnectionData = "InstanceName=" + developerOptions.InstanceName + "&Zone=" + developerOptions.Zone;
                provisionResult.EndUserMessage = "Successfully added instance " + developerOptions.InstanceName + "\n";
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
                provisionResult.IsSuccess      = false;
            }
            return(provisionResult);
        }
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string        connectionData      = request.ConnectionData;
            var           deprovisionResult   = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest            = request.Manifest;
            var           developerParameters = request.DeveloperParameters;
            var           developerOptions    = GoogleCloudDeveloperOptions.Parse(developerParameters);

            try
            {
                var conInfo = ConnectionInfo.Parse(connectionData);
                developerOptions.InstanceName = conInfo.InstanceName;
                developerOptions.Zone         = conInfo.Zone;
                var op = new InstanceOperations(manifest, developerOptions);
                op.RemoveInstance();
                deprovisionResult.IsSuccess      = true;
                deprovisionResult.EndUserMessage = "Successfully deleted instance: " + conInfo.InstanceName;
            }

            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message;
                deprovisionResult.IsSuccess      = false;
            }
            return(deprovisionResult);
        }
        // parses the developer options into a usable model - these are the ones that come from the web form.
        internal static GoogleCloudDeveloperOptions Parse(IEnumerable <AddonParameter> parameters)
        {
            var options = new GoogleCloudDeveloperOptions();

            foreach (var parameter in parameters)
            {
                MapToOption(options, parameter.Key.ToLowerInvariant(), parameter.Value);
            }
            return(options);
        }
        public override OperationResult Test(AddonTestRequest request)
        {
            var testProgress = "";
            var testResult   = new OperationResult {
                IsSuccess = false
            };

            var manifest = request.Manifest;

            var developerParameters = request.DeveloperParameters;
            var developerOptions    = GoogleCloudDeveloperOptions.Parse(developerParameters);

            testProgress += "Attempting to add an instance...";
            try
            {
                //add instance
                var op = new InstanceOperations(manifest, developerOptions);
                op.AddInstance();
                testProgress += "Successfully added instance.\n";
                //wait for instance to finishing adding
                Thread.Sleep(120000);

                try
                {
                    //remove instance
                    testProgress += "Attempting to remove an instance...";
                    op.RemoveInstance();
                    testProgress        += "Successfully removed instance.\n";
                    testResult.IsSuccess = true;
                }
                catch (AggregateException e)
                {
                    foreach (var err in e.InnerExceptions)
                    {
                        Log.Error("Error occurred during test of Google Cloud Addon", err);
                        testProgress += "EXCEPTION: " + err + "\n";
                    }
                    testProgress += "Failed to remove instance \n";
                }
            }
            catch (AggregateException e)
            {
                foreach (var err in e.InnerExceptions)
                {
                    Log.Error("Error occurred during test of Google Cloud Addon", err);
                    testProgress += "EXCEPTION: " + err + "\n";
                }
                testProgress += "Failed to add instance \n";
            }
            testResult.EndUserMessage = testProgress;
            return(testResult);
        }
 private static void MapToOption(GoogleCloudDeveloperOptions options, string key, string value)
 {
     if (key.Equals("projectid"))
     {
         options.ProjectId = value;
         return;
     }
     if (key.Equals("instancename"))
     {
         options.InstanceName = value;
         return;
     }
     if (key.Equals("zone"))
     {
         options.Zone = value;
         return;
     }
     if (key.Equals("sourceimage"))
     {
         options.SourceImage = value;
         return;
     }
     if (key.Equals("disktype"))
     {
         options.DiskType = value;
         return;
     }
     if (key.Equals("machinetype"))
     {
         options.MachineType = value;
         return;
     }
     if (key.Equals("sourceimageproject"))
     {
         options.SourceImageProject = value;
         return;
     }
     throw new ArgumentException(string.Format("Developer parameter {0} is either not readable, or not supported at this time.", key));
 }
Exemple #6
0
        internal InstanceOperations(AddonManifest manifest, GoogleCloudDeveloperOptions developerOptions)
        {
            try
            {
                var manifestprops = manifest.GetProperties().ToDictionary(x => x.Key, x => x.Value);
                ProjectId           = manifestprops["ProjectID"];
                ServiceAccountEmail = manifestprops["Email"];
                CertificateFile     = manifestprops["CertFile"];

                InstanceName       = developerOptions.InstanceName;
                SourceImage        = developerOptions.SourceImage;
                DiskType           = developerOptions.DiskType;
                Zone               = developerOptions.Zone;
                MachineType        = developerOptions.MachineType;
                SourceImageProject = developerOptions.SourceImageProject;
            }

            catch (Exception e)
            {
                throw new ArgumentException("Argument syntax is incorrect - " + e.Message);
            }
        }