Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the --dhcp option to the clone subcommand #8

Closed
wants to merge 12 commits into from
Closed

Add the --dhcp option to the clone subcommand #8

wants to merge 12 commits into from

Conversation

jctanner
Copy link

@jctanner jctanner commented Aug 7, 2014

Addresses #3
This is my first foray into the vsphere api objects, so I did a bit of shooting in the dark on how to accomplish DHCP. Please let me know what you would like revised in this patch and I would be happy to do so.

  1. Should passing IPs in the arguments override the --dhcp option or vice versa?
  2. Should multiple nics with both static and DHCP be allowed?

James Tanner added 2 commits August 7, 2014 13:04
@jctanner
Copy link
Author

jctanner commented Aug 7, 2014

The second commit adds a convenient way to wait until the dhcp address is obtained. That makes it a lot easier on orchestration tools like ansible to use ezmomi to provision new virtual machines.

I copied the code for finding all VMs and I really suspect there is a more optimized call to fetch a single one, so any guidance would be appreciated.

@snobear
Copy link
Owner

snobear commented Aug 11, 2014

Thanks @jctanner. I'm thrilled to have another contributor!

  1. Yes, it makes sense to me that --ips should override --dhcp. If neither one is specified, it should default to dhcp. Currently, it complains if --ips isn't specified, so please set required=False on the ips param.

  2. I like the flexibility of multiple NICs with both static and dhcp IPs, but let's hold off on that. For now we'll only support one or the other. We can revisit in another pull request, just to keep the PRs smaller and easier to review and test.

A few other things...

  • it fails if waitforips is not specified. Looks like you intended for False as default, but argparse doesn't seem to be setting a default for it? Or maybe its when it tries to be set in self.config.
ezmomi clone --dhcp --hostname jtest01 --ips 172.22.31.230 --folder /
Cloning centos65.btp to new host jtest01...
Traceback (most recent call last):
  File "/home/snobear/ezmomi/bin/ezmomi", line 4, in <module>
    cli.cli()
  File "/home/snobear/ezmomi/lib/python2.6/site-packages/ezmomi/cli.py", line 31, in cli
    ez.clone()
  File "/home/snobear/ezmomi/lib/python2.6/site-packages/ezmomi/ezmomi.py", line 297, in clone
    if self.config['waitforip']:
KeyError: 'waitforip'
  • can you have --folder be optional? It could default to the root folder (which I lazily use for everything). I believe the root dir in vSphere is just /, but may want to check.

For me it seems to never get a dhcp ip. The VM boots up, but the NIC, hostname, etc.. isn't configured on the linux side. The adapter is created on the VMWare side though. I need to look at logs and what not - could be a difference in how our templates are... feel free to address the above points in the meantime.

@v1gnesh
Copy link

v1gnesh commented Aug 11, 2014

@jctanner, @snobear

For point number 2, do you mean 2 NIC's where one is static and the other is DHCP-based?

@jctanner
Copy link
Author

@v1gnesh that would be one scenario, yes.

@jctanner
Copy link
Author

@snobear

  • I got a bit too greedy and ended up adding --count (70c2303)
  • --folder is now optional and the default is to /.
  • waitforip traceback fixed

As to your VM not getting an IP on boot ...

  1. Was there a NIC attached to the template?
  2. Is there a NIC in the dmesg output on linux?
  3. Is there something other than "lo" in the "ifconfig -a" output?
  4. What OS + version?

@snobear
Copy link
Owner

snobear commented Aug 13, 2014

Sounds good on the points.

Per my dhcp issue:

  1. Yes
  2. Yes. dmesg | grep eth shows vmxnet3 eth0: NIC Link is up 10000 Mbps.
  3. Yes, I see eth0 in ifconfig -a.
  4. CentOS 6.5

I don't see /etc/sysconfig/network-scripts/ifcfg-eth0 (only ifcfg-lo). I see a bunch of these in /var/log/messages:

vmsvc [warning] [guestinfo] RecordRoutingInfo: Unable to collect IPv4 routing table

I could be running into this issue. I'll do some more research.

James Tanner added 4 commits August 13, 2014 00:20
@jctanner
Copy link
Author

@snobear any updates?

@snobear
Copy link
Owner

