zoukankan      html  css  js  c++  java
  • windows auto activate

    目前所支持的windows镜像都是未激活状态,未激活状态下很多功能无法使用。

    以后将要实现的功能是,windows虚机启动后,网络正常后能与KMS服务器通信,自动激活key

    目前想到两种办法:

    1、bat批处理脚本,开启自动运行,利用slmgr激活

    2、cloudbase-init的LocalScriptsPlugin功能,将写好的脚本放在 cloudbaseinit.plugins.common.localscripts目录下

    3、cloudbaseinit.plugins.windows.licensing.WindowsLicensingPlugin插件,该插件在代码里能实现set kms主机,及slmgr直接注入key

    from oslo_log import log as oslo_logging
    from cloudbaseinit import conf as cloudbaseinit_conf
    from cloudbaseinit import constant
    from cloudbaseinit.osutils import factory as osutils_factory
    from cloudbaseinit.plugins.common import base
    from cloudbaseinit.utils.windows import licensing
     
    CONF = cloudbaseinit_conf.CONF
    LOG = oslo_logging.getLogger(__name__)
     
     
    class WindowsLicensingPlugin(base.BasePlugin):
     
        def _set_product_key(self, service, manager):
            if not CONF.set_kms_product_key and not CONF.set_avma_product_key:
                return
     
            description, license_family, is_current = manager.get_kms_product()
            if is_current:
                LOG.info('Product "%s" is already the current one, no need to set '
                         'a product key', description)
            else:
                use_avma = service.get_use_avma_licensing()
                if use_avma is None:
                    use_avma = CONF.set_avma_product_key
                LOG.debug("Use AVMA: %s", use_avma)
     
                product_key = None
                if use_avma:
                    product_key = manager.get_volume_activation_product_key(
                        license_family, constant.VOL_ACT_AVMA)
                    if not product_key:
                        LOG.error("AVMA product key not found for this OS")
     
                if not product_key and CONF.set_kms_product_key:
                    product_key = manager.get_volume_activation_product_key(
                        license_family, constant.VOL_ACT_KMS)
                    if not product_key:
                        LOG.error("KMS product key not found for this OS")
     
                if product_key:
                    LOG.info("Setting product key: %s", product_key)
                    manager.set_product_key(product_key)
     
        def _set_kms_host(self, service, manager):
            kms_host = service.get_kms_host() or CONF.kms_host
            if kms_host:
                LOG.info("Setting KMS host: %s", kms_host)
                manager.set_kms_host(*kms_host.split(':'))
     
        def _activate_windows(self, service, manager):
            if CONF.activate_windows:
                # note(alexpilotti): KMS clients activate themselves
                # so this could be skipped if a KMS host is set
                LOG.info("Activating Windows")
                activation_result = manager.activate_windows()
                LOG.debug("Activation result:
    %s" % activation_result)
     
        def _log_licensing_info(self, manager):
            if CONF.log_licensing_info:
                license_info = manager.get_licensing_info()
                LOG.info('Microsoft Windows license info:
    %s' % license_info)
     
        def execute(self, service, shared_data):
            osutils = osutils_factory.get_os_utils()
     
            if osutils.is_nano_server():
                LOG.info("Licensing info and activation are not available on "
                         "Nano Server")
            else:
                manager = licensing.get_licensing_manager()
     
                eval_end_date = manager.is_eval()
                if eval_end_date:
                    LOG.info("Evaluation license, skipping activation. "
                             "Evaluation end date: %s", eval_end_date)
                else:
                    self._set_product_key(service, manager)
                    self._set_kms_host(service, manager)
                    self._activate_windows(service, manager)
                    manager.refresh_status()
     
                self._log_licensing_info(manager)
     
            return base.PLUGIN_EXECUTION_DONE, False
    cloudbase-init-master.cloudbaseinit.plugins.windows.licensing.py

    cloud-init配置文件,需要开启cloudbaseinit.plugins.windows.licensing.WindowsLicensingPlugin插件,activate_windows=true,check_latest_version=false

    参考:http://cloudbase-init.readthedocs.io/en/latest/plugins.html#winrm-listener-main

  • 相关阅读:
    windows xp查看缩略图时有缩略图没有文件名
    数据库的相关操作
    使用timer控件创建一个简单的报警程序
    xp_sendmail的正确配置与使用
    SQL Server 索引结构及其使用(三)
    启动与关闭服务器
    不间断连续图片滚动效果的制作方法
    使用C#调用外部Ping命令获取网络连接情况
    SQL Server 索引结构及其使用(一)
    winform 与asp.net 下拉列表的区别
  • 原文地址:https://www.cnblogs.com/gushiren/p/9512588.html
Copyright © 2011-2022 走看看