Re: [virt-manager PATCH][v2][RFC] Introduction of cloud-init configuration in virt-install

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/21/19 1:18 PM, Athina Plaskasoviti wrote:
> Triggered by:
> --install is_cloud=yes ... --import
> 
> Signed-off-by: Athina Plaskasoviti <athina.plaskasoviti@xxxxxxxxx>
> ---
>  virt-install                        |  9 ++++---
>  virtinst/cli.py                     |  2 ++
>  virtinst/install/cloudinit.py       | 41 +++++++++++++++++++++++++++++
>  virtinst/install/installer.py       | 16 ++++++++++-
>  virtinst/install/installerinject.py | 20 +++++++-------
>  5 files changed, 75 insertions(+), 13 deletions(-)
>  create mode 100644 virtinst/install/cloudinit.py
> 

So from the other discussion I think a reasonable starting point for
this is to use:

--cloud-init root-password=generate

As the starting point. When that's working well, we can commit it, and
discuss next steps from there, including the ssh options Dan layed out,
and virt-manager discussions.

Use the --unattended in cli.py as a guide. cloudinit.py should have a
small CloudinitData class that's filled in on the command line, then
passed to the installer with set_cloudinit_data, similar to
set_unattended_data. The class will only have a root_password value from
the command line for now.

You can generate a random password in the format we suggested, with:

import random

import string

passwd = ""

for dummy in range(16):

    passwd += random.choice(string.ascii_letters + string.digits)

> diff --git a/virt-install b/virt-install
> index ee2b9006..b3608662 100755
> --- a/virt-install
> +++ b/virt-install
> @@ -399,6 +399,7 @@ def build_installer(options, guest, installdata):
>      install_kernel_args = installdata.kernel_args
>      install_os = installdata.os
>      no_install = installdata.no_install
> +    is_cloud = installdata.is_cloud
>      if installdata.kernel_args:
>          if installdata.kernel_args_overwrite:
>              install_kernel_args = installdata.kernel_args
> @@ -417,10 +418,11 @@ def build_installer(options, guest, installdata):
>              no_install = True
>      elif options.pxe:
>          install_bootdev = "network"
> +    elif options.import_install:
> +        no_install = True
>      elif installdata.is_set:
>          pass
> -    elif (options.import_install or
> -          options.xmlonly or
> +    elif (options.xmlonly or
>            options.boot):
>          no_install = True
>  
> @@ -433,7 +435,8 @@ def build_installer(options, guest, installdata):
>              install_kernel=install_kernel,
>              install_initrd=install_initrd,
>              install_kernel_args=install_kernel_args,
> -            no_install=no_install)
> +            no_install=no_install,
> +            is_cloud=is_cloud)
>  
>      if options.unattended:
>          unattended_data = cli.parse_unattended(options.unattended)
> diff --git a/virtinst/cli.py b/virtinst/cli.py
> index 9a1fe2f6..a2a501a5 100644
> --- a/virtinst/cli.py
> +++ b/virtinst/cli.py
> @@ -1580,6 +1580,7 @@ class ParserInstall(VirtCLIParser):
>                  is_onoff=True)
>          cls.add_arg("os", "os")
>          cls.add_arg("no_install", "no_install", is_onoff=True)
> +        cls.add_arg("is_cloud", "is_cloud", is_onoff=True)
>  
>  
>  class InstallData:
> @@ -1592,6 +1593,7 @@ class InstallData:
>          self.os = None
>          self.is_set = False
>          self.no_install = None
> +        self.is_cloud = None
>  
>  
>  def parse_install(optstr):
> diff --git a/virtinst/install/cloudinit.py b/virtinst/install/cloudinit.py
> new file mode 100644
> index 00000000..25b2a79b
> --- /dev/null
> +++ b/virtinst/install/cloudinit.py
> @@ -0,0 +1,41 @@
> +import tempfile
> +from ..logger import log
> +
> +
> +def create_metadata(scratchdir, hostname=None):
> +    if hostname:
> +        instance = hostname
> +    else:
> +        hostname = instance = "localhost"
> +
> +    fileobj = tempfile.NamedTemporaryFile(
> +            prefix="virtinst-", suffix="-metadata",
> +            dir=scratchdir, delete=False)
> +    filename = fileobj.name
> +
> +    with open(filename, "w") as f:
> +        log.debug("Writing instance-id and hostname to file meta-data")
> +        f.writelines(['instance-id: %s\n' % instance,
> +            'hostname: %s\n' % hostname])
> +    return filename
> +
> +
> +def create_userdata(scratchdir, username=None, password=None):
> +    if not password:
> +        password = "password"
> +
> +    fileobj = tempfile.NamedTemporaryFile(
> +            prefix="virtinst-", suffix="-userdata",
> +            dir=scratchdir, delete=False)
> +    filename = fileobj.name
> +
> +    with open(filename, "w+") as f:
> +        f.write("#cloud-config\n")
> +        if username:
> +            log.debug("Writing username to file user-data")
> +            f.write("name: %s\n" % username)
> +        log.debug("Writing password and cmd for disabling of cloud-init to file user-data")
> +        f.writelines(["password: %s\n" % password,
> +            "chpasswd: { expire: False }\n", "runcmd:\n",
> +            "- [ sudo, touch, /etc/cloud/cloud-init.disabled ]"])
> +    return filename

I'd like to have the content we are going to write to be logged. I
attached a patch that reworks this area a bit to accomplish that.

Also, from my research in the other thread, the meta-data file can be
empty, just write "" to it and it should be fine, though I only tested
with Fedora but from reading the cloud-init code I think it should be
fine for other distros too.

Thanks,
Cole
>From a9019cde033a2abe0b53afcd0e415c76f5f86422 Mon Sep 17 00:00:00 2001
Message-Id: <a9019cde033a2abe0b53afcd0e415c76f5f86422.1561552903.git.crobinso@xxxxxxxxxx>
From: Cole Robinson <crobinso@xxxxxxxxxx>
Date: Mon, 24 Jun 2019 09:47:48 -0400
Subject: [PATCH virt-manager] logging

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 virtinst/install/cloudinit.py | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/virtinst/install/cloudinit.py b/virtinst/install/cloudinit.py
index 25b2a79b..af71550d 100644
--- a/virtinst/install/cloudinit.py
+++ b/virtinst/install/cloudinit.py
@@ -8,15 +8,17 @@ def create_metadata(scratchdir, hostname=None):
     else:
         hostname = instance = "localhost"
 
+    content = 'instance-id: %s\n' % instance
+    content += 'hostname: %s\n' % hostname
+    log.debug("Generated cloud-init metadata:\n%s", content)
+
     fileobj = tempfile.NamedTemporaryFile(
             prefix="virtinst-", suffix="-metadata",
             dir=scratchdir, delete=False)
     filename = fileobj.name
 
     with open(filename, "w") as f:
-        log.debug("Writing instance-id and hostname to file meta-data")
-        f.writelines(['instance-id: %s\n' % instance,
-            'hostname: %s\n' % hostname])
+        f.write(content)
     return filename
 
 
@@ -24,18 +26,20 @@ def create_userdata(scratchdir, username=None, password=None):
     if not password:
         password = "password"
 
+    content = "#cloud-config\n"
+    if username:
+        content += "name: %s\n" % username
+    content += "password: %s\n" % password
+    content += "chpasswd: { expire: False }\n"
+    content += "runcmd:\n"
+    content += "- [ sudo, touch, /etc/cloud/cloud-init.disabled ]"
+    log.debug("Generated cloud-init userdata:\n%s", content)
+
     fileobj = tempfile.NamedTemporaryFile(
             prefix="virtinst-", suffix="-userdata",
             dir=scratchdir, delete=False)
     filename = fileobj.name
 
     with open(filename, "w+") as f:
-        f.write("#cloud-config\n")
-        if username:
-            log.debug("Writing username to file user-data")
-            f.write("name: %s\n" % username)
-        log.debug("Writing password and cmd for disabling of cloud-init to file user-data")
-        f.writelines(["password: %s\n" % password,
-            "chpasswd: { expire: False }\n", "runcmd:\n",
-            "- [ sudo, touch, /etc/cloud/cloud-init.disabled ]"])
+        f.write(content)
     return filename
-- 
2.21.0

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list

[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux