/// <summary>Adds an additional NIC to a server.</summary>
        /// <param name="serverId">The server id.</param>
        /// <param name="vlanId">The VLAN id</param>
        /// <param name="privateIpv4">The Private IP v4 address</param>
        /// <param name="networkAdapter">The optional network adapter type (E1000 or VMXNET3)</param>
        /// <returns>The <see cref="Task"/>.</returns>
        public async Task <ResponseType> AddNic(Guid serverId, Guid?vlanId, string privateIpv4, string networkAdapter = null)
        {
            if (vlanId == null && string.IsNullOrEmpty(privateIpv4))
            {
                throw new ArgumentNullException("vlanId");
            }

            var nic = new VlanIdOrPrivateIpType
            {
                networkAdapter = networkAdapter
            };

            // Private IP takes priority over vlanId
            // As Setting VlanId will make the api allocate the ip automatically ignoring the privateIp
            if (!string.IsNullOrEmpty(privateIpv4))
            {
                nic.privateIpv4 = privateIpv4;
            }
            else
            {
                nic.vlanId = vlanId != null?vlanId.ToString() : null;
            }

            AddNicType addNicType = new AddNicType
            {
                serverId = serverId.ToString(),
                nic      = nic
            };

            return(await _apiClient.PostAsync <AddNicType, ResponseType>(ApiUris.AddNic(_apiClient.OrganizationId), addNicType));
        }
예제 #2
0
        /// <summary>
        ///     The process record method.
        /// </summary>
        protected override void ProcessRecord()
        {
            ResponseType response = null;

            base.ProcessRecord();
            try
            {
                var nic = new AddNicType
                {
                    serverId = Server != null ? Server.id : ServerId,
                    nic      = new NewNicType
                    {
                        privateIpv4 = PrimaryPrivateIp,
                        vlanId      = Vlan != null? Vlan.id : null
                    }
                };

                response = Connection.ApiClient.AddNicToServer(nic).Result;
            }
            catch (AggregateException ae)
            {
                ae.Handle(
                    e =>
                {
                    if (e is ComputeApiException)
                    {
                        WriteError(new ErrorRecord(e, "-2", ErrorCategory.InvalidOperation, Connection));
                    }
                    else
                    {
                        // if (e is HttpRequestException)
                        ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection));
                    }

                    return(true);
                });
            }

            WriteObject(response);
        }
예제 #3
0
 /// <summary>Adds an additional NIC to a server.</summary>
 /// <param name="addNicType">The server id.</param>
 /// <returns>The <see cref="Task"/>.</returns>
 public async Task <ResponseType> AddNic(AddNicType addNicType)
 {
     return(await _apiClient.PostAsync <AddNicType, ResponseType>(ApiUris.AddNic(_apiClient.OrganizationId), addNicType));
 }
예제 #4
0
 /// <summary>
 ///     An IComputeApiClient extension method that adds a NIC to server to 'addNic'.
 /// </summary>
 /// <remarks>	Anthony, 4/24/2015. </remarks>
 /// <param name="client">	The compute client. </param>
 /// <param name="addNic">	The add NIC. </param>
 /// <returns>	A standard response. </returns>
 public static async Task <ResponseType> AddNicToServer(this IComputeApiClient client, AddNicType addNic)
 {
     return
         (await client.WebApi.PostAsync <AddNicType, ResponseType>(ApiUris.AddNic(client.WebApi.OrganizationId), addNic));
 }