Comprehensive data protection for all workloads
Post Reply
pwjohnston
Novice
Posts: 7
Liked: never
Joined: Mar 18, 2014 3:38 pm
Contact:

Need to set Linux Guest IPs with script

Post by pwjohnston »

Hello,

We’re in a bit of a quandary. Right now we have a Production Center and are trying to set up a DR. We switched to SLES from RedHat because it was included in the vSphere license. Then we got Veeam to do our backup and replication.

Well, Veeam will replicate our VMs, but it will not change the IPs for use in DR because they don’t support that on Linux. One of the guys was nice enough to give me a PowerCLI script

In
http://forums.veeam.com/veeam-backup-re ... ml#p107289
tslighter was kind enough to suggest this PowerCLI script.

$cred = Get-Credential
$interface = Get-VMGuestNetworkInterface -VM lnx01 -GuestCredential ($cred) | ?{ $_.Ip -like "192.168.1.*"}
Set-VMGuestNetworkInterface -VMGuestNetworkInterface $interface -Ip 192.168.2.10 -Netmask 255.255.255.0 -Gateway 192.168.2.1 -GuestCredential $cred


The problem with this is the Get/Set-VMGuestNetworkInterface does not seem to work with SLES or Win2012.

https://www.vmware.com/support/develope ... rface.html

“This cmdlet supports only Windows XP 32 SP3, Windows Server 2003 32bit SP2, Windows Server 2003 64bit SP2, Windows 7 64 bit, Windows Server 2008 R2 64bit and Redhat Enterprise 5 operating systems.”


We have too many machines to do this by hand when we need to fail over to DR. Does anyone have an idea of how I can do this?
tsightler
VP, Product Management
Posts: 6011
Liked: 2843 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Need to set Linux Guest IPs with script

Post by tsightler »

So if Set-VMGuestNetworkInterface doesn't work with SLES then I'd have to suggest writing your own script that uses the VIX API to run a shell script on the hosts. It shouldn't be that hard to create a custom script that makes the changes you need, then push and run those via VIX.

There are some "low-tech" solutions such as adding a secondary IP and gateway that only works at the DR site, or having two NICs, one that's live at the Prod site and another that's live only at the DR site, then you just "disconnect" (either manually or by script) the one that's not used.

You can also attempt to deal with this at the network layer by simply changing routing, but of course that assumes failover of all VMs to the DR site.

How are you planning to deal with DNS changes to point to the new IP's or is this not important in your environment?

Does the solution need to be completely handled external of the guest OS, or can you run scripts within the guest? If so I previously used a really simple script that would ping the default interface, and if it didn't respond assume it was powering on at the DR site and changed the IP. You could even schedule the script to run in cron.

Unfortunately my experience with SLES is limited, but you could also try to modify the Get/Set-VMGuestNetworkInterface helper scripts to work with SLES. These scripts are typically located in C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts and are called as follows:

GetVMGuestNetworkInterface_LinuxGuest
SetVMGuestNetworkInterface_LinuxGuest

The scripts are pretty simple, but I can see they are pretty RHEL specific, but the last time I used SLES it used a very similar setup (i.e. network configs in /etc/sysconfig/network/ifcfg-ethX). I'm actually pretty surprised that it doesn't just work even though it specifically says what versions it supported. I just ran it against a RHEL6 host I have in my lab and it still works even though that version is not specifically listed.
pwjohnston
Novice
Posts: 7
Liked: never
Joined: Mar 18, 2014 3:38 pm
Contact:

Re: Need to set Linux Guest IPs with script

Post by pwjohnston »

>How are you planning to deal with DNS changes to point to the new IP's or is this not important in your environment?
I'm not sure yet, but what I think we're doing is having DNS in both Prod and DR. Then all the machines will have DNS for both, but I'm sure that

>Does the solution need to be completely handled external of the guest OS, or can you run scripts within the guest?
Yeah, the Sr Admins did not like the idea of having anything in the rc.local of the Prod machines for fear that they might not come up right after a reboot. They want it hands off. The two nics is actually a really good idea too. I'll keep that one in mind.

What do you think about Invoke-VMScript?

https://www.vmware.com/support/develope ... cript.html

I was thinking the thing that would make them most comfortable since they're all Linux people would be sticking with Bash (or they prefer Perl which I have no experience in.) But if I could come up with something that would write the address and not just using the ifconfig which would disappear after a reboot they would probably really love that.

Thanks again tsightler!
tsightler
VP, Product Management
Posts: 6011
Liked: 2843 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Need to set Linux Guest IPs with script

Post by tsightler »

Invoke-VMscript will certainly work to run a script on the guest, so if you had a script that worked you'd be good.

Effectively this is all Set-VMGuestNetworkInterface is doing anyway, taking some parameters, pushing the bash scripts that I listed to the host via VIX, then running the scripts with the parameters. It'd be easy enough to reproduce this and perhaps simplify it by having the script already staged. I believe that SuSE still keeps all of it's networking config in /etc/sysconfig/network so one option could be to just have /etc/sysconfig/network-prod and /etc/sysconfig/network-dr and have a script that does nothing but change the symbolic link from one to the other (or just copy them to /etc/sysconfig/network, whichever method you prefer). Then you could just run the "DR" script via Invoke-VMscript. Based on your specific setup you might need to change /etc/resolv.conf, but once again really easy, just have resolv.conf.dr and have the script copy it.

https://www.suse.com/documentation/sles ... nconf.html

It feels like it would be pretty easy.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Paul.Loewenkamp and 119 guests