Esempio n. 1
0
 public PackageIPAddress[] GetPackageIPAddresses(int packageId, int orgId, IPAddressPool pool, string filterColumn, string filterValue,
                                                 string sortColumn, int maximumRows, int startRowIndex)
 {
     packageAddresses = ES.Services.Servers.GetPackageIPAddresses(packageId, orgId, pool,
                                                                  filterColumn, filterValue, sortColumn, startRowIndex, maximumRows, true);
     return(packageAddresses.Items);
 }
Esempio n. 2
0
        public ActionResult UnblockIP(IPIndexViewModel iivm)
        {
            var ip = new IPAddressPool();

            ip = IPAddressPoolBLO.Current.GetById(iivm.Id);
            if (ip.StatusCode == Constants.StatusCode.IP_BLOCKED)
            {
                ip.StatusCode = Constants.StatusCode.IP_AVAILABLE;
                IPAddressPoolDAO.Current.Update(ip);
                var blockip = LogBLO.Current.GetBlockedIP(ip.IPAddress).FirstOrDefault();

                var log = new Log();
                log.TypeOfLog            = Constants.TypeOfLog.LOG_UNBLOCK_IP;
                log.Object               = Constants.Object.OBJECT_IP;
                log.ChangedValueOfObject = ip.IPAddress;
                log.ObjectStatus         = Constants.StatusCode.IP_AVAILABLE;
                log.Description          = iivm.Description;
                log.LogTime              = DateTime.Now;
                log.PreviousId           = blockip.Id;
                LogBLO.Current.Add(log);
                return(RedirectToAction("Index", new { Message = "IP Address was unblocked!" }));
            }
            else
            {
                return(RedirectToAction("Index", new { FailUnBlock = "IP Address was unblocked already!" }));
            }
        }
Esempio n. 3
0
        public ActionResult BlockIP(IPIndexViewModel iivm)
        {
            //int? id = ipid.ToInt();

            var ip = new IPAddressPool();

            ip = IPAddressPoolBLO.Current.GetById(iivm.Id);
            if (ip.StatusCode == Constants.StatusCode.IP_AVAILABLE)
            {
                ip.StatusCode = Constants.StatusCode.IP_BLOCKED;
                IPAddressPoolDAO.Current.AddOrUpdate(ip);
                var log = new Log();
                log.TypeOfLog            = Constants.TypeOfLog.LOG_BLOCK_IP;
                log.Object               = Constants.Object.OBJECT_IP;
                log.ChangedValueOfObject = ip.IPAddress;
                log.ObjectStatus         = Constants.StatusCode.IP_BLOCKED;
                log.LogTime              = DateTime.Now;
                log.Description          = iivm.Description;
                LogBLO.Current.Add(log);
                return(RedirectToAction("Index", new { Message = "IP Address was blocked!" }));
            }
            else
            {
                return(RedirectToAction("Index", new { FailBlock = "IP Address was blocked already!" }));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// This function is responsible for updating the IP address pool.
        /// </summary>
        protected override void DoODLVSEMCmdlet()
        {
            var JavaScriptSerializer = new JavaScriptSerializer();

            JavaScriptSerializer.MaxJsonLength = int.MaxValue;
            StringBuilder json = new StringBuilder(" \"NetworkGatewayInfo\":" + JavaScriptSerializer.Serialize(this.NetworkGatewayInfo));

            json.Append("\"Name\":\"" + this.Name + "\"");
            json.Append("\"Description\":\"" + this.Description + "\"");
            json.Append("\"IPAddressSubnet\":\"" + this.IPAddressSubnet + "\"");
            json.Append("\"AddressRangeStart\":\"" + this.AddressRangeStart + "\"");
            json.Append("\"AddressRangeEnd\":\"" + this.AddressRangeEnd + "\"");
            json.Append("\"IPAddressPoolId\":\"" + this.IPAddressPoolId + "\"");
            ODLVSEMETW.EventWriteDoCmdlet(MethodBase.GetCurrentMethod().Name,
                                          "Updating IP Address Pool.",
                                          string.Empty);
            TransactionManager txnMng = new TransactionManager();

            txnMng.StartTransaction();
            var ope = TransactionManager.Operation.None;
            VSEMIPAddressPoolManagement vSEMIPAddressPoolManagement = null;

            try {
                string connectionString =
                    this.conn.ConnectionString.Split(',').FirstOrDefault();
                vSEMIPAddressPoolManagement =
                    new VSEMIPAddressPoolManagement(connectionString,
                                                    this.conn.Credential);
                IPAddressPool pool = vSEMIPAddressPoolManagement.UpdateIpAddressPool(txnMng,
                                                                                     this.Name,
                                                                                     this.Description,
                                                                                     this.IPAddressSubnet,
                                                                                     this.AddressRangeStart,
                                                                                     this.AddressRangeEnd,
                                                                                     this.NetworkGatewayInfo,
                                                                                     this.conn,
                                                                                     this.IPAddressPoolId);
                ODLVSEMETW.EventWriteReturnLibrary(string.Format(CultureInfo.CurrentCulture,
                                                                 "VSEM IP address pool with ID: {0} is updated",
                                                                 this.IPAddressPoolId.ToString("B")),
                                                   string.Empty);
                string output = "\"pool\":" + JavaScriptSerializer.Serialize(pool);
                ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, output);
                this.WriteObject(pool);

                ope = TransactionManager.Operation.Commit;
            } catch (Exception ex) {
                Exception exception = VSEMODLExceptionUtil.ConvertExceptionToVSEMException(ex);
                ODLVSEMETW.EventWriteFailedCmdlet(this.CmdletName, exception.GetType() + " : " + ex.Message);
                ope = TransactionManager.Operation.Rollback;
                ODLVSEMETW.EventWriteEndCmdlet(this.CmdletName, string.Empty);
                throw exception;
            } finally {
                txnMng.EndTransaction(ope);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Create a VSEM IP Address Pool.
        /// </summary>
        /// <param name="name">Name of IP address pool.</param>
        /// <param name="description">Description of IP address pool.</param>
        /// <param name="subnet">IP address subnet.</param>
        /// <param name="addressStart">Starting address for IP address pool.</param>
        /// <param name="addressEnd">Ending address for IP address pool.</param>
        /// <param name="gatewayInfo">Network gateway info.</param>
        /// <returns>New instance of VSEMIPAddressPool.</returns>
        private IPAddressPool CreateIpAddressPool(string name,
                                                  string description,
                                                  string subnet,
                                                  string addressStart,
                                                  string addressEnd,
                                                  NetworkGatewayInfo[] gatewayInfo)
        {
            if (string.IsNullOrEmpty(name))
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'name' is null or invalid.");
                throw new ArgumentException("The parameter 'name' is null or invalid.");
            }
            if (string.IsNullOrEmpty(subnet))
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'subnet' is null or invalid.");
                throw new ArgumentException("The parameter 'subnet' is null or invalid.");
            }
            if (string.IsNullOrEmpty(addressStart))
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'addressStart' is null or invalid.");
                throw new ArgumentException("The parameter 'addressStart' is null or invalid.");
            }
            if (string.IsNullOrEmpty(addressEnd))
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'addressEnd' is null or invalid.");
                throw new ArgumentException(
                          "The parameter 'addressEnd' is null or invalid.");
            }
            IPAddressPool pool = new IPAddressPool();

            pool.Id                    = Guid.NewGuid();
            pool.Name                  = name;
            pool.Description           = description;
            pool.IPAddressSubnet       = subnet;
            pool.AddressRangeStart     = addressStart;
            pool.AddressRangeEnd       = addressEnd;
            pool.NetworkGateways       = gatewayInfo;
            pool.LastModifiedTimeStamp = DateTime.Now;
            pool.IsNetBIOSEnabled      = false;

            return(pool);
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int           serverId = Utils.ParseInt(ddlServer.SelectedValue, 0);
                IPAddressPool pool     = (IPAddressPool)Enum.Parse(typeof(IPAddressPool), ddlPools.SelectedValue, true);
                string        comments = txtComments.Text.Trim();

                // add ip address
                if (endIP.Text != "" || startIP.Text.Contains("/"))
                {
                    try
                    {
                        // add IP range
                        ResultObject res = ES.Services.Servers.AddIPAddressesRange(pool, serverId, startIP.Text, endIP.Text,
                                                                                   internalIP.Text, subnetMask.Text, defaultGateway.Text, comments);
                        if (!res.IsSuccess)
                        {
                            // show error
                            messageBox.ShowMessage(res, "IP_ADD_IP_RANGE", "IP");
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowErrorMessage("IP_ADD_IP_RANGE", ex);
                        return;
                    }
                }
                else
                {
                    // add single IP
                    try
                    {
                        IntResult res = ES.Services.Servers.AddIPAddress(pool, serverId, startIP.Text,
                                                                         internalIP.Text, subnetMask.Text, defaultGateway.Text, comments);
                        if (!res.IsSuccess)
                        {
                            messageBox.ShowMessage(res, "IP_ADD_IP", "IP");
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowErrorMessage("IP_ADD_IP", ex);
                        return;
                    }
                }

                // Redirect back to the portal home page
                RedirectBack();
            }
        }
