コード例 #1
0
        private void ProfileManager()
        {
            string hostName   = cb.get_option("sourcehostname");
            string entityType = cb.get_option("entitytype");
            string entityName = cb.get_option("entityname");

            try
            {
                hostprofileManager       = cb._connection._sic.hostProfileManager;
                profilecomplianceManager = cb._connection._sic.complianceManager;
                ManagedObjectReference        hostmor       = cb._svcUtil.getEntityByName("HostSystem", hostName);
                ManagedObjectReference        hostProfile   = CreateHostProfile(hostmor, hostName);
                ManagedObjectReference        attachMoref   = cb._svcUtil.getEntityByName(entityType, entityName);
                List <ManagedObjectReference> entityMorList = new List <ManagedObjectReference>();
                entityMorList.Add(attachMoref);
                ManagedObjectReference[] entityList = entityMorList.ToArray();
                AttachProfileWithManagedEntity(hostProfile, entityList);
                PrintProfilesAssociatedWithEntity(attachMoref);

                List <ManagedObjectReference> hpmor = new List <ManagedObjectReference>();
                List <ManagedObjectReference> hamor = new List <ManagedObjectReference>();
                hpmor.Add(hostProfile);
                hamor.Add(attachMoref);
                if (entityType.Equals("HostSystem"))
                {
                    UpdateReferenceHost(hostProfile, attachMoref);
                    HostConfigSpec hostConfigSpec =
                        ExecuteHostProfile(hostProfile, attachMoref);
                    if (hostConfigSpec != null)
                    {
                        ConfigurationTasksToBeAppliedOnHost(hostConfigSpec, attachMoref);
                        if (CheckProfileCompliance(hpmor.ToArray(), hamor.ToArray()))
                        {
                            ApplyConfigurationToHost(attachMoref, hostConfigSpec);
                        }
                    }
                }
                else
                {
                    CheckProfileCompliance(hpmor.ToArray(), hamor.ToArray());
                }
                DetachHostFromProfile(hostProfile, hamor.ToArray());
                DeleteHostProfile(hostProfile);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// Setting the host to maintenance mode and apply the configuration to the host.
        /// </summary>
        /// <param name="attachHostMoref">ManagedObjectReference</param>
        /// <param name="hostConfigSpec">HostConfigSpec</param>
        private void ApplyConfigurationToHost(ManagedObjectReference attachHostMoref,
                                              HostConfigSpec hostConfigSpec)
        {
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine("* Applying Configuration changes or HostProfile to Host");
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine("Putting Host in Maintenance Mode");
            ManagedObjectReference mainmodetask =
                cb._connection._service.EnterMaintenanceMode_Task(attachHostMoref, 0, false, true, null);

            if (mainmodetask != null)
            {
                String status = cb.getServiceUtil().WaitForTask(
                    mainmodetask);
                if (status.Equals("sucess"))
                {
                    Console.WriteLine("Success: Entered Maintenance Mode");
                }
                else
                {
                    throw new Exception(status);
                }
            }
            Console.WriteLine("Applying Profile to Host");
            ManagedObjectReference apphostconftask =
                cb._connection._service.ApplyHostConfig_Task(hostprofileManager, attachHostMoref,
                                                             hostConfigSpec, null);

            if (apphostconftask != null)
            {
                String status = cb.getServiceUtil().WaitForTask(
                    mainmodetask);
                if (status.Equals("sucess"))
                {
                    Console.WriteLine("Success: Apply Configuration to Host");
                }
                else
                {
                    throw new Exception(status);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Generate a list of configuration tasks that will be performed on the host
        ///during HostProfile application.
        /// </summary>
        /// <param name="hostConfigSpec">HostConfigSpec</param>
        /// <param name="attachHostMoref">ManagedObjectReference</param>
        private void ConfigurationTasksToBeAppliedOnHost(HostConfigSpec hostConfigSpec,
                                                         ManagedObjectReference attachHostMoref)
        {
            Console.WriteLine("-------------------------------------------------------");
            Console.WriteLine("* Config Tasks on the Host during HostProfile Application");
            Console.WriteLine("-------------------------------------------------------");
            HostProfileManagerConfigTaskList hostProfileManagerConfigTaskList =
                cb._connection._service.GenerateConfigTaskList(hostprofileManager, hostConfigSpec,
                                                               attachHostMoref);

            LocalizableMessage[] taskMessages =
                hostProfileManagerConfigTaskList.taskDescription;
            if (taskMessages != null)
            {
                foreach (LocalizableMessage taskMessage in taskMessages)
                {
                    Console.WriteLine("Message : " + taskMessage.message);
                }
            }
            else
            {
                Console.WriteLine("There are no configuration changes to be made");
            }
        }
コード例 #4
0
 /// <summary>
 /// Generate a list of configuration tasks that will be performed on the host
 ///during HostProfile application.
 /// </summary>
 /// <param name="hostConfigSpec">HostConfigSpec</param>
 /// <param name="attachHostMoref">ManagedObjectReference</param>
 private void ConfigurationTasksToBeAppliedOnHost(HostConfigSpec hostConfigSpec,
                                                         ManagedObjectReference attachHostMoref)
 {
     Console.WriteLine("-------------------------------------------------------");
     Console.WriteLine("* Config Tasks on the Host during HostProfile Application");
     Console.WriteLine("-------------------------------------------------------");
     HostProfileManagerConfigTaskList hostProfileManagerConfigTaskList =
          cb._connection._service.GenerateConfigTaskList(hostprofileManager, hostConfigSpec,
                 attachHostMoref);
     LocalizableMessage[] taskMessages =
           hostProfileManagerConfigTaskList.taskDescription;
     if (taskMessages != null)
     {
         foreach (LocalizableMessage taskMessage in taskMessages)
         {
             Console.WriteLine("Message : " + taskMessage.message);
         }
     }
     else
     {
         Console.WriteLine("There are no configuration changes to be made");
     }
 }
コード例 #5
0
 /// <summary>
 /// Setting the host to maintenance mode and apply the configuration to the host.
 /// </summary>
 /// <param name="attachHostMoref">ManagedObjectReference</param>
 /// <param name="hostConfigSpec">HostConfigSpec</param>
 private void ApplyConfigurationToHost(ManagedObjectReference attachHostMoref,
                                               HostConfigSpec hostConfigSpec)
 {
     Console.WriteLine("----------------------------------------------------");
     Console.WriteLine("* Applying Configuration changes or HostProfile to Host");
     Console.WriteLine("----------------------------------------------------");
     Console.WriteLine("Putting Host in Maintenance Mode");
     ManagedObjectReference mainmodetask =
           cb._connection._service.EnterMaintenanceMode_Task(attachHostMoref, 0, false, true, null);
     if (mainmodetask != null)
     {
         String status = cb.getServiceUtil().WaitForTask(
               mainmodetask);
         if (status.Equals("sucess"))
         {
             Console.WriteLine("Success: Entered Maintenance Mode");
         }
         else
         {
             throw new Exception(status);
         }
     }
     Console.WriteLine("Applying Profile to Host");
     ManagedObjectReference apphostconftask =
           cb._connection._service.ApplyHostConfig_Task(hostprofileManager, attachHostMoref,
                 hostConfigSpec, null);
     if (apphostconftask != null)
     {
         String status = cb.getServiceUtil().WaitForTask(
               mainmodetask);
         if (status.Equals("sucess"))
         {
             Console.WriteLine("Success: Apply Configuration to Host");
         }
         else
         {
             throw new Exception(status);
         }
     }
 }