/// <summary>
 /// Update device details for specified device given the specified data
 /// </summary>
 /// <param name="deviceDetails">Current device details for the device.</param>
 /// <param name="newName">New friendly name for the device. Null if its not to be changed</param>
 /// <param name="timeZone">New timeZone value for the device. Null if its not to be changed</param>
 /// <param name="secondaryDnsServer">New Secondary DNS Server address for the device. Null if its not to be changed</param>
 /// <param name="networkConfigs">An array or NetworkConfig objects for different interfaces. Null if its not to be changed</param>
 /// <returns></returns>
 public TaskStatusInfo UpdateDeviceDetails(DeviceDetails deviceDetails, string newName, TimeZoneInfo timeZone, IPAddress secondaryDnsServer, NetworkConfig[] networkConfigs)
 {
     // Update the object
     this.UpdateDeviceDetailsObject(deviceDetails, newName, timeZone, secondaryDnsServer, networkConfigs);
     // Copy stuff over from the DeviceDetails object into a new DeviceDetailsRequest object.
     var request = new DeviceDetailsRequest();
     MiscUtils.CopyProperties(deviceDetails, request);
     var taskStatusInfo = this.GetStorSimpleClient().DeviceDetails.UpdateDeviceDetails(request, this.GetCustomRequestHeaders());
     return taskStatusInfo;
 }