Esempio n. 7
0
        public DhcpAddressPool(DhcpPool pool)
        {
            Pool = pool;
            AvailableAddresses = new IPAddressPool(pool.Network);

            var toUnset = Pool.Exclusions.Clone();

            toUnset.Add(pool.Network.BaseNetwork.Network);
            toUnset.Add(pool.Network.Broadcast);
            toUnset.Add(Pool.DefaultGateways);
            UnsetAvailable(toUnset);
        }
 public void BindAddresses(ListBox list, IPAddressPool pool)
 {
     IPAddressInfo[] ips = ES.Services.Servers.GetUnallottedIPAddresses(PanelSecurity.PackageId, ResourceGroups.VPS, pool);
     foreach (IPAddressInfo ip in ips)
     {
         string txt = ip.ExternalIP;
         if (!String.IsNullOrEmpty(ip.DefaultGateway))
         {
             txt += "/" + ip.DefaultGateway;
         }
         list.Items.Add(new ListItem(txt, ip.AddressId.ToString()));
     }
 }
Esempio n. 9
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    int           serverId = Utils.ParseInt(ddlServer.SelectedValue, 0);
                    IPAddressPool pool     = IPAddressPool.PhoneNumbers;

                    ResultObject res = null;

                    // update single IP address
                    if (!String.IsNullOrEmpty(PanelRequest.Addresses))
                    {
                        // update multiple IPs
                        string[] ids       = PanelRequest.Addresses.Split(',');
                        int[]    addresses = new int[ids.Length];
                        for (int i = 0; i < ids.Length; i++)
                        {
                            addresses[i] = Utils.ParseInt(ids[i], 0);
                        }

                        res = ES.Services.Servers.UpdateIPAddresses(addresses,
                                                                    pool, serverId, "", "", txtComments.Text.Trim(), 0);
                    }
                    else
                    {
                        string address = Phone.Text;

                        // update single IP
                        res = ES.Services.Servers.UpdateIPAddress(PanelRequest.AddressID,
                                                                  pool, serverId, address, "", "", "", txtComments.Text.Trim(), 0);
                    }

                    if (!res.IsSuccess)
                    {
                        messageBox.ShowMessage(res, "IP_UPDATE_IP", "IP");
                        return;
                    }

                    //	 Redirect back to the portal home page
                    RedirectBack();
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("IP_UPDATE_IP", ex);
                    return;
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Check if IP address pools overlaps.
        /// </summary>
        /// <param name="poolFirst">First IP address pool.</param>
        /// <param name="poolSecond">Second IP address pool.</param>
        /// <returns>True if IP address pols overlap.</returns>
        private static bool AreIPAddressPoolsOverlapping(IPAddressPool poolFirst, IPAddressPool poolSecond)
        {
            bool overlap = false;

            if (poolFirst.Id.CompareTo(Guid.Empty) == 0 || poolSecond.Id.CompareTo(Guid.Empty) == 0)
            {
                return(overlap);
            }
            if ((IsLesser(poolFirst.AddressRangeStart, poolSecond.AddressRangeStart) &&
                 IsLesser(poolSecond.AddressRangeStart, poolFirst.AddressRangeEnd)) ||
                (IsLesser(poolFirst.AddressRangeStart, poolSecond.AddressRangeEnd) &&
                 IsLesser(poolSecond.AddressRangeEnd, poolFirst.AddressRangeEnd)) ||
                (IsLesser(poolSecond.AddressRangeStart, poolFirst.AddressRangeEnd) &&
                 IsLesser(poolFirst.AddressRangeEnd, poolSecond.AddressRangeEnd)))
            {
                overlap = true;
            }
            return(overlap);
        }
        public void BindAddresses(ListBox list, IPAddressPool pool, string selectedmac)
        {
            int    serviceId   = Utils.ParseInt(HyperVServices.SelectedValue, 0);
            string vmId        = VirtualMachines.SelectedValue;
            int    adaptervlan = 0;

            if (serviceId > 0 && vmId != "")
            {
                VirtualMachine vm = ES.Services.Proxmox.GetVirtualMachineExtendedInfo(serviceId, vmId);
                if (vm != null)
                {
                    foreach (VirtualMachineNetworkAdapter adapter in vm.Adapters)
                    {
                        if (adapter.MacAddress == selectedmac)
                        {
                            adaptervlan = adapter.vlan;
                        }
                    }
                }
            }
            list.Items.Clear();
            //IPAddressInfo[] ips = ES.Services.Servers.GetUnallottedIPAddresses(PanelSecurity.PackageId, ResourceGroups.Proxmox, pool);
            IPAddressInfo[] ips = ES.Services.Servers.GetUnallottedIPAddresses(-1, serviceId.ToString(), pool);
            foreach (IPAddressInfo ip in ips)
            {
                if (ip.VLAN == adaptervlan)
                {
                    string txt = ip.ExternalIP;
                    if (!String.IsNullOrEmpty(ip.DefaultGateway))
                    {
                        txt += "/" + ip.DefaultGateway;
                    }
                    list.Items.Add(new ListItem(txt, ip.AddressId.ToString()));
                }
            }
        }
