diff --git a/openappstack/__main__.py b/openappstack/__main__.py index c9c6f32f3f30e272d071b3cf7dd5fe81b61de546..3369a99a39640d06081b60a30ba388f784365184 100755 --- a/openappstack/__main__.py +++ b/openappstack/__main__.py @@ -64,6 +64,11 @@ def main(): # pylint: disable=too-many-statements,too-many-branches,too-many-lo 'domain', metavar='DOMAIN_NAME', help='Domain name to run OpenAppStack under') + create_parser.add_argument( + '--hostname', + type=str, + help='hostname of the machine. If not provided for a new machine, a ' + 'hostname is generated.') group = create_parser.add_mutually_exclusive_group(required=True) @@ -76,14 +81,15 @@ def main(): # pylint: disable=too-many-statements,too-many-branches,too-many-lo metavar='ID', type=int, help='ID of existing Greenhost VPS to use') + group.add_argument( + '--ip-address', + metavar='IP', + help='IP address of non-greenhost VPS to use. You *must* provide ' + '--hostname with this argument') droplet_creation_group = create_parser.add_argument_group( 'droplet creation', 'When using --create-droplet, you need to provide:') - droplet_creation_group.add_argument( - '--hostname', - type=str, - help='hostname of the new machine. If not provided, a hostname is generated') droplet_creation_group.add_argument( '--ssh-key-id', @@ -239,6 +245,11 @@ def create(clus, args): cosmos.wait_for_ssh(clus.ip_address) elif args.droplet_id: clus.set_info_by_droplet_id(args.droplet_id) + elif args.ip_address: + if not args.hostname: + log.error('--hostname required when using --ip-address') + sys.exit(2) + clus.set_info_by_ip_and_hostname(args.ip_address, args.hostname) # Write inventory.yml and settings.yml files clus.write_cluster_files() diff --git a/openappstack/cluster.py b/openappstack/cluster.py index 0b6b91dc1aa2435d7f1fe5ec0ce8cde4f6dfbd08..51928fbf3be210b5f4ccbe452101bd5c1b90e9b1 100644 --- a/openappstack/cluster.py +++ b/openappstack/cluster.py @@ -114,6 +114,10 @@ class Cluster: self.ip_address = droplet['networks']['v4'][0]['ip_address'] self.hostname = droplet['name'] + def set_info_by_ip_and_hostname(self, ip_address, hostname): + self.ip_address = ip_address + self.hostname = hostname + def write_cluster_files(self): """Creates an inventory.yml and settings.yml file for the cluster""" self.make_cluster_directory()