示例#1
0
        /// <summary>
        /// Returns the latest image that is part of an image family and is not deprecated.
        /// Documentation https://developers.google.com/compute/alpha/reference/images/getFromFamily
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="family">Name of the image family to search for.</param>
        /// <returns>ImageResponse</returns>
        public static Image GetFromFamily(ComputeService service, string project, string family)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (family == null)
                {
                    throw new ArgumentNullException(family);
                }

                // Make the request.
                return(service.Images.GetFromFamily(project, family).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Images.GetFromFamily failed.", ex);
            }
        }
        /// <summary>
        /// Retrieves an aggregated list of target pools.
        /// Documentation https://developers.google.com/compute/beta/reference/targetPools/aggregatedList
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>TargetPoolAggregatedListResponse</returns>
        public static TargetPoolAggregatedList AggregatedList(ComputeService service, string project, TargetPoolsAggregatedListOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }

                // Building the initial request.
                var request = service.TargetPools.AggregatedList(project);

                // Applying optional parameters to the request.
                request = (TargetPoolsResource.AggregatedListRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request TargetPools.AggregatedList failed.", ex);
            }
        }
        /// <summary>
        /// Gets the most recent health check results for each IP for the instance that is referenced by the given target pool.
        /// Documentation https://developers.google.com/compute/beta/reference/targetPools/getHealth
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="region">Name of the region scoping this request.</param>
        /// <param name="targetPool">Name of the TargetPool resource to which the queried instance belongs.</param>
        /// <param name="body">A valid Compute beta body.</param>
        /// <returns>TargetPoolInstanceHealthResponse</returns>
        public static TargetPoolInstanceHealth GetHealth(ComputeService service, string project, string region, string targetPool, InstanceReference body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (region == null)
                {
                    throw new ArgumentNullException(region);
                }
                if (targetPool == null)
                {
                    throw new ArgumentNullException(targetPool);
                }

                // Make the request.
                return(service.TargetPools.GetHealth(body, project, region, targetPool).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request TargetPools.GetHealth failed.", ex);
            }
        }
        /// <summary>
        /// Returns the specified accelerator type. Get a list of available accelerator types by making a list() request.
        /// Documentation https://developers.google.com/compute/beta/reference/acceleratorTypes/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="zone">The name of the zone for this request.</param>
        /// <param name="acceleratorType">Name of the accelerator type to return.</param>
        /// <returns>AcceleratorTypeResponse</returns>
        public static AcceleratorType Get(ComputeService service, string project, string zone, string acceleratorType)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (zone == null)
                {
                    throw new ArgumentNullException(zone);
                }
                if (acceleratorType == null)
                {
                    throw new ArgumentNullException(acceleratorType);
                }

                // Make the request.
                return(service.AcceleratorTypes.Get(project, zone, acceleratorType).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request AcceleratorTypes.Get failed.", ex);
            }
        }
        /// <summary>
        /// Sets the access control policy on the specified resource. Replaces any existing policy.
        /// Documentation https://developers.google.com/compute/alpha/reference/licenseCodes/setIamPolicy
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="resource">Name of the resource for this request.</param>
        /// <param name="body">A valid Compute alpha body.</param>
        /// <returns>PolicyResponse</returns>
        public static Policy SetIamPolicy(ComputeService service, string project, string resource, Policy body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (resource == null)
                {
                    throw new ArgumentNullException(resource);
                }

                // Make the request.
                return(service.LicenseCodes.SetIamPolicy(body, project, resource).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request LicenseCodes.SetIamPolicy failed.", ex);
            }
        }
示例#6
0
        private async Task <OperationResult> StartGoogleCloudInstance(GoogleCloudModel model)
        {
            try
            {
                var computeService = new ComputeService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = await GetCredential(model),
                    ApplicationName       = "Blockbase",
                });

                var name = SdkContext.RandomResourceName("blockbase-", 2);

                var zone = "us-central1-a";

                var requestBody = JsonConvert.DeserializeObject <Google.Apis.Compute.v1.Data.Instance>(Resources.GOOGLE_REQUEST_BODY);
                requestBody.Name = name;

                var request = computeService.Instances.Insert(requestBody, model.ProjectId, zone);

                var response = request.Execute();
                return(new OperationResult()
                {
                    IsSuccessful = true
                });
            }
            catch (Exception e)
            {
                return(new OperationResult()
                {
                    IsSuccessful = false,
                    ErrorMessage = $"Instance failed ( Error: {e.Message} )"
                });
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            const string region = "RegionOne";

            // Configure OpenStack.NET
            OpenStackNet.Configure(options => options.DefaultTimeout = TimeSpan.FromSeconds(5));

            // Authenticate
            var identityUrl = new Uri("http://example.com");
            var user        = new CloudIdentityWithProject();
            var identity    = new OpenStackIdentityProvider(identityUrl, user);

            identity.Authenticate();

            // Use legacy and new providers
            var legacyNetworking = new CloudNetworksProvider(null, identity);

            legacyNetworking.ListNetworks();
            var networks = new NetworkingService(identity, region);

            networks.ListNetworks();

            var legacyCompute = new CloudServersProvider(null, identity);

            legacyCompute.ListServers();
            var compute = new ComputeService(identity, region);

            compute.ListServers();
        }
示例#8
0
        /// <summary>
        /// Returns all of the details about the specified managed instance group. Get a list of available managed instance groups by making a list() request.
        /// Documentation https://developers.google.com/compute/v1/reference/instanceGroupManagers/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="zone">The name of the zone where the managed instance group is located.</param>
        /// <param name="instanceGroupManager">The name of the managed instance group.</param>
        /// <returns>InstanceGroupManagerResponse</returns>
        public static InstanceGroupManager Get(ComputeService service, string project, string zone, string instanceGroupManager)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (zone == null)
                {
                    throw new ArgumentNullException(zone);
                }
                if (instanceGroupManager == null)
                {
                    throw new ArgumentNullException(instanceGroupManager);
                }

                // Make the request.
                return(service.InstanceGroupManagers.Get(project, zone, instanceGroupManager).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request InstanceGroupManagers.Get failed.", ex);
            }
        }
        /// <summary>
        /// Returns the specified autoscaler.
        /// Documentation https://developers.google.com/compute/beta/reference/regionAutoscalers/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="region">Name of the region scoping this request.</param>
        /// <param name="autoscaler">Name of the autoscaler to return.</param>
        /// <returns>AutoscalerResponse</returns>
        public static Autoscaler Get(ComputeService service, string project, string region, string autoscaler)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (region == null)
                {
                    throw new ArgumentNullException(region);
                }
                if (autoscaler == null)
                {
                    throw new ArgumentNullException(autoscaler);
                }

                // Make the request.
                return(service.RegionAutoscalers.Get(project, region, autoscaler).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request RegionAutoscalers.Get failed.", ex);
            }
        }
        /// <summary>
        /// Returns the specified BackendService resource. Get a list of available backend services by making a list() request.
        /// Documentation https://developers.google.com/compute/alpha/reference/backendServices/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="backendService">Name of the BackendService resource to return.</param>
        /// <returns>BackendServiceResponse</returns>
        public static BackendService Get(ComputeService service, string project, string backendService)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (backendService == null)
                {
                    throw new ArgumentNullException(backendService);
                }

                // Make the request.
                return(service.BackendServices.Get(project, backendService).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request BackendServices.Get failed.", ex);
            }
        }
        /// <summary>
        /// Returns the specified firewall.
        /// Documentation https://developers.google.com/compute/v1/reference/firewalls/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="firewall">Name of the firewall rule to return.</param>
        /// <returns>FirewallResponse</returns>
        public static Firewall Get(ComputeService service, string project, string firewall)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (firewall == null)
                {
                    throw new ArgumentNullException(firewall);
                }

                // Make the request.
                return(service.Firewalls.Get(project, firewall).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Firewalls.Get failed.", ex);
            }
        }
        /// <summary>
        /// Switches the network mode from auto subnet mode to custom subnet mode.
        /// Documentation https://developers.google.com/compute/v1/reference/networks/switchToCustomMode
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="network">Name of the network to be updated.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>OperationResponse</returns>
        public static Operation SwitchToCustomMode(ComputeService service, string project, string network, NetworksSwitchToCustomModeOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (network == null)
                {
                    throw new ArgumentNullException(network);
                }

                // Building the initial request.
                var request = service.Networks.SwitchToCustomMode(project, network);

                // Applying optional parameters to the request.
                request = (NetworksResource.SwitchToCustomModeRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Networks.SwitchToCustomMode failed.", ex);
            }
        }
        /// <summary>
        /// Returns the specified network. Get a list of available networks by making a list() request.
        /// Documentation https://developers.google.com/compute/v1/reference/networks/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="network">Name of the network to return.</param>
        /// <returns>NetworkResponse</returns>
        public static Network Get(ComputeService service, string project, string network)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (network == null)
                {
                    throw new ArgumentNullException(network);
                }

                // Make the request.
                return(service.Networks.Get(project, network).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Networks.Get failed.", ex);
            }
        }
        /// <summary>
        /// Creates a network in the specified project using the data included in the request.
        /// Documentation https://developers.google.com/compute/v1/reference/networks/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="body">A valid Compute v1 body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Insert(ComputeService service, string project, Network body, NetworksInsertOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }

                // Building the initial request.
                var request = service.Networks.Insert(body, project);

                // Applying optional parameters to the request.
                request = (NetworksResource.InsertRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Networks.Insert failed.", ex);
            }
        }
示例#15
0
        /// <summary>
        /// Deletes the specified TargetTcpProxy resource.
        /// Documentation https://developers.google.com/compute/v1/reference/targetTcpProxies/delete
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="targetTcpProxy">Name of the TargetTcpProxy resource to delete.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Delete(ComputeService service, string project, string targetTcpProxy, TargetTcpProxiesDeleteOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (targetTcpProxy == null)
                {
                    throw new ArgumentNullException(targetTcpProxy);
                }

                // Building the initial request.
                var request = service.TargetTcpProxies.Delete(project, targetTcpProxy);

                // Applying optional parameters to the request.
                request = (TargetTcpProxiesResource.DeleteRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request TargetTcpProxies.Delete failed.", ex);
            }
        }
        /// <summary>
        /// Returns the specified commitment resource. Get a list of available commitments by making a list() request.
        /// Documentation https://developers.google.com/compute/v1/reference/regionCommitments/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="region">Name of the region for this request.</param>
        /// <param name="commitment">Name of the commitment to return.</param>
        /// <returns>CommitmentResponse</returns>
        public static Commitment Get(ComputeService service, string project, string region, string commitment)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (region == null)
                {
                    throw new ArgumentNullException(region);
                }
                if (commitment == null)
                {
                    throw new ArgumentNullException(commitment);
                }

                // Make the request.
                return(service.RegionCommitments.Get(project, region, commitment).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request RegionCommitments.Get failed.", ex);
            }
        }
示例#17
0
        /// <summary>
        /// Returns the specified TargetTcpProxy resource. Get a list of available target TCP proxies by making a list() request.
        /// Documentation https://developers.google.com/compute/v1/reference/targetTcpProxies/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="targetTcpProxy">Name of the TargetTcpProxy resource to return.</param>
        /// <returns>TargetTcpProxyResponse</returns>
        public static TargetTcpProxy Get(ComputeService service, string project, string targetTcpProxy)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (targetTcpProxy == null)
                {
                    throw new ArgumentNullException(targetTcpProxy);
                }

                // Make the request.
                return(service.TargetTcpProxies.Get(project, targetTcpProxy).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request TargetTcpProxies.Get failed.", ex);
            }
        }