Esempio n. 12
0
 public int GetIPAddressesPagedCount(IPAddressPool pool, int serverId, string filterColumn, string filterValue)
 {
     return(ips.Count);
 }
 public int GetPackageIPAddressesCount(int packageId, IPAddressPool pool, string filterColumn, string filterValue)
 {
     return packageAddresses.Count;
 }
Esempio n. 14
0
 public IntResult AddIPAddress(IPAddressPool pool, int serverId,
                               string externalIP, string internalIP, string subnetMask, string defaultGateway, string comments)
 {
     return(ServerController.AddIPAddress(pool, serverId, externalIP, internalIP, subnetMask, defaultGateway, comments));
 }
Esempio n. 15
0
 public int GetIPAddressesPagedCount(IPAddressPool pool, int serverId, string filterColumn, string filterValue)
 {
     return ips.Count;
 }
Esempio n. 16
0
 public ResultObject AllocateMaximumPackageIPAddresses(int packageId, string groupName, IPAddressPool pool)
 {
     return(ServerController.AllocateMaximumPackageIPAddresses(packageId, groupName, pool));
 }
Esempio n. 17
0
 /// <remarks/>
 public System.IAsyncResult BeginAllocateMaximumPackageIPAddresses(int packageId, string groupName, IPAddressPool pool, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("AllocateMaximumPackageIPAddresses", new object[] {
                 packageId,
                 groupName,
                 pool}, callback, asyncState);
 }
Esempio n. 18
0
        public static ResultObject AllocateMaximumPackageIPAddresses(int packageId, string groupName, IPAddressPool pool)
        {
            // get maximum server IPs
            int maxAvailableIPs = GetUnallottedIPAddresses(packageId, groupName, pool).Count;

            // get quota name
            string quotaName = GetIPAddressesQuotaByResourceGroup(groupName);

            // get hosting plan IPs
            int number = 0;

            PackageContext cntx = PackageController.GetPackageContext(packageId);
            if (cntx.Quotas.ContainsKey(quotaName))
            {
                number = cntx.Quotas[quotaName].QuotaAllocatedValue;
                if (number == -1)
                {
                    // unlimited
                    if (number > maxAvailableIPs) // requested more than available
                        number = maxAvailableIPs; // assign max available server IPs
                }
                else
                {
                    // quota
                    number = number - cntx.Quotas[quotaName].QuotaUsedValue;
                }
            }

            // allocate
            return AllocatePackageIPAddresses(packageId, groupName, pool,
                true, number, new int[0]);
        }
Esempio n. 19
0
 public PackageIPAddressesPaged GetPackageIPAddresses(int packageId, int orgId, IPAddressPool pool,
                                                      string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows, bool recursive)
 {
     return(ServerController.GetPackageIPAddresses(packageId, orgId, pool,
                                                   filterColumn, filterValue, sortColumn, startRow, maximumRows, recursive));
 }
Esempio n. 20
0
        public static List<IPAddressInfo> GetUnallottedIPAddresses(int packageId, string groupName, IPAddressPool pool)
        {
            // get service ID
            int serviceId = PackageController.GetPackageServiceId(packageId, groupName);

            // get unallotted addresses
            return ObjectUtils.CreateListFromDataReader<IPAddressInfo>(
                DataProvider.GetUnallottedIPAddresses(packageId, serviceId, (int)pool));
        }
Esempio n. 21
0
        public static ResultObject AllocatePackageIPAddresses(int packageId, string groupName, IPAddressPool pool, bool allocateRandom, int addressesNumber, int[] addressId)
        {
            #region Check account and space statuses
            // create result object
            ResultObject res = new ResultObject();

            // check account
            if (!SecurityContext.CheckAccount(res, DemandAccount.NotDemo | DemandAccount.IsActive))
                return res;

            // check package
            if (!SecurityContext.CheckPackage(res, packageId, DemandPackage.IsActive))
                return res;
            #endregion

            // get total number of addresses requested
            if (!allocateRandom && addressId != null)
                addressesNumber = addressId.Length;

            if (addressesNumber <= 0)
            {
                res.IsSuccess = true;
                return res; // just exit
            }

            // check quotas
            string quotaName = GetIPAddressesQuotaByResourceGroup(groupName);

            // get maximum server IPs
            List<IPAddressInfo> ips = ServerController.GetUnallottedIPAddresses(packageId, groupName, pool);
            int maxAvailableIPs = ips.Count;

            if (maxAvailableIPs == 0)
            {
                res.ErrorCodes.Add("IP_ADDRESSES_POOL_IS_EMPTY");
                return res;
            }

            // get hosting plan IP limits
            PackageContext cntx = PackageController.GetPackageContext(packageId);
            int quotaAllocated = cntx.Quotas[quotaName].QuotaAllocatedValue;
            int quotaUsed = cntx.Quotas[quotaName].QuotaUsedValue;

            // check the maximum allowed number
            if (quotaAllocated != -1 &&
                (addressesNumber > (quotaAllocated - quotaUsed)))
            {
                res.ErrorCodes.Add("IP_ADDRESSES_QUOTA_LIMIT_REACHED");
                return res;
            }

            // check if requested more than available
            if (addressesNumber > maxAvailableIPs)
                addressesNumber = maxAvailableIPs;

            res = TaskManager.StartResultTask<ResultObject>("IP_ADDRESS", "ALLOCATE_PACKAGE_IP");
            TaskManager.PackageId = packageId;

            try
            {
                if (allocateRandom)
                {
                    int[] ids = new int[addressesNumber];
                    for (int i = 0; i < addressesNumber; i++)
                        ids[i] = ips[i].AddressId;

                    addressId = ids;
                }

                // prepare XML document
                string xml = PrepareIPsXML(addressId);

                // save to database
                try
                {
                    DataProvider.AllocatePackageIPAddresses(packageId, xml);
                }
                catch (Exception ex)
                {
                    TaskManager.CompleteResultTask(res, VirtualizationErrorCodes.CANNOT_ADD_IP_ADDRESSES_TO_DATABASE, ex);
                    return res;
                }
            }
            catch (Exception ex)
            {
                TaskManager.CompleteResultTask(res, VirtualizationErrorCodes.ALLOCATE_EXTERNAL_ADDRESSES_GENERAL_ERROR, ex);
                return res;
            }

            TaskManager.CompleteResultTask();
            return res;
        }
Esempio n. 22
0
        public static PackageIPAddressesPaged GetPackageIPAddresses(int packageId, IPAddressPool pool,
            string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows, bool recursive)
        {
            PackageIPAddressesPaged result = new PackageIPAddressesPaged();

            // get reader
            IDataReader reader = DataProvider.GetPackageIPAddresses(packageId, (int)pool, filterColumn, filterValue, sortColumn, startRow, maximumRows, recursive);

            // number of items = first data reader
            reader.Read();
            result.Count = (int)reader[0];

            // items = second data reader
            reader.NextResult();
            result.Items = ObjectUtils.CreateListFromDataReader<PackageIPAddress>(reader).ToArray();

            return result;
        }
Esempio n. 23
0
        public static ResultObject UpdateIPAddresses(int[] addresses, IPAddressPool pool, int serverId,
            string subnetMask, string defaultGateway, string comments)
        {
            ResultObject res = new ResultObject();

            #region Check account statuses
            // check account
            if (!SecurityContext.CheckAccount(res, DemandAccount.NotDemo | DemandAccount.IsAdmin | DemandAccount.IsActive))
                return res;
            #endregion

            // start task
            res = TaskManager.StartResultTask<ResultObject>("IP_ADDRESS", "UPDATE_RANGE");

            try
            {
                string xmlIds = PrepareIPsXML(addresses);
                DataProvider.UpdateIPAddresses(xmlIds, (int)pool, serverId, subnetMask, defaultGateway, comments);
            }
            catch (Exception ex)
            {
                TaskManager.CompleteResultTask(res, "IP_ADDRESSES_UPDATE_ERROR", ex);
                return res;
            }

            TaskManager.CompleteResultTask();
            return res;
        }
Esempio n. 24
0
 public ResultObject UpdateIPAddress(int addressId, IPAddressPool pool, int serverId,
                                     string externalIP, string internalIP, string subnetMask, string defaultGateway, string comments)
 {
     return(ServerController.UpdateIPAddress(addressId, pool, serverId, externalIP, internalIP, subnetMask, defaultGateway, comments));
 }
Esempio n. 25
0
 public IPAddressesPaged GetIPAddressesPaged(IPAddressPool pool, int serverId,
                                             string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
 {
     return(ServerController.GetIPAddressesPaged(pool, serverId, filterColumn, filterValue, sortColumn, startRow, maximumRows));
 }
Esempio n. 26
0
 public static List<PackageIPAddress> GetItemIPAddresses(int itemId, IPAddressPool pool)
 {
     return ObjectUtils.CreateListFromDataReader<PackageIPAddress>(
         DataProvider.GetItemIPAddresses(SecurityContext.User.UserId, itemId, (int)pool));
 }
Esempio n. 27
0
 public ResultObject UpdateIPAddresses(int[] addresses, IPAddressPool pool, int serverId,
                                       string subnetMask, string defaultGateway, string comments, int VLAN)
 {
     return(ServerController.UpdateIPAddresses(addresses, pool, serverId, subnetMask, defaultGateway, comments, VLAN));
 }
Esempio n. 28
0
 public static List<IPAddressInfo> GetIPAddresses(IPAddressPool pool, int serverId)
 {
     return ObjectUtils.CreateListFromDataReader<IPAddressInfo>(
         DataProvider.GetIPAddresses(SecurityContext.User.UserId, (int)pool, serverId));
 }
Esempio n. 29
0
 public List <PackageIPAddress> GetPackageUnassignedIPAddresses(int packageId, int orgId, IPAddressPool pool)
 {
     return(ServerController.GetPackageUnassignedIPAddresses(packageId, orgId, pool));
 }
Esempio n. 30
0
        public static IPAddressesPaged GetIPAddressesPaged(IPAddressPool pool, int serverId,
            string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
        {
            IPAddressesPaged result = new IPAddressesPaged();

            // get reader
            IDataReader reader = DataProvider.GetIPAddressesPaged(SecurityContext.User.UserId, (int)pool, serverId, filterColumn, filterValue, sortColumn, startRow, maximumRows);

            // number of items = first data reader
            reader.Read();
            result.Count = (int)reader[0];

            // items = second data reader
            reader.NextResult();
            result.Items = ObjectUtils.CreateListFromDataReader<IPAddressInfo>(reader).ToArray();

            return result;
        }
Esempio n. 31
0
 /// <remarks/>
 public void AllocateMaximumPackageIPAddressesAsync(int packageId, string groupName, IPAddressPool pool, object userState) {
     if ((this.AllocateMaximumPackageIPAddressesOperationCompleted == null)) {
         this.AllocateMaximumPackageIPAddressesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAllocateMaximumPackageIPAddressesOperationCompleted);
     }
     this.InvokeAsync("AllocateMaximumPackageIPAddresses", new object[] {
                 packageId,
                 groupName,
                 pool}, this.AllocateMaximumPackageIPAddressesOperationCompleted, userState);
 }
Esempio n. 32
0
        public static IntResult AddIPAddress(IPAddressPool pool, int serverId,
            string externalIP, string internalIP, string subnetMask, string defaultGateway, string comments)
        {
            IntResult res = new IntResult();

            #region Check account statuses
            // check account
            if (!SecurityContext.CheckAccount(res, DemandAccount.NotDemo | DemandAccount.IsAdmin | DemandAccount.IsActive))
                return res;
            #endregion

            // start task
            res = TaskManager.StartResultTask<IntResult>("IP_ADDRESS", "ADD");
            TaskManager.ItemName = externalIP;
            TaskManager.WriteParameter("IP Address", externalIP);
            TaskManager.WriteParameter("NAT Address", internalIP);

            try
            {
                res.Value = DataProvider.AddIPAddress((int)pool, serverId, externalIP, internalIP,
                                            subnetMask, defaultGateway, comments);

            }
            catch (Exception ex)
            {
                TaskManager.CompleteResultTask(res, "IP_ADDRESS_ADD_ERROR", ex);
                return res;
            }

            TaskManager.CompleteResultTask();
            return res;
        }
Esempio n. 33
0
        /// <summary>
        /// Check if IP address pool is valid.
        /// </summary>
        /// <param name="pool">IP address pool to check.</param>
        /// <returns>true if UP address pool is valid.</returns>
        private static string IsIPAddressPoolValid(IPAddressPool pool)
        {
            StringBuilder isvalid = new StringBuilder();

            if (pool == null)
            {
                return(isvalid.ToString());
            }

            if (!string.IsNullOrEmpty(pool.AddressRangeStart))
            {
                if (!Validations.IsIPAddressValid(pool.AddressRangeStart))
                {
                    isvalid.Append("Format of IP address in AddressRangeStart is invalid.\n"
                                   + ipStringValidationMessage + "\n");
                }
            }

            if (!string.IsNullOrEmpty(pool.AddressRangeEnd))
            {
                if (!Validations.IsIPAddressValid(pool.AddressRangeEnd))
                {
                    isvalid.Append("Format of IP address in AddressRangeEnd is invalid.\n"
                                   + ipStringValidationMessage + "\n");
                }
            }

            if (!string.IsNullOrEmpty(pool.IPAddressSubnet))
            {
                if (!Validations.IsIPAddressWithSubnetValid(
                        pool.IPAddressSubnet))
                {
                    isvalid.Append(ipStringWithPortValidationMessage + "\n");
                }
            }

            if (!string.IsNullOrEmpty(isvalid.ToString()))
            {
                return(isvalid.ToString());
            }

            if (!string.IsNullOrEmpty(pool.IPAddressSubnet))
            {
                isvalid.Append(IsInRange(pool.IPAddressSubnet,
                                         pool.AddressRangeStart,
                                         "AddressRangeStart",
                                         pool.AddressRangeEnd,
                                         "AddressRangeEnd"));
            }

            if (!string.IsNullOrEmpty(isvalid.ToString()))
            {
                return(isvalid.ToString());
            }

            if (!string.IsNullOrEmpty(pool.AddressRangeStart) &&
                !string.IsNullOrEmpty(pool.AddressRangeEnd))
            {
                if (!IsLesser(pool.AddressRangeStart,
                              pool.AddressRangeEnd))
                {
                    isvalid.Append(
                        "'AddressRangeStart' cannot be greater than 'AddressRangeEnd'.\n");
                }
            }

            if (pool.NetworkGateways != null)
            {
                foreach (var networkGateway in pool.NetworkGateways)
                {
                    if (!string.IsNullOrEmpty(networkGateway.IPAddress))
                    {
                        if (!Validations.IsIPAddressValid(networkGateway.IPAddress))
                        {
                            isvalid.Append(
                                "Format of one or more IP address(s) in NetworkGatewayInfo is invalid.\n"
                                + ipStringValidationMessage + "\n");
                            break;
                        }
                        isvalid.Append(IsInRange(pool.IPAddressSubnet,
                                                 networkGateway.IPAddress,
                                                 "IPAddress of NetworkGatewayInfo",
                                                 null,
                                                 null));
                    }
                    else
                    {
                        isvalid.Append(
                            "Value of one or more IP address(s) in NetworkGatewayInfo is null.\n"
                            + ipStringValidationMessage + "\n");
                        break;
                    }

                    if (networkGateway.Metric != null &&
                        (networkGateway.Metric < 1 ||
                         networkGateway.Metric > 9999))
                    {
                        isvalid.Append(
                            "Value of one or more Metric(s) in NetworkGatewayInfo is invalid.\n"
                            + "Value of Metric in NetworkGatwayInfo should be between 1 and 9999.\n");
                        break;
                    }
                }
            }
            return(isvalid.ToString());
        }
Esempio n. 34
0
        public static ResultObject AddIPAddressesRange(IPAddressPool pool, int serverId,
            string externalIP, string endIP, string internalIP, string subnetMask, string defaultGateway, string comments)
        {
            ResultObject res = new ResultObject();

            #region Check account statuses
            // check account
            if (!SecurityContext.CheckAccount(res, DemandAccount.NotDemo | DemandAccount.IsAdmin | DemandAccount.IsActive))
                return res;
            #endregion

            // start task
            res = TaskManager.StartResultTask<ResultObject>("IP_ADDRESS", "ADD_RANGE");
            TaskManager.ItemName = externalIP;
            TaskManager.WriteParameter("IP Address", externalIP);
            TaskManager.WriteParameter("End IP Address", endIP);
            TaskManager.WriteParameter("NAT Address", internalIP);

            try
            {
                if (externalIP == endIP)
                {
                    // add single IP and exit
                    AddIPAddress(pool, serverId, externalIP, internalIP, subnetMask, defaultGateway, comments);
                    TaskManager.CompleteResultTask();
                    return res;
                }

                long startExternalIP = ConvertIPToLong(externalIP);
                long startInternalIP = ConvertIPToLong(internalIP);
                long endExternalIP = ConvertIPToLong(endIP);

                int i = 0;
                long step = (endExternalIP < startExternalIP) ? -1 : 1;

                while (true)
                {
                    if (i > 128)
                        break;

                    // add IP address
                    DataProvider.AddIPAddress((int)pool, serverId,
                        ConvertLongToIP(startExternalIP),
                        ConvertLongToIP(startInternalIP),
                        subnetMask, defaultGateway, comments);

                    if (startExternalIP == endExternalIP)
                        break;

                    i++;

                    startExternalIP += step;

                    if (startInternalIP != 0)
                        startInternalIP += step;
                }
            }
            catch (Exception ex)
            {
                TaskManager.CompleteResultTask(res, "IP_ADDRESS_ADD_RANGE_ERROR", ex);
                return res;
            }

            TaskManager.CompleteResultTask();
            return res;
        }
Esempio n. 35
0
 public IPAddressInfo[] GetIPAddressesPaged(IPAddressPool pool, int serverId, string filterColumn, string filterValue,
     string sortColumn, int maximumRows, int startRowIndex)
 {
     ips = ES.Services.Servers.GetIPAddressesPaged(pool, serverId, filterColumn, filterValue, sortColumn, startRowIndex, maximumRows);
     return ips.Items;
 }
Esempio n. 36
0
 public List<IPAddressInfo> GetIPAddresses(IPAddressPool pool, int serverId)
 {
     return ServerController.GetIPAddresses(pool, serverId);
 }
Esempio n. 37
0
 public IPAddressInfo[] GetIPAddressesPaged(IPAddressPool pool, int serverId, string filterColumn, string filterValue,
                                            string sortColumn, int maximumRows, int startRowIndex)
 {
     ips = ES.Services.Servers.GetIPAddressesPaged(pool, serverId, filterColumn, filterValue, sortColumn, startRowIndex, maximumRows);
     return(ips.Items);
 }
Esempio n. 38
0
 public IPAddressesPaged GetIPAddressesPaged(IPAddressPool pool, int serverId,
     string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
 {
     return ServerController.GetIPAddressesPaged(pool, serverId, filterColumn, filterValue, sortColumn, startRow, maximumRows);
 }
 public PackageIPAddress[] GetPackageIPAddresses(int packageId, IPAddressPool pool, string filterColumn, string filterValue,
     string sortColumn, int maximumRows, int startRowIndex)
 {
     packageAddresses = ES.Services.Servers.GetPackageIPAddresses(packageId, pool,
         filterColumn, filterValue, sortColumn, startRowIndex, maximumRows, true);
     return packageAddresses.Items;
 }
Esempio n. 40
0
 public ResultObject AddIPAddressesRange(IPAddressPool pool, int serverId,
     string externalIP, string endIP, string internalIP, string subnetMask, string defaultGateway, string comments)
 {
     return ServerController.AddIPAddressesRange(pool, serverId, externalIP, endIP, internalIP, subnetMask, defaultGateway, comments);
 }
Esempio n. 41
0
 public List <IPAddressInfo> GetIPAddresses(IPAddressPool pool, int serverId)
 {
     return(ServerController.GetIPAddresses(pool, serverId));
 }
Esempio n. 42
0
 public ResultObject UpdateIPAddress(int addressId, IPAddressPool pool, int serverId,
     string externalIP, string internalIP, string subnetMask, string defaultGateway, string comments)
 {
     return ServerController.UpdateIPAddress(addressId, pool, serverId, externalIP, internalIP, subnetMask, defaultGateway, comments);
 }
Esempio n. 43
0
 public ResultObject AddIPAddressesRange(IPAddressPool pool, int serverId,
                                         string externalIP, string endIP, string internalIP, string subnetMask, string defaultGateway, string comments, int VLAN)
 {
     return(ServerController.AddIPAddressesRange(pool, serverId, externalIP, endIP, internalIP, subnetMask, defaultGateway, comments, VLAN));
 }
Esempio n. 44
0
 public ResultObject UpdateIPAddresses(int[] addresses, IPAddressPool pool, int serverId,
     string subnetMask, string defaultGateway, string comments)
 {
     return ServerController.UpdateIPAddresses(addresses, pool, serverId, subnetMask, defaultGateway, comments);
 }
Esempio n. 45
0
 public List <IPAddressInfo> GetUnallottedIPAddresses(int packageId, string groupName, IPAddressPool pool)
 {
     return(ServerController.GetUnallottedIPAddresses(packageId, groupName, pool));
 }
Esempio n. 46
0
        /// <summary>
        /// Update the specified IP Address Pool with the specified info.
        /// </summary>
        /// <param name="txnMng">Transaction manager.</param>
        /// <param name="name">Name of IP Address Pool.</param>
        /// <param name="description">Description for IP address Pool.</param>
        /// <param name="subnet">IP address subnet.</param>
        /// <param name="addressStart">Starting address for IP Address Pool.</param>
        /// <param name="addressEnd">Ending address for IP Address Pool.</param>
        /// <param name="gatewayInfo">Network gateway info.</param>
        /// <param name="conn">VSEM connection object.</param>
        /// <param name="ipAddressPoolId">IP address pool.</param>
        /// <returns>Updated IP address pool.</returns>
        public IPAddressPool UpdateIpAddressPool(TransactionManager txnMng,
                                                 string name,
                                                 string description,
                                                 string subnet,
                                                 string addressStart,
                                                 string addressEnd,
                                                 NetworkGatewayInfo[] gatewayInfo,
                                                 VSEMConnection conn,
                                                 Guid ipAddressPoolId)
        {
            var JavaScriptSerializer = new JavaScriptSerializer();

            JavaScriptSerializer.MaxJsonLength = int.MaxValue;
            StringBuilder json = new StringBuilder("\"txnMng\":" + JavaScriptSerializer.Serialize(txnMng));

            json.Append(" \"gatewayInfo\":" + JavaScriptSerializer.Serialize(gatewayInfo));
            json.Append("\"name\":\"" + name + "\"");
            json.Append("\"description\":\"" + description + "\"");
            json.Append("\"subnet\":\"" + subnet + "\"");
            json.Append("\"addressStart\":\"" + addressStart + "\"");
            json.Append("\"addressEnd\":\"" + addressEnd + "\"");
            json.Append("\"ipAddressPoolId\":\"" + ipAddressPoolId + "\"");
            ODLVSEMETW.EventWriteStartLibrary(MethodBase.GetCurrentMethod().Name,
                                              json.ToString());
            if (txnMng == null)
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'txnMng' is null or invalid.");
                throw new ArgumentException("The parameter 'txnMng' is null or invalid.");
            }
            if (conn == null)
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'conn' is null or invalid.");
                throw new ArgumentException("The parameter 'conn' is null or invalid.");
            }
            if (name != null)
            {
                if (string.IsNullOrWhiteSpace(name))
                {
                    ODLVSEMETW.EventWriteArgumentError(
                        MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                        MethodBase.GetCurrentMethod().Name,
                        "The parameter 'name' is invalid.");
                    throw new ArgumentException(
                              "The parameter 'name' is invalid.");
                }
            }

            string VtnHostName = this.ConnectionString;

            if (VtnHostName.StartsWith(@"https://", StringComparison.Ordinal))
            {
                VtnHostName = VtnHostName.Substring(8);
            }

            VtnHostName = VtnHostName.Split('.', ':').First();

            var vMNetworkConfig = new VMNetworkConfig(VtnHostName);

            txnMng.SetConfigManager(vMNetworkConfig, TransactionManager.OpenMode.WriteMode);
            if (vMNetworkConfig.VMNetwork.VMNetworkMappingInformation.VMNetworkInfo.Count == 0)
            {
                ODLVSEMETW.EventWriteConfigManagerFileIOError(MethodBase.GetCurrentMethod().Name,
                                                              string.Format(CultureInfo.CurrentCulture,
                                                                            "VMNetwork.config {0}",
                                                                            configFileIOErrorValidationMessage));
                throw new InvalidOperationException(
                          string.Format(CultureInfo.CurrentCulture,
                                        "VMNetwork.config {0}",
                                        configFileIOErrorValidationMessage));
            }

            VMSubnet      vmNetDefFrom = null;
            IPAddressPool pool         = null;

            foreach (var vmNet in vMNetworkConfig.VMNetwork.VmNetworks)
            {
                foreach (var vmNetDef in vmNet.VMSubnets)
                {
                    if (vmNetDef.IPSubnets != null)
                    {
                        foreach (var ipsunet in vmNetDef.IPSubnets)
                        {
                            pool = ipsunet.IPAddressPools.FirstOrDefault(p => p.Id == ipAddressPoolId);
                            if (pool != null)
                            {
                                vmNetDefFrom = vmNetDef;
                                break;
                            }
                        }
                    }
                    if (vmNetDefFrom != null)
                    {
                        break;
                    }
                }
                if (vmNetDefFrom != null)
                {
                    break;
                }
            }

            if (vmNetDefFrom == null)
            {
                ODLVSEMETW.EventWriteValidateIPAddressPoolError(
                    MethodBase.GetCurrentMethod().Name,
                    string.Format(CultureInfo.CurrentCulture,
                                  "IP Address Pool '{0}' not found.",
                                  ipAddressPoolId));
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                          "IP Address Pool '{0}' not found.",
                                                          ipAddressPoolId));
            }

            this.SyncVMSubnet(vmNetDefFrom.Id, vMNetworkConfig);

            if (pool != null)
            {
                // Update the IP Address Pool
                if (name != null)
                {
                    pool.Name = name;
                }

                if (description != null)
                {
                    pool.Description = description;
                }

                if (subnet != null)
                {
                    pool.IPAddressSubnet = subnet;
                }

                if (addressStart != null)
                {
                    pool.AddressRangeStart = addressStart;
                }

                if (addressEnd != null)
                {
                    pool.AddressRangeEnd = addressEnd;
                }

                if (gatewayInfo != null)
                {
                    pool.NetworkGateways = gatewayInfo;
                }
                string error = Validations.IsIPSubnetListValid(
                    vmNetDefFrom.IPSubnets.ToList(),
                    ipAddressPoolId);
                if (!string.IsNullOrEmpty(error))
                {
                    ODLVSEMETW.EventWriteValidateVMNetDefinitionError(
                        MethodBase.GetCurrentMethod().Name,
                        error);
                    throw new ArgumentException(error);
                }
            }

            string output = "\"pool\":" + JavaScriptSerializer.Serialize(pool);

            ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, output);
            return(pool);
        }
Esempio n. 47
0
 public int GetPackageIPAddressesCount(int packageId, int orgId, IPAddressPool pool)
 {
     return(ServerController.GetPackageIPAddressesCount(packageId, orgId, pool));
 }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int           serverId = Utils.ParseInt(ddlServer.SelectedValue, 0);
                IPAddressPool pool     = IPAddressPool.PhoneNumbers;
                string        comments = txtComments.Text.Trim();

                string start;
                string end;

                start = startPhone.Text;
                end   = endPhone.Text;

                // add ip address
                if (end != "" || start.Contains("/"))
                {
                    string errorKey = "IP_ADD_PHONE_RANGE";

                    try
                    {
                        // add IP range
                        ResultObject res = ES.Services.Servers.AddIPAddressesRange(pool, serverId, start, end,
                                                                                   "", "", "", comments);
                        if (!res.IsSuccess)
                        {
                            // show error
                            messageBox.ShowMessage(res, errorKey, "IP");
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowErrorMessage(errorKey, ex);
                        return;
                    }
                }
                else
                {
                    string errorKey = "IP_ADD_PHONE";

                    // add single IP
                    try
                    {
                        IntResult res = ES.Services.Servers.AddIPAddress(pool, serverId, start,
                                                                         "", "", "", comments);
                        if (!res.IsSuccess)
                        {
                            messageBox.ShowMessage(res, errorKey, "IP");
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowErrorMessage(errorKey, ex);
                        return;
                    }
                }

                // Redirect back to the portal home page
                RedirectBack();
            }
        }