Esempio n. 2
0
        /// <summary>
        /// Update the specified DeviceDetails object with given network config data
        /// </summary>
        /// <param name="details">DeviceDetails object to be updated</param>
        /// <param name="netConfig">network config object to pick new details from</param>
        private void UpdateDeviceDetailsWithNetworkConfig(DeviceDetails details, NetworkConfig netConfig)
        {
            // See if deviceDetails already has an object for the interface for which network config has been provided.
            // If not, then a new object is to be provided.
            var netInterface = details.NetInterfaceList.FirstOrDefault(x => x.InterfaceId == netConfig.InterfaceAlias);

            if (netInterface == null)
            {
                netInterface = new NetInterface
                {
                    NicIPv4Settings = new NicIPv4(),
                    NicIPv6Settings = new NicIPv6()
                };
                details.NetInterfaceList.Add(netInterface);
            }

            netInterface.IsIScsiEnabled = netConfig.IsIscsiEnabled.HasValue ? netConfig.IsIscsiEnabled.Value : netInterface.IsIScsiEnabled;

            netInterface.IsCloudEnabled = netConfig.IsCloudEnabled.HasValue ? netConfig.IsCloudEnabled.Value : netInterface.IsCloudEnabled;

            if (netConfig.InterfaceAlias == NetInterfaceId.Data0)
            {   // Other interfaces are not supposed to have controller IPs
                if (netConfig.Controller0IPv4Address != null)
                {
                    netInterface.NicIPv4Settings.Controller0IPv4Address = netConfig.Controller0IPv4Address.ToString();
                }
                if (netConfig.Controller1IPv4Address != null)
                {
                    netInterface.NicIPv4Settings.Controller1IPv4Address = netConfig.Controller1IPv4Address.ToString();
                }
            }
            if (netConfig.IPv4Gateway != null)
            {
                netInterface.NicIPv4Settings.IPv4Gateway = netConfig.IPv4Gateway.ToString();
            }
            if (netConfig.IPv4Address != null)
            {
                netInterface.NicIPv4Settings.IPv4Address = netConfig.IPv4Address.ToString();
            }
            if (netConfig.IPv4Netmask != null)
            {
                netInterface.NicIPv4Settings.IPv4Netmask = netConfig.IPv4Netmask.ToString();
            }
            if (netConfig.IPv6Prefix != null)
            {
                netInterface.NicIPv6Settings.IPv6Prefix = netConfig.IPv6Prefix.ToString();
            }
            if (netConfig.IPv6Gateway != null)
            {
                netInterface.NicIPv6Settings.IPv6Gateway = netConfig.IPv6Gateway.ToString();
            }

            // Make sure that the interface gets enabled as well
            netInterface.IsEnabled = true;
        }
        /// <summary>
        /// Validate that all mandatory data for the first Device Configuration has been provided.
        /// </summary>
        /// <returns>bool indicating whether all mandatory data is there or not.</returns>
        internal bool ValidParamsForFirstDeviceConfiguration(NetworkConfig[] netConfigs, TimeZoneInfo timeZone, string secondaryDnsServer)
        {
            if (netConfigs == null)
            {
                return false;
            }
            // Make sure network config for Data0 has been provided with atleast Controller0 IP Address
            var data0 = netConfigs.FirstOrDefault(x => x.InterfaceAlias == NetInterfaceId.Data0);
            if (data0 == null || data0.Controller0IPv4Address == null || data0.Controller1IPv4Address == null)
            {
                return false;
            }
            // Timezone is also mandatory
            if (timeZone == null || secondaryDnsServer == null)
            {
                return false;
            }

            // There must be atleast one iscsi enabled net interface in the first config
            var iscsiEnabledInterfacePresent = netConfigs.Any(x => x.IsIscsiEnabled == true);
            if (!iscsiEnabledInterfacePresent)
            {
                return false;
            }

            return true;
        }
 /// <summary>
 /// Validate that all network configs are valid.
 /// 
 /// Its mandatory to provide either (IPv4 Address and netmask) or IPv6 orefix for an interface that
 /// is being enabled. ( Was previously disabled and is now being configured)
 /// </summary>
 internal void ValidateNetworkConfigs(DeviceDetails details, NetworkConfig[] StorSimpleNetworkConfig)
 {
     if (StorSimpleNetworkConfig == null)
     {
         return;
     }
     foreach (var netConfig in StorSimpleNetworkConfig)
     {
         // get corresponding netInterface in device details.
         var netInterface = details.NetInterfaceList.FirstOrDefault(x => x.InterfaceId == netConfig.InterfaceAlias);
         // If its being enabled and its not Data0, it must have IP Address info
         if (netInterface == null || (netInterface.InterfaceId != NetInterfaceId.Data0 && !netInterface.IsEnabled))
         {
             // If its not an enabled interface either IPv6(prefix) or IPv4(address and mask) must be provided.
             if ((netConfig.IPv4Address == null || netConfig.IPv4Netmask == null) && netConfig.IPv6Prefix == null)
             {
                 throw new ArgumentException(string.Format(Resources.IPAddressesNotProvidedForNetInterfaceBeingEnabled, StorSimpleContext.ResourceName, details.DeviceProperties.DeviceId));
             }
         }
     }
 }
        /// <summary>
        /// Modify the provided DeviceDetails object with the data provided
        /// </summary>
        /// <param name="details"></param>
        private void UpdateDeviceDetailsObject(DeviceDetails deviceDetails, string newName, TimeZoneInfo timeZone, IPAddress secondaryDnsServer, NetworkConfig[] networkConfigs)
        {
            // modify details for non-null data provided to cmdlet

            if (!string.IsNullOrEmpty(newName))
            {
                deviceDetails.DeviceProperties.FriendlyName = newName;
            }

            if (timeZone != null)
            {
                deviceDetails.TimeServer.TimeZone = timeZone.StandardName;
            }

            if (secondaryDnsServer != null)
            {
                var secondaryDnsString = secondaryDnsServer.ToString();
                var secondaryDnsType = secondaryDnsServer.AddressFamily;
                if (secondaryDnsType == AddressFamily.InterNetwork)   // IPv4
                {
                    deviceDetails.DnsServer.SecondaryIPv4.Clear();
                    deviceDetails.DnsServer.SecondaryIPv4.Add(secondaryDnsString);
                }
                else if (secondaryDnsType == AddressFamily.InterNetworkV6)
                {
                    deviceDetails.DnsServer.SecondaryIPv6.Clear();
                    deviceDetails.DnsServer.SecondaryIPv6.Add(secondaryDnsString);
                }
            }

            if (networkConfigs != null && networkConfigs.Count()  > 0)
            {
                foreach (var netConfig in networkConfigs)
                {
                    this.UpdateDeviceDetailsWithNetworkConfig(deviceDetails, netConfig);
                }
            }

            // There are a bunch of details that this cmdlet never edits and the service 
            // considers null values for them to mean that there have been no changes.
            deviceDetails.AlertNotification = null;
            deviceDetails.Chap = null;
            deviceDetails.RemoteMgmtSettingsInfo = null;
            deviceDetails.RemoteMinishellSecretInfo = null;
            deviceDetails.SecretEncryptionCertThumbprint = null;
            deviceDetails.Snapshot = null;
            deviceDetails.VirtualApplianceProperties = null;
            deviceDetails.WebProxy = null;
        }
        /// <summary>
        /// Update the specified DeviceDetails object with given network config data
        /// </summary>
        /// <param name="details">DeviceDetails object to be updated</param>
        /// <param name="netConfig">network config object to pick new details from</param>
        private void UpdateDeviceDetailsWithNetworkConfig(DeviceDetails details, NetworkConfig netConfig)
        {
            // See if deviceDetails already has an object for the interface for which network config has been provided.
            // If not, then a new object is to be provided.
            var netInterface = details.NetInterfaceList.FirstOrDefault(x => x.InterfaceId == netConfig.InterfaceAlias);
            if (netInterface == null)
            {
                netInterface = new NetInterface
                {
                    NicIPv4Settings = new NicIPv4(),
                    NicIPv6Settings = new NicIPv6()
                };
                details.NetInterfaceList.Add(netInterface);
            }

            netInterface.IsIScsiEnabled = netConfig.IsIscsiEnabled.HasValue ? netConfig.IsIscsiEnabled.Value : netInterface.IsIScsiEnabled;

            netInterface.IsCloudEnabled = netConfig.IsCloudEnabled.HasValue ? netConfig.IsCloudEnabled.Value : netInterface.IsCloudEnabled;

            if (netConfig.InterfaceAlias == NetInterfaceId.Data0)
            {   // Other interfaces are not supposed to have controller IPs
                if (netConfig.Controller0IPv4Address != null)
                {
                    netInterface.NicIPv4Settings.Controller0IPv4Address = netConfig.Controller0IPv4Address.ToString();
                }
                if (netConfig.Controller1IPv4Address != null)
                {
                    netInterface.NicIPv4Settings.Controller1IPv4Address = netConfig.Controller1IPv4Address.ToString();
                }
            }
            if (netConfig.IPv4Gateway != null)
            {
                netInterface.NicIPv4Settings.IPv4Gateway = netConfig.IPv4Gateway.ToString();
            }
            if (netConfig.IPv4Address != null)
            {
                netInterface.NicIPv4Settings.IPv4Address = netConfig.IPv4Address.ToString();
            }
            if (netConfig.IPv4Netmask != null)
            {
                netInterface.NicIPv4Settings.IPv4Netmask = netConfig.IPv4Netmask.ToString();
            }
            if (netConfig.IPv6Prefix != null)
            {
                netInterface.NicIPv6Settings.IPv6Prefix = netConfig.IPv6Prefix.ToString();
            }
            if (netConfig.IPv6Gateway != null)
            {
                netInterface.NicIPv6Settings.IPv6Gateway = netConfig.IPv6Gateway.ToString();
            }

            // Make sure that the interface gets enabled as well
            netInterface.IsEnabled = true;
        }