Example #1
0
        private void Configure()
        {
            configuration = new Configuration
            {
                Username = "******",
                Password = "******",
            };

            dcApi     = new DataCenterApi(configuration);
            serverApi = new ServerApi(configuration);
            nicApi    = new NetworkInterfacesApi(configuration);
            lbApi     = new LoadBalancerApi(configuration);

            //Create a datacenter.
            if (datacenter == null)
            {
                datacenter = new Datacenter
                {
                    Properties = new DatacenterProperties
                    {
                        Name        = ".Net V2 - Test " + DateTime.Now.ToShortTimeString(),
                        Description = "Unit test for .Net SDK PB REST V2",
                        Location    = "us/lasdev"
                    }
                };

                datacenter = dcApi.Create(datacenter);
            }

            if (server == null)
            {
                server = new Server
                {
                    Properties = new ServerProperties
                    {
                        Name  = ".Net V2 - Test " + DateTime.Now.ToShortTimeString(),
                        Cores = 1,
                        Ram   = 256
                    }
                };

                server = serverApi.Create(datacenter.Id, server);
                DoWait(server.Request);
            }

            if (lb == null)
            {
                lb = new Loadbalancer
                {
                    Properties = new LoadbalancerProperties {
                        Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString()
                    }
                };

                lb = lbApi.Create(datacenter.Id, lb);

                DoWait(lb.Request);
            }
        }
        public void LoadbalancerCreate()
        {
            Configure();
            lb = new Loadbalancer
            {
                Properties = new LoadbalancerProperties { Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString() }
            };

            lb = lbApi.Create(datacenter.Id, lb);

            DoWait(lb.Request);

            Assert.IsNotNull(lb);
        }
        public void LoadbalancerCreate()
        {
            Configure();
            lb = new Loadbalancer
            {
                Properties = new LoadbalancerProperties {
                    Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString()
                }
            };

            lb = lbApi.Create(datacenter.Id, lb);

            DoWait(lb.Request);

            Assert.IsNotNull(lb);
        }
        /// <summary>
        /// Create a Lan Creates a Loadbalancer within the datacenter
        /// </summary>
        /// <param name="datacenterId"></param>
        /// <param name="loadbalancer">Loadbalancer to be created</param>
        /// <param name="parameter">Controls whether response is pretty-printed (with indentation and new lines)</param>
        /// <param name="depth">Controls the details depth of response objects. \nEg. GET /datacenters/[ID]\n	- depth=0: only direct properties are included. Children (servers etc.) are not included\n	- depth=1: direct properties and children references are included\n	- depth=2: direct properties and children properties are included\n	- depth=3: direct properties and children properties and children&#39;s children are included\n	- depth=... and so on</param>
        /// <returns>Task of ApiResponse (Loadbalancer)</returns>
        public async System.Threading.Tasks.Task<ApiResponse<Loadbalancer>> CreateAsyncWithHttpInfo(string datacenterId, Loadbalancer loadbalancer, bool? parameter = null, int? depth = null)
        {
            // verify the required parameter 'datacenterId' is set
            if (datacenterId == null) throw new ApiException(400, "Missing required parameter 'datacenterId' when calling Create");
            // verify the required parameter 'loadbalancer' is set
            if (loadbalancer == null) throw new ApiException(400, "Missing required parameter 'loadbalancer' when calling Create");


            var path_ = "/datacenters/{datacenterId}/loadbalancers";

            var pathParams = new Dictionary<String, String>();
            var queryParams = new Dictionary<String, String>();
            var headerParams = new Dictionary<String, String>();
            var formParams = new Dictionary<String, String>();
            var fileParams = new Dictionary<String, FileParameter>();
            Object postBody = null;

            // to determine the Content-Type header
            String[] httpContentTypes = new String[] {
                "application/json", "application/vnd.profitbricks.resource+json"
            };
            String httpContentType = Configuration.ApiClient.SelectHeaderContentType(httpContentTypes);

            // to determine the Accept header
            String[] httpHeaderAccepts = new String[] {
                "application/vnd.profitbricks.resource+json"
            };
            String httpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(httpHeaderAccepts);
            if (httpHeaderAccept != null)
                headerParams.Add("Accept", httpHeaderAccept);

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            pathParams.Add("format", "json");
            if (datacenterId != null) pathParams.Add("datacenterId", Configuration.ApiClient.ParameterToString(datacenterId)); // path parameter

            if (parameter != null) queryParams.Add("parameter", Configuration.ApiClient.ParameterToString(parameter)); // query parameter
            if (depth != null) queryParams.Add("depth", Configuration.ApiClient.ParameterToString(depth)); // query parameter



            postBody = Configuration.ApiClient.Serialize(loadbalancer); // http body (model) parameter



            // authentication (basicAuth) required

            // http basic authentication required
            if (!String.IsNullOrEmpty(Configuration.Username) || !String.IsNullOrEmpty(Configuration.Password))
            {
                headerParams["Authorization"] = "Basic " + ApiClient.Base64Encode(Configuration.Username + ":" + Configuration.Password);
            }


            // make the HTTP request
            IRestResponse response = (IRestResponse)await Configuration.ApiClient.CallApiAsync(path_,
                Method.POST, queryParams, postBody, headerParams, formParams, fileParams,
                pathParams, httpContentType);

            int statusCode = (int)response.StatusCode;

            if (statusCode >= 400)
                throw new ApiException(statusCode, "Error calling Create: " + response.Content, response.Content);
            else if (statusCode == 0)
                throw new ApiException(statusCode, "Error calling Create: " + response.ErrorMessage, response.ErrorMessage);

            return new ApiResponse<Loadbalancer>(statusCode,
                response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                (Loadbalancer)Configuration.ApiClient.Deserialize(response, typeof(Loadbalancer)));

        }
        /// <summary>
        /// Create a Lan Creates a Loadbalancer within the datacenter
        /// </summary>
        /// <param name="datacenterId"></param>
        /// <param name="loadbalancer">Loadbalancer to be created</param>
        /// <param name="parameter">Controls whether response is pretty-printed (with indentation and new lines)</param>
        /// <param name="depth">Controls the details depth of response objects. \nEg. GET /datacenters/[ID]\n	- depth=0: only direct properties are included. Children (servers etc.) are not included\n	- depth=1: direct properties and children references are included\n	- depth=2: direct properties and children properties are included\n	- depth=3: direct properties and children properties and children&#39;s children are included\n	- depth=... and so on</param>
        /// <returns>Task of Loadbalancer</returns>
        public async System.Threading.Tasks.Task<Loadbalancer> CreateAsync(string datacenterId, Loadbalancer loadbalancer, bool? parameter = null, int? depth = null)
        {
            ApiResponse<Loadbalancer> response = await CreateAsyncWithHttpInfo(datacenterId, loadbalancer, parameter, depth);
            return response.Data;

        }
 /// <summary>
 /// Create a Lan Creates a Loadbalancer within the datacenter
 /// </summary>
 /// <param name="datacenterId"></param> 
 /// <param name="loadbalancer">Loadbalancer to be created</param> 
 /// <param name="parameter">Controls whether response is pretty-printed (with indentation and new lines)</param> 
 /// <param name="depth">Controls the details depth of response objects. \nEg. GET /datacenters/[ID]\n	- depth=0: only direct properties are included. Children (servers etc.) are not included\n	- depth=1: direct properties and children references are included\n	- depth=2: direct properties and children properties are included\n	- depth=3: direct properties and children properties and children&#39;s children are included\n	- depth=... and so on</param> 
 /// <returns>Loadbalancer</returns>
 public Loadbalancer Create(string datacenterId, Loadbalancer loadbalancer, bool? parameter = null, int? depth = null)
 {
     ApiResponse<Loadbalancer> response = CreateWithHttpInfo(datacenterId, loadbalancer, parameter, depth);
     response.Data.Request = response.Headers["Location"];
     return response.Data;
 }
 /// <summary>
 /// Modify a Loadbalancer You can use update attributes of a resource
 /// </summary>
 /// <param name="datacenterId"></param> 
 /// <param name="loadbalancerId"></param> 
 /// <param name="loadbalancer">Modified Loadbalancer</param> 
 /// <param name="body"></param> 
 /// <param name="parameter">Controls whether response is pretty-printed (with indentation and new lines)</param> 
 /// <param name="depth">Controls the details depth of response objects. \nEg. GET /datacenters/[ID]\n	- depth=0: only direct properties are included. Children (servers etc.) are not included\n	- depth=1: direct properties and children references are included\n	- depth=2: direct properties and children properties are included\n	- depth=3: direct properties and children properties and children&#39;s children are included\n	- depth=... and so on</param> 
 /// <returns>Loadbalancer</returns>
 public Loadbalancer Update(string datacenterId, string loadbalancerId, Loadbalancer loadbalancer, Body1 body = null, bool? parameter = null, int? depth = null)
 {
     ApiResponse<Loadbalancer> response = UpdateWithHttpInfo(datacenterId, loadbalancerId, loadbalancer, body, parameter, depth);
     return response.Data;
 }
        private void Configure()
        {
            configuration = new Configuration
            {
                Username = "******",
                Password = "******",

            };

            dcApi = new DataCenterApi(configuration);
            serverApi = new ServerApi(configuration);
            nicApi = new NetworkInterfacesApi(configuration);
            lbApi = new LoadBalancerApi(configuration);

            //Create a datacenter.
            if (datacenter == null)
            {
                datacenter = new Datacenter
                {
                    Properties = new DatacenterProperties
                    {
                        Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString(),
                        Description = "Unit test for .Net SDK PB REST V2",
                        Location = "us/lasdev"
                    }
                };

                datacenter = dcApi.Create(datacenter);
            }

            if(server == null)
            {
                server = new Server
                {
                    Properties = new ServerProperties
                    {
                        Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString(),
                        Cores = 1,
                        Ram = 256
                    }
                };

                server = serverApi.Create(datacenter.Id, server);
                DoWait(server.Request);
            }

            if (lb == null)
            {
                lb = new Loadbalancer
                {
                    Properties = new LoadbalancerProperties { Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString() }
                };

                lb = lbApi.Create(datacenter.Id, lb);

                DoWait(lb.Request);
            }
        }