Esempio n. 49
0
 public ResultObject AllocatePackageIPAddresses(int packageId, int orgId, string groupName, IPAddressPool pool, bool allocateRandom, int addressesNumber,
                                                int[] addressId)
 {
     return(ServerController.AllocatePackageIPAddresses(packageId, orgId, groupName, pool, allocateRandom,
                                                        addressesNumber, addressId));
 }
Esempio n. 50
0
 public int GetPackageIPAddressesCount(int packageId, int orgId, IPAddressPool pool)
 {
     return ServerController.GetPackageIPAddressesCount(packageId, orgId, pool);
 }
 public void BindAddresses(ListBox list, IPAddressPool pool)
 {
     IPAddressInfo[] ips = ES.Services.Servers.GetUnallottedIPAddresses(PanelSecurity.PackageId, ResourceGroups.VPS, pool);
     foreach (IPAddressInfo ip in ips)
     {
         string txt = ip.ExternalIP;
         if (!String.IsNullOrEmpty(ip.DefaultGateway))
             txt += "/" + ip.DefaultGateway;
         list.Items.Add(new ListItem(txt, ip.AddressId.ToString()));
     }
 }
Esempio n. 52
0
 public List<PackageIPAddress> GetPackageUnassignedIPAddresses(int packageId, int orgId, IPAddressPool pool)
 {
     return ServerController.GetPackageUnassignedIPAddresses(packageId, orgId, pool);
 }
Esempio n. 53
0
 /// <remarks/>
 public void AllocateMaximumPackageIPAddressesAsync(int packageId, string groupName, IPAddressPool pool) {
     this.AllocateMaximumPackageIPAddressesAsync(packageId, groupName, pool, null);
 }
Esempio n. 54
0
 public ResultObject AllocatePackageIPAddresses(int packageId,int orgId, string groupName, IPAddressPool pool, bool allocateRandom, int addressesNumber,
     int[] addressId)
 {
     return ServerController.AllocatePackageIPAddresses(packageId, orgId, groupName, pool, allocateRandom,
         addressesNumber, addressId);
 }
Esempio n. 55
0
 public ResultObject AllocateMaximumPackageIPAddresses(int packageId, string groupName, IPAddressPool pool) {
     object[] results = this.Invoke("AllocateMaximumPackageIPAddresses", new object[] {
                 packageId,
                 groupName,
                 pool});
     return ((ResultObject)(results[0]));
 }
Esempio n. 56
0
 public ResultObject AllocateMaximumPackageIPAddresses(int packageId, string groupName, IPAddressPool pool)
 {
     return ServerController.AllocateMaximumPackageIPAddresses(packageId, groupName, pool);
 }
Esempio n. 57
0
 public List<IPAddressInfo> GetUnallottedIPAddresses(int packageId, string groupName, IPAddressPool pool)
 {
     return ServerController.GetUnallottedIPAddresses(packageId, groupName, pool);
 }
Esempio n. 58
0
        /// <summary>
        /// Create an IP Address Pool and add it to the specified VM Subnet.
        /// </summary>
        /// <param name="txnMng">Transaction manager.</param>
        /// <param name="name">Name of IP address pool.</param>
        /// <param name="description">Description for IP address pool.</param>
        /// <param name="subnet">IP address subnet.</param>
        /// <param name="addressStart">Starting address for IP address pool.</param>
        /// <param name="addressEnd">Ending address for IP address pool.</param>
        /// <param name="gatewayInfo">Network gateway info.</param>
        /// <param name="vmNetworkDefinitionId">VM Subnet ID.</param>
        /// <returns>Newly created ip address pool.</returns>
        public IPAddressPool CreateIpAddressPool(TransactionManager txnMng,
                                                 string name,
                                                 string description,
                                                 string subnet,
                                                 string addressStart,
                                                 string addressEnd,
                                                 NetworkGatewayInfo[] gatewayInfo,
                                                 Guid vmNetworkDefinitionId)
        {
            var JavaScriptSerializer = new JavaScriptSerializer();

            JavaScriptSerializer.MaxJsonLength = int.MaxValue;
            StringBuilder json = new StringBuilder("\"txnMng\":" + JavaScriptSerializer.Serialize(txnMng));

            json.Append(" \"gatewayInfo\":" + JavaScriptSerializer.Serialize(gatewayInfo));
            json.Append("\"name\":\"" + name + "\"");
            json.Append("\"description\":\"" + description + "\"");
            json.Append("\"subnet\":\"" + subnet + "\"");
            json.Append("\"addressStart\":\"" + addressStart + "\"");
            json.Append("\"addressEnd\":\"" + addressEnd + "\"");
            ODLVSEMETW.EventWriteStartLibrary(MethodBase.GetCurrentMethod().Name,
                                              json.ToString());
            if (txnMng == null)
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'txnMng' is null or invalid.");
                throw new ArgumentException("The parameter 'txnMng' is null or invalid.");
            }
            if (string.IsNullOrEmpty(name))
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'name' is null or invalid.");
                throw new ArgumentException("The parameter 'name' is null or invalid.");
            }
            if (string.IsNullOrEmpty(subnet))
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'subnet' is null or invalid.");
                throw new ArgumentException("The parameter 'subnet' is null or invalid.");
            }
            if (string.IsNullOrEmpty(addressStart))
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'addressStart' is null or invalid.");
                throw new ArgumentException("The parameter 'addressStart' is null or invalid.");
            }
            if (string.IsNullOrEmpty(addressEnd))
            {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'addressEnd' is null or invalid.");
                throw new ArgumentException(
                          "The parameter 'addressEnd' is null or invalid.");
            }
            string VtnHostName = this.ConnectionString;

            if (VtnHostName.StartsWith(@"https://", StringComparison.Ordinal))
            {
                VtnHostName = VtnHostName.Substring(8);
            }

            VtnHostName = VtnHostName.Split('.', ':').First();

            var vMNetworkConfig = new VMNetworkConfig(VtnHostName);

            txnMng.SetConfigManager(vMNetworkConfig, TransactionManager.OpenMode.WriteMode);
            if (vMNetworkConfig.VMNetwork.VMNetworkMappingInformation.VMNetworkInfo.Count == 0)
            {
                ODLVSEMETW.EventWriteConfigManagerFileIOError(
                    MethodBase.GetCurrentMethod().Name,
                    string.Format(CultureInfo.CurrentCulture,
                                  "VMNetwork.config {0}",
                                  configFileIOErrorValidationMessage));
                throw new InvalidOperationException(
                          string.Format(CultureInfo.CurrentCulture,
                                        "VMNetwork.config {0}",
                                        configFileIOErrorValidationMessage));
            }

            VMSubnet vmNetDef = null;

            foreach (var vmNet in vMNetworkConfig.VMNetwork.VmNetworks)
            {
                vmNetDef = vmNet.VMSubnets.FirstOrDefault(vmSubNet =>
                                                          vmSubNet.Id == vmNetworkDefinitionId);
                if (vmNetDef != null)
                {
                    break;
                }
            }

            if (vmNetDef == null)
            {
                ODLVSEMETW.EventWriteValidateVMNetDefinitionError(
                    MethodBase.GetCurrentMethod().Name,
                    string.Format(CultureInfo.CurrentCulture,
                                  "VM Subnet '{0}' not found.",
                                  vmNetworkDefinitionId.ToString("B")));
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                          "VM Subnet '{0}' not found.",
                                                          vmNetworkDefinitionId.ToString("B")));
            }

            this.SyncVMSubnet(vmNetworkDefinitionId, vMNetworkConfig);

            IPAddressPool poolAdd = null;

            if (vmNetDef != null)
            {
                poolAdd = this.CreateIpAddressPool(name,
                                                   description,
                                                   subnet,
                                                   addressStart,
                                                   addressEnd,
                                                   gatewayInfo);

                if (poolAdd != null)
                {
                    AddressFamily addressFamily = AddressFamily.IPv4;
                    IPAddress     address       = null;
                    var           parts         = subnet.Split('/');
                    var           parsingResult = IPAddress.TryParse(parts[0], out address);
                    if (parsingResult == false || address == null)
                    {
                        ODLVSEMETW.EventWriteArgumentError(
                            MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                            MethodBase.GetCurrentMethod().Name,
                            "The parameter 'subnet' is null or invalid.");
                        throw new ArgumentException("The parameter 'subnet' is invalid.");
                    }
                    switch (address.AddressFamily)
                    {
                    case System.Net.Sockets.AddressFamily.InterNetwork:
                        addressFamily = AddressFamily.IPv4;
                        break;

                    case System.Net.Sockets.AddressFamily.InterNetworkV6:
                        addressFamily = AddressFamily.IPv6;
                        break;

                    default:
                        ODLVSEMETW.EventWriteArgumentError(
                            MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                            MethodBase.GetCurrentMethod().Name,
                            "The parameter 'subnet' is null or invalid.");
                        throw new ArgumentException("The IP address family of subnet is invalid.");
                    }

                    IPSubnet ipsub = null;
                    if (vmNetDef.IPSubnets != null)
                    {
                        ipsub = vmNetDef.IPSubnets.FirstOrDefault(x => x.AddressFamily == addressFamily);
                    }
                    else
                    {
                        vmNetDef.IPSubnets = new IPSubnet[0];
                    }
                    if (ipsub == null)
                    {
                        IPSubnet ipSubnet = new IPSubnet();
                        ipSubnet.Id             = Guid.NewGuid();
                        poolAdd.IPSubnetId      = ipSubnet.Id;
                        ipSubnet.IPAddressPools = new IPAddressPool[] {
                            poolAdd
                        };
                        ipSubnet.AddressFamily         = addressFamily;
                        ipSubnet.LastModifiedTimeStamp = DateTime.Now;
                        ipSubnet.Subnet       = subnet;
                        ipSubnet.SupportsDHCP = true;
                        List <IPSubnet> subnets = vmNetDef.IPSubnets.ToList();
                        subnets.Add(ipSubnet);
                        vmNetDef.IPSubnets = subnets.ToArray();
                    }
                    else
                    {
                        List <IPAddressPool> pools = ipsub.IPAddressPools.ToList();
                        pools.Add(poolAdd);
                        poolAdd.IPSubnetId          = ipsub.Id;
                        ipsub.IPAddressPools        = pools.ToArray();
                        ipsub.LastModifiedTimeStamp = DateTime.Now;
                    }
                    vmNetDef.LastModifiedTimeStamp = DateTime.Now;

                    string error = Validations.IsIPSubnetListValid(
                        vmNetDef.IPSubnets.ToList(), poolAdd.Id);
                    if (!string.IsNullOrEmpty(error))
                    {
                        ODLVSEMETW.EventWriteValidateVMNetDefinitionError(
                            MethodBase.GetCurrentMethod().Name,
                            error);
                        throw new ArgumentException(error);
                    }
                }
            }

            return(poolAdd);
        }
Esempio n. 59
0
 public int GetPackageIPAddressesCount(int packageId, int orgId, IPAddressPool pool, string filterColumn, string filterValue)
 {
     return(packageAddresses.Count);
 }
Esempio n. 60
0
 public PackageIPAddressesPaged GetPackageIPAddresses(int packageId, int orgId, IPAddressPool pool,
     string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows, bool recursive)
 {
     return ServerController.GetPackageIPAddresses(packageId, orgId, pool,
         filterColumn, filterValue, sortColumn, startRow, maximumRows, recursive);
 }