snobear commented Aug 19, 2014

@jctanner Got busy the past week. I'm going to dig into it in a few minutes. Thanks for pinging me on it.

@snobear
Copy link
Owner

snobear commented Aug 19, 2014

@jctanner does your VM template have a network script e.g. ifcfg-eth0 already present? Mine does not. I'd want ezmomi to create them if needed, which is does for static IPs currently.

Pretty sure we need the CustomizationSpec set in order to customize the guest and create the ifcfg-eth* configs. That's vim.vm.customization.Specification() in pyvmomi terms. I see you bypassed this when dhcp is set. It should be pretty straightforward to add.

I can merge your pull request as-is and then add in the ability for dhcp to be customized appropriately on the guest. Or you can tackle it. Thoughts?

@jctanner
Copy link
Author

@snobear yes i had an ifcfg-eth0 and the 70-persistent-net.rules for udev file was cleared out so that the cloned VM's NIC would be assigned to eth0.

If we were to write out ifcfg-eth0, how would that play out for templates that are not RHEL based? I can work on this if you define the workflow you want (preferably not exclusive to RHEL).

What aspects of the customizationspec are needed? This is something I wasn't sure of, so I bypassed it.

@snobear
Copy link
Owner

snobear commented Aug 19, 2014

AFAIK the customization spec is distro-agnostic. vSphere handles customizing the guest's network settings with all the OS particulars done behind the scenes, so we are basically abstracted from it and don't have to think about it. So I'm sure whatever distros are supported by VMWare will be able to have the guest customized.

Basically, you'll need to change FixedIp() to the equivalent DHCP object, which I believe is DhcpIpGenerator() around this line. See docs on that.

Rethinking this some, let's make dhcp operate similar as possible to how static --ips operates.

Workflow:

  • --dhcp should accept any number of args like the static --ips option does, but instead of passing IP addresses, it will accept VMWare network names. Allows people with multiple dhcp-ready networks to specify where the NIC is placed. So, e.g.
ezmomi clone --hostname foo --dhcp MyNetwork MyNetwork OtherNetworkName

would configure three NICs: two in MyNetwork and one in OtherNetworkName. Network settings are defined in config.yml. For now we only support dhcp OR static ips, and not mix both. Make it complain and exit if both are specified on command line.

  • Try and keep the code DRY by using ip_settings list variable and the same loops that ips uses.

As an idea or example, this loop where we get the network settings for each network device:

If static ips, loop over self.config['ips'] field as currently done. Otherwise, loop over the self.config['dhcp'] field. Some of the logic inside the loop will need to change or be conditional.

Just set the ip to 'dhcp' wherever that field is set, e.g. here. That could be your check in the later loop that sets up the custom spec.

This will set it up nicely to support mixed static and dhcp, whenever we add that later.

Hope this is a decent workflow and not too micro-managed. Or macro-managed, if there is such a thing. Let me know if you have any questions.

@sitle
Copy link
Contributor

sitle commented Aug 21, 2014

@jctanner - Hi, can you create a different branch for the folder option please ? I want to test this functionality if you don ´t mind.

@snobear
Copy link
Owner

snobear commented Sep 11, 2014

Hi @jctanner how goes it? Just checking in to see if you're still interested in working on the dhcp thing..

@snobear
Copy link
Owner

snobear commented Jan 8, 2015

@jctanner Are you still interested in finishing this one out?

@snobear
Copy link
Owner

snobear commented Jan 14, 2015

Haven't heard from @jctanner so closing this. I appreciate the PR and will reference your changes when implementing the dhcp feature.

@snobear snobear closed this Jan 14, 2015
@derchrisuk
Copy link

I don't want to create a new issue for this, so I add my comments here.
I'm also looking for a DHCP option.
When I played around with the pyVmomi clone samples, I could get a new cloned VM with DHCP, as my source Template has been configured with DHCP.
Would like to have this option here as well.
At the moment I have to come up with some side part solution for the Fixed IP assignment.
But we have a DHCP pool for our VMs, and would like to use that.
I already modified this one here to get me the IP from a VM once it has been cloned.

@iahmad-khan
Copy link

hi , any update? creating vm from template using dhcp

@derchrisuk
Copy link

If I have some time I can pull out the changes I did on my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants