Skip to content

Commit b755e80

Browse files
dulekEmilienM
authored andcommitted
Allow providing arbitrary dir
dsal-helper generates configs somewhere. Now that's it's a package it makes sense to be able to specify where. By default that's current dir.
1 parent 3a4f8cd commit b755e80

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

tools/dsal/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ dsal-helper anaconda-cfg --disks sda,sdb --boot-disk sda <hostname>
2323

2424
The file will get created as `anaconda/anaconda-ks-<hostname>`.
2525

26+
Note that you can manipulate base directory where the files are created using
27+
`--dir` option.
28+
2629
### Cloning and configuring dev-install
2730

2831
```
@@ -68,6 +71,7 @@ form of `4.x`, e.g. `get-latest.sh 4.9`. The binary will be placed in a
6871
directory named with the nightly version.
6972

7073
## TODOs
74+
* Dehardcode SSH keys from anaconda template.
7175
* Supporting anything else than 8.4 and 16.2.
7276
* Automating other useful activities:
7377
* Downloading openshift-install.

tools/dsal/dsal_helper/dsal_helper.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def __init__(self):
2929
self.app_dir = os.path.dirname(os.path.realpath(__file__))
3030

3131
parser = self._get_arg_parser()
32-
args = parser.parse_args()
32+
self.args = parser.parse_args()
3333
self._setup_jinja()
34-
if hasattr(args, 'func'):
34+
if hasattr(self.args, 'func'):
3535
try:
36-
self._setup_openstack(args.cloud)
36+
self._setup_openstack()
3737
except:
3838
pass
39-
args.func(args)
39+
self.args.func(self.args)
4040
return
4141

4242
parser.print_help()
@@ -51,7 +51,11 @@ def _get_arg_parser(self):
5151
description="Helper for deploying dev-install on DSAL boxes")
5252
parser.add_argument('-c', '--cloud',
5353
default=os.environ.get('OS_CLOUD'),
54-
help='name in clouds.yaml to use')
54+
help='name in clouds.yaml to use, defaults to '
55+
'OS_CLOUD envvar')
56+
parser.add_argument('-d', '--dir', default='',
57+
help='directory where to place generated configs, '
58+
'defaults to working dir')
5559

5660
subparsers = parser.add_subparsers(help='supported commands')
5761

@@ -122,18 +126,20 @@ def _get_arg_parser(self):
122126

123127
return parser
124128

125-
def _setup_openstack(self, cloud_name):
126-
conn = openstack.connection.from_config(cloud=cloud_name)
129+
def _setup_openstack(self):
130+
conn = openstack.connection.from_config(cloud=self.args.cloud)
127131
self.os = conn
128132
self.neutron = conn.network
129133

130134
def _create_dir(self, directory):
131-
pathlib.Path(directory).mkdir(exist_ok=True, parents=True)
135+
path = pathlib.Path(self.args.dir, directory)
136+
path.mkdir(exist_ok=True, parents=True)
137+
return str(path)
132138

133139
def _render(self, directory, template_file, file, vars):
134-
self._create_dir(directory)
140+
directory = self._create_dir(directory)
135141
template = self.jinja.get_template(template_file)
136-
with open(f'{directory}/{file}', 'w') as f:
142+
with open(os.path.join(directory, file), 'w') as f:
137143
print(template.render(**vars), file=f)
138144

139145
def anaconda_cfg(self, args):

0 commit comments

Comments
 (0)