Created
June 26, 2015 14:48
-
-
Save niedbalski/ffecd47ac9620a1d425a to your computer and use it in GitHub Desktop.
Update a juju machine ip address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to run | |
========== | |
$ sudo pip install jujuclient | |
$ chmod 0755 update-juju-machine-ip.py | |
$ ./update-juju-machine-ip.py machine-0 10.5.0.125 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
from jujuclient import Environment | |
import sys | |
import subprocess | |
class UpdateIP(Environment): | |
def __init__(self, *args, **kwargs): | |
Environment.__init__(self, *args, **kwargs) | |
def set_machine_addresses(self, addresses): | |
if not isinstance(addresses, list): | |
addresses = [addresses] | |
return self._rpc({ | |
'type': "Machiner", | |
'version': 0, | |
'request': "SetMachineAddresses", | |
'params': { | |
'MachineAddresses': addresses, | |
} | |
}) | |
def main(): | |
if not len(sys.argv) > 2: | |
print('Usage: %s machine-0 192.168.1.1' % sys.argv[0], file=sys.stderr) | |
sys.exit(-1) | |
env = UpdateIP.connect(subprocess.check_output(["juju", "env"]).rstrip('\n')) | |
env.set_machine_addresses({ | |
'Tag': sys.argv[1], | |
'Addresses': [ {'Type': "ipv4", 'Value': sys.argv[2], 'Scope': 'public'}], | |
}) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment