Skip to content

Commit

Permalink
provide subnets ids directly to the tool via argument
Browse files Browse the repository at this point in the history
  • Loading branch information
nikromen committed Oct 3, 2023
1 parent c0f0156 commit 6645ace
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 7 additions & 3 deletions resalloc_ibm_cloud/argparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import argparse


def default_arg_parser():
"""
The part that every resalloc-ibm-cloud utility needs
Expand Down Expand Up @@ -45,10 +46,13 @@ def vm_arg_parser():
"--no-floating-ip", action="store_true", help="Don't use floating IPs (for VPN)"
)
parser_create.add_argument(
"--zones",
"--subnets-ids",
type=str,
nargs="+",
help=(
"Path to json file with zones as keys and subnet id as value."
'content of file will look like: {"jp-tok-1": "secret-subnet-id-123-abcd", ...}'
"Space separated list of subnets ids. In case zones are different than a"
" basic zone, then specify subnet id with zone colon separated like this:"
" zone-1:subnet-id-1 zone-2:subnet-id-2"
),
required=True,
)
Expand Down
12 changes: 3 additions & 9 deletions resalloc_ibm_cloud/ibm_cloud_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""


import json
import logging
import pipes
import os
Expand Down Expand Up @@ -132,8 +131,7 @@ def create_instance(service, instance_name, opts):
"""

log = opts.log
with open(opts.zones, "r", encoding="utf-8") as zone_file:
zones = json.load(zone_file)
zone, subnet_id = _get_zone_and_subnet_id(opts)

instance_prototype_model = {
"keys": [{"id": opts.ssh_key_id}],
Expand All @@ -155,14 +153,14 @@ def create_instance(service, instance_name, opts):
"primary_network_interface": {
"name": "primary-network-interface",
"subnet": {
"id": zones[opts.zone],
"id": subnet_id,
},
"security_groups": [
{"id": opts.security_group_id},
],
},
"zone": {
"name": urlparse(opts.se),
"name": zone,
},
"volume_attachments": [
{
Expand Down Expand Up @@ -344,10 +342,6 @@ def main():
opts.instance = "production" if "-prod-" in name else "devel"

if opts.subparser == "create":
with open(opts.zones, "r", encoding="utf-8") as zone_file:
allowed_zones = list(json.load(zone_file).keys())

opts.zone = random.choice(allowed_zones)
# detect_floating_ip_name(opts)
create_instance(service, name, opts)
elif opts.subparser == "delete":
Expand Down

0 comments on commit 6645ace

Please sign in to comment.