mirror of
https://github.com/ansible/awx.git
synced 2026-05-06 17:07:36 -02:30
Begin changing Import to work with the structure created by Export
This commit is contained in:
@@ -179,11 +179,12 @@ class Import(CustomCommand):
|
|||||||
name = 'import'
|
name = 'import'
|
||||||
help_text = 'import resources into Tower'
|
help_text = 'import resources into Tower'
|
||||||
|
|
||||||
def create_resource(self, client, resource, asset):
|
def create_assets(self, resource, assets):
|
||||||
api_resource = getattr(client.v2, resource)
|
endpoint = getattr(self.v2, resource)
|
||||||
if resource == 'users' and 'password' not in asset:
|
for asset in assets:
|
||||||
asset['password'] = 'password'
|
if resource == 'users' and 'password' not in asset:
|
||||||
api_resource.post(asset)
|
asset['password'] = 'password'
|
||||||
|
endpoint.post({k: v for k, v in asset.items() if k != 'related'})
|
||||||
|
|
||||||
def handle(self, client, parser):
|
def handle(self, client, parser):
|
||||||
if client.help:
|
if client.help:
|
||||||
@@ -192,10 +193,10 @@ class Import(CustomCommand):
|
|||||||
|
|
||||||
data = json.load(sys.stdin)
|
data = json.load(sys.stdin)
|
||||||
client.authenticate()
|
client.authenticate()
|
||||||
|
self.v2 = client.v2
|
||||||
|
|
||||||
for resource, assets in data.items():
|
for resource, assets in data.items(): # FIXME: do a topological sort by dependencies
|
||||||
for asset in assets:
|
self.create_assets(resource, assets)
|
||||||
self.create_resource(client, resource, asset)
|
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user