예제 #1
0
        //*********************************************************************
        ///
        ///  <summary>
        ///
        ///  </summary>
        /// <param name="spa"></param>
        /// <param name="vmDepReqs"></param>
        ///
        //*********************************************************************

        //*** NOTE * Network

        private void ProcessSub(Models.ServiceProviderAccount spa,
                                List <Models.VmDeploymentRequest> vmDepReqs, IEnumerable <AzureResourceGroup> aRGs)
        {
            try
            {
                var servOps = new HostedServiceOps(new Connection(
                                                       spa.AccountID, spa.CertificateThumbprint,
                                                       spa.AzureADTenantId, spa.AzureADClientId, spa.AzureADClientKey));

                var rgList = servOps.FetchResourceGroupList();

                foreach (var rg in rgList)
                {
                    ProcessFoundRg(rg, spa, aRGs, servOps);
                }

                var vmOps = new VmOps(new Connection(
                                          spa.AccountID, spa.CertificateThumbprint,
                                          spa.AzureADTenantId, spa.AzureADClientId, spa.AzureADClientKey));

                var vmList = vmOps.FetchVmList();

                foreach (var vm in vmList)
                {
                    ProcessFoundVm(vm, spa, vmDepReqs);
                }

                //LogThis(EventLogEntryType.Information, "VmOp Request Submitted OK", 2, 2);
            }
            catch (Exception ex)
            {
                LogThis(ex, EventLogEntryType.Error, "CmpWapExtension.ProcessorSyncSubs.ProcessSub()", 100, 1);
            }
        }
예제 #2
0
        //*********************************************************************
        ///
        ///  <summary>
        ///
        ///  </summary>
        ///  <param name="arg"></param>
        ///  <param name="spa"></param>
        ///  <param name="aRGs"></param>
        /// <param name="hso"></param>
        ///
        //*********************************************************************
        private void ProcessFoundRg(AzureResourceGroup arg, Models.ServiceProviderAccount spa,
                                    IEnumerable <AzureResourceGroup> aRGs, HostedServiceOps hso)
        {
            //*** Look for RG in list of aRGs, leave if found
            if (aRGs.Any(vdr => vdr.Name.Equals(arg.Name,
                                                StringComparison.InvariantCultureIgnoreCase)))
            {
                return;
            }

            //var rg = hso.GetResourceGroup(arg.Name);

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

            var vdb = new Models.Container()
            {
                //ID = 0,
                Name           = arg.Name,
                Region         = arg.Location,
                SubscriptionId = spa.AccountID,
                CIOwner        = "",
                Code           = "",
                Config         = "",
                CreatedBy      = "",
                CreatedOn      = utcNow,
                HasService     = false,
                IsActive       = true,
                LastUpdatedBy  = "",
                LastUpdatedOn  =
                    utcNow,
                Path = arg.Id,
                Type = CmpInterfaceModel.Constants.ContainerTypeEnum.ResourceGroup.ToString()
            };

            _cdb.InsertAzureContainer(vdb);
        }
예제 #3
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);
        }