Пример #1
0
        public static string GetPublicIPName(Microsoft.WindowsAzure.Management.Compute.Models.Role vmRole)
        {
            string name = null;

            if (vmRole != null && vmRole.ConfigurationSets != null && vmRole.ConfigurationSets.Any())
            {
                var networkCfg = vmRole.ConfigurationSets
                                 .Where(c => string.Equals(c.ConfigurationSetType, ConfigurationSetTypes.NetworkConfiguration, StringComparison.OrdinalIgnoreCase))
                                 .SingleOrDefault();

                if (networkCfg != null)
                {
                    var publicIp = networkCfg.PublicIPs.FirstOrDefault();
                    name = publicIp == null ? null : publicIp.Name;
                }
            }

            return(name);
        }
Пример #2
0
        //*********************************************************************
        ///
        ///  <summary>
        ///
        ///  </summary>
        ///  <param name="vm"></param>
        /// <param name="spa"></param>
        /// <param name="vmDepReqs"></param>
        ///
        //*********************************************************************
        private void ProcessFoundVm(
            Microsoft.WindowsAzure.Management.Compute.Models.Role vm,
            Models.ServiceProviderAccount spa, IEnumerable <VmDeploymentRequest> vmDepReqs)
        {
            //*** Look for VM in list of VmDepReqs, leave if found
            if (vmDepReqs.Any(vdr => vdr.TargetVmName.Equals(vm.RoleName,
                                                             StringComparison.InvariantCultureIgnoreCase)))
            {
                return;
            }

            //*** VM not found, so add to VmDepReq DB table
            var utcNow = DateTime.UtcNow;

            //*** TODO * Build as much actual config as possible here
            var config =
                @"<?xml version=""1.0"" encoding=""utf-8""?><VmConfig xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""></VmConfig>";

            var vdb = new Models.VmDeploymentRequest()
            {
                Active                = true,
                AftsID                = 0,
                Config                = config,
                ConfigOriginal        = config,
                CurrentStateStartTime = utcNow,
                CurrentStateTryCount  = 0,
                ExceptionMessage      = null,
                ExceptionTypeCode     = null,
                ID = 0,
                LastStatusUpdate              = utcNow,
                LastState                     = CmpInterfaceModel.Constants.StatusEnum.Complete.ToString(),
                OverwriteExisting             = false,
                ParentAppID                   = "",
                ParentAppName                 = "",
                RequestDescription            = "SyncVm:" + vm.RoleName,
                RequestName                   = "SyncVm:" + vm.RoleName,
                RequestType                   = CmpInterfaceModel.Constants.RequestTypeEnum.SyncVm.ToString(),
                ServiceProviderAccountID      = spa.ID,
                ServiceProviderResourceGroup  = null,
                ServiceProviderStatusCheckTag = null,
                SourceServerName              = null,
                SourceServerRegion            = null,
                SourceVhdFilesCSV             = null,
                StatusCode                    = CmpInterfaceModel.Constants.StatusEnum.Complete.ToString(),
                StatusMessage                 = "Imported from Azure Subscription",
                TagData                   = "<SyncReq></SyncReq>",
                TagID                     = 0,
                TargetAccount             = spa.AccountID,
                TargetAccountCreds        = null,
                TargetAccountType         = CmpInterfaceModel.Constants.TargetAccountTypeEnum.AzureSubscription.ToString(),
                TargetLocation            = null,
                TargetLocationType        = null,
                TargetServicename         = vm.Label,
                TargetServiceProviderType = CmpInterfaceModel.Constants.TargetServiceProviderTypeEnum.Azure.ToString(),
                TargetVmName              = vm.RoleName,
                ValidationResults         = null,
                VmSize                    = vm.RoleSize,
                WhenRequested             = utcNow,
                WhoRequested              = "CmpWorkerService"
            };

            _cdb.InsertVmDepRequest(vdb);
        }