/// <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));
        }
        /// <summary>
        /// The process record method.
        /// </summary>
        protected override void ProcessRecord()
        {
            ResponseType response = null;

            base.ProcessRecord();
            try
            {
                VlanIdOrPrivateIpType primaryNic = new VlanIdOrPrivateIpType
                {
                    vlanId      = PrimaryNetwork.id,
                    privateIpv4 = PrimaryPrivateIp
                };


                var server = new DeployServerType
                {
                    name                  = Name,
                    description           = Description,
                    imageId               = ServerImage.id,
                    start                 = IsStarted,
                    administratorPassword = AdminPassword,
                    networkInfo           =
                        new DeployServerTypeNetworkInfo
                    {
                        networkDomainId =
                            NetworkDomain.id,
                        primaryNic = primaryNic
                    }
                };

                response = Connection.ApiClient.DeployServerOnNetworkDomain(server).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);
        }