示例#18
0
        private async Task <string> DeleteDisk()
        {
            ServiceAccountCredential credential = new ServiceAccountCredential(
                new ServiceAccountCredential.Initializer(ServiceAccountEmail)
            {
                Scopes = new[] { ComputeService.Scope.Compute, ComputeService.Scope.CloudPlatform }
            }.FromPrivateKey(PrivateKey));

            var cs = new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = "GCloud Delete Disk"
            };

            var t = new ComputeService(cs);

            var request = t.Disks.Delete(Project, Region + "-" + Zone, DiskName);

            var response = request.Execute();

            if (response.HttpErrorStatusCode != null)
            {
                var errorStr = new StringBuilder();
                foreach (var error in response.Error.Errors)
                {
                    errorStr.AppendLine(error.Code + " - " + error.Message);
                }
                return(errorStr.ToString());
            }
            else
            {
                return("Success");
            }
        }
        /// <summary>
        /// Retrieves the specified Operations resource. Get a list of operations by making a list() request.
        /// Documentation https://developers.google.com/compute/beta/reference/globalOperations/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="operation">Name of the Operations resource to return.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Get(ComputeService service, string project, string operation)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (operation == null)
                {
                    throw new ArgumentNullException(operation);
                }

                // Make the request.
                return(service.GlobalOperations.Get(project, operation).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request GlobalOperations.Get failed.", ex);
            }
        }
        /// <summary>
        /// Gets the most recent health check results for this BackendService.
        /// Documentation https://developers.google.com/compute/alpha/reference/backendServices/getHealth
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">NA</param>
        /// <param name="backendService">Name of the BackendService resource to which the queried instance belongs.</param>
        /// <param name="body">A valid Compute alpha body.</param>
        /// <returns>BackendServiceGroupHealthResponse</returns>
        public static BackendServiceGroupHealth GetHealth(ComputeService service, string project, string backendService, ResourceGroupReference body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (backendService == null)
                {
                    throw new ArgumentNullException(backendService);
                }

                // Make the request.
                return(service.BackendServices.GetHealth(body, project, backendService).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request BackendServices.GetHealth failed.", ex);
            }
        }
        public ComputeServiceTests(ITestOutputHelper testLog)
        {
            var testOutput = new XunitTraceListener(testLog);
            Trace.Listeners.Add(testOutput);
            OpenStackNet.Tracing.Http.Listeners.Add(testOutput);

            var authenticationProvider = TestIdentityProvider.GetOperatorIdentity();
            _compute = new ComputeService(authenticationProvider, "RegionOne");
        }
        public ComputeTestDataManager(ComputeService compute)
        {
            _compute = compute;
            _testData = new HashSet<object>();

            var identityProvider = TestIdentityProvider.GetIdentityProvider();
            var blockStorage = new CloudBlockStorageProvider(null, "RegionOne", identityProvider, null);
            BlockStorage = new BlockStorageTestDataManager(blockStorage);
        }
        public SecurityGroupTests(ITestOutputHelper testLog)
        {
            var testOutput = new XunitTraceListener(testLog);
            Trace.Listeners.Add(testOutput);
            OpenStackNet.Tracing.Http.Listeners.Add(testOutput);

            var authenticationProvider = TestIdentityProvider.GetIdentityProvider();
            _compute = new ComputeService(authenticationProvider, "RegionOne");

            _testData = new ComputeTestDataManager(_compute);
        }
