[virt-tools-list] [virt-manager PATCH] cloudinit: Add disable=yes|no

Cole Robinson crobinso at redhat.com
Wed Jul 3 18:05:10 UTC 2019


On 7/3/19 2:06 AM, Athina Plaskasoviti wrote:
> Cli option to permanently disable cloud-init after first boot by user request.
> Handled so that bare --cloud-init defaults to --cloud-init root-password=generate,disable=yes.
> 

Text here is quite long. Please keep lines to max 72 chars, that's the
git convention

> Signed-off-by: Athina Plaskasoviti <athina.plaskasoviti at gmail.com>
> ---
>  virtinst/cli.py               | 4 +++-
>  virtinst/install/cloudinit.py | 7 +++++--
>  2 files changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/virtinst/cli.py b/virtinst/cli.py
> index caa12289..c080dfcf 100644
> --- a/virtinst/cli.py
> +++ b/virtinst/cli.py
> @@ -1614,14 +1614,16 @@ class ParserCloudInit(VirtCLIParser):
>      def _init_class(cls, **kwargs):
>          VirtCLIParser._init_class(**kwargs)
>          cls.add_arg("root-password", "root_password")
> +        cls.add_arg("disable", "disable", is_onoff=True)
>  
>  
>  def parse_cloud_init(optstr):
>      ret = CloudInitData()
>      if optstr == 1:
>          # This means bare --cloud-init, so there's nothing to parse.
> -        log.warning("Defaulting to --cloud-init root-password=generate")
> +        log.warning("Defaulting to --cloud-init root-password=generate,disable=yes")
>          ret.root_password = "generate"
> +        ret.disable = True
>          return ret
>  
>      parser = ParserCloudInit(optstr)
> diff --git a/virtinst/install/cloudinit.py b/virtinst/install/cloudinit.py
> index 8041cc86..032d65e4 100644
> --- a/virtinst/install/cloudinit.py
> +++ b/virtinst/install/cloudinit.py
> @@ -6,6 +6,7 @@ from ..logger import log
>  
>  
>  class CloudInitData():
> +    disable = None
>      root_password = None
>  
>  
> @@ -40,8 +41,10 @@ def create_userdata(scratchdir, cloudinit_data):
>          content += "    root:%s\n" % rootpass
>          content += "  expire: True\n"
>  
> -    content += "runcmd:\n"
> -    content += "- [ sudo, touch, /etc/cloud/cloud-init.disabled ]\n"
> +    disable = cloudinit_data.disable
> +    if disable is True:
> +        content += "runcmd:\n"
> +        content += "- [ sudo, touch, /etc/cloud/cloud-init.disabled ]\n"

This can be simplified to just:

if cloudinit_data.disable:
    ....

I fixed that and pushed it to the cloudinit branch

Thanks,
Cole




More information about the virt-tools-list mailing list