示例#24
0
    public async Task Run(string identityEndpoint, string username, string password, string project, string region)
    {
        // Configure authentication
        var user = new CloudIdentityWithProject
        {
            Username = username,
            Password = password,
            ProjectName = project
        };
        var identity = new OpenStackIdentityProvider(new Uri(identityEndpoint), user);
        var compute = new ComputeService(identity, region);

        Console.WriteLine("Looking up the tiny flavor...");
        var flavors = await compute.ListFlavorsAsync();
        var tinyFlavor = flavors.FirstOrDefault(x => x.Name.Contains("tiny"));
        if(tinyFlavor == null) throw new Exception("Unable to find a flavor with the 'tiny' in the name!");

        Console.WriteLine("Looking up the cirros image...");
        var images = await compute.ListImagesAsync(new ImageListOptions {Name = "cirros"});
        var cirrosImage = images.FirstOrDefault();
        if(cirrosImage == null) throw new Exception("Unable to find an image named 'cirros'");

        Console.WriteLine("Creating Sample server... ");
        var serverDefinition = new ServerCreateDefinition("sample", cirrosImage.Id, tinyFlavor.Id);
        var server = await compute.CreateServerAsync(serverDefinition);

        Console.WriteLine("Waiting for the sample server to come online...");
        await server.WaitUntilActiveAsync();

        Console.WriteLine("Taking a snaphot of the sample server...");
        var snapshot = await server.SnapshotAsync(new SnapshotServerRequest("sample-snapshot"));
        await snapshot.WaitUntilActiveAsync();

        Console.WriteLine();
        Console.WriteLine("Sample Server Information:");
        Console.WriteLine();
        Console.WriteLine($"Server Id: {server.Id}");
        Console.WriteLine($"Server Name: {server.Name}");
        Console.WriteLine($"Server Status: {server.Status}");
        Console.WriteLine($"Server Address: {server.IPv4Address}");
        Console.WriteLine();
        Console.WriteLine("Sample Snapshot Information:");
        Console.WriteLine();
        Console.WriteLine($"Image Id: {snapshot.Id}");
        Console.WriteLine($"Image Name: {snapshot.Name}");
        Console.WriteLine($"Image Status: {snapshot.Status}");
        Console.WriteLine($"Image Type: {snapshot.Type}");
        Console.WriteLine();

        Console.WriteLine("Deleting Sample Server...");
        await snapshot.DeleteAsync();
        await server.DeleteAsync();
    }
        public Layer3ExtensionTests(ITestOutputHelper testLog)
        {
            var testOutput = new XunitTraceListener(testLog);
            Trace.Listeners.Add(testOutput);
            OpenStackNet.Tracing.Http.Listeners.Add(testOutput);

            // The operator identity is necessary to create external networks
            var authenticationProvider = TestIdentityProvider.GetOperatorIdentity();
            _networkingService = new NetworkingService(authenticationProvider, "RegionOne");

            _testData = new NetworkingTestDataManager(_networkingService);
            var compute = new ComputeService(authenticationProvider, "RegionOne");
            _computeTestData = new ComputeTestDataManager(compute);
        }
示例#26
0
        static void Main(string[] args)
        {
            const string region = "RegionOne";

            // Configure OpenStack.NET
            OpenStackNet.Configure(options => options.DefaultTimeout=TimeSpan.FromSeconds(5));

            // Authenticate
            var identityUrl = new Uri("http://example.com");
            var user = new CloudIdentityWithProject();
            var identity = new OpenStackIdentityProvider(identityUrl, user);
            identity.Authenticate();

            // Use legacy and new providers
            var legacyNetworking = new CloudNetworksProvider(null, identity);
            legacyNetworking.ListNetworks();
            var networks = new NetworkingService(identity, region);
            networks.ListNetworks();

            var legacyCompute = new CloudServersProvider(null, identity);
            legacyCompute.ListServers();
            var compute = new ComputeService(identity, region);
            compute.ListServers();
        }
 public ComputeServiceTests()
 {
     _compute = new ComputeService(Stubs.AuthenticationProvider, "region");
 }
示例#28
0
        public void DisassociateFloatingIPFromServer()
        {
            var compute = new ComputeService(Stubs.AuthenticationProvider, "region");

            using (var httpTest = new HttpTest())
            {
                Identifier serverId = Guid.NewGuid();
                const string ip = "10.0.0.1";
                httpTest.RespondWithJson(new Server
                {
                    Id = serverId,
                    Addresses =
                    {
                        ["network1"] = new List<ServerAddress>
                        {
                            new ServerAddress {IP = ip, Type = AddressType.Floating}
                        }
                    }
                });
                httpTest.RespondWith((int)HttpStatusCode.OK, "ip disassociated!");

                var server = compute.GetServer(serverId);
                server.DisassociateFloatingIP(ip);

                Assert.Null(server.Addresses["network1"].FirstOrDefault(a => a.IP == ip && a.Type == AddressType.Floating));
            }
        }