Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Podman provider #298

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/mrack/providers/podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async def init(
self,
container_images,
default_network,
network_options,
ssh_key,
container_options,
extra_commands,
Expand All @@ -63,6 +64,7 @@ async def init(
self.max_retry = max_retry
self.images = container_images
self.default_network = default_network
self.network_options = network_options
self.ssh_key = ssh_key
self.podman_options = container_options
self.extra_commands = extra_commands
Expand Down Expand Up @@ -93,7 +95,11 @@ async def prepare_provisioning(self, reqs):
awaitables = []
for network in network_list:
if not await self.podman.network_exists(network):
awaitables.append(self.podman.network_create(network))
awaitables.append(
self.podman.network_create(
network, options=self.network_options
)
)

network_results = await asyncio.gather(*awaitables)
success = all(network_results)
Expand Down Expand Up @@ -173,7 +179,8 @@ async def wait_till_provisioned(self, resource):

while datetime.now() < timeout_time:
try:
server = await self.podman.inspect(cont_id)[0]
servers = await self.podman.inspect(cont_id)
server = servers[0]
dav-pascual marked this conversation as resolved.
Show resolved Hide resolved
except ProvisioningError as err:
logger.error(f"{log_msg_start} {object2json(err)}")
raise ServerNotFoundError(cont_id) from err
Expand Down Expand Up @@ -223,6 +230,22 @@ async def wait_till_provisioned(self, resource):

return server, req

async def _wait_for_ssh(self, host, timeout, port):
log_msg_start = f"{self.dsp_name} [{host}]"
start_ssh = datetime.now()
while True:
res = await self.podman.exec_command(
host._host_id, "systemctl -q is-active sshd"
)
logger.info(f"{log_msg_start} ran is-active for ssh, result '{res}'")
if not res:
await asyncio.sleep(10)
if datetime.now() - start_ssh >= timedelta(seconds=(timeout * 60)):
break
else:
break
return res, host

async def delete_host(self, host_id, host_name):
"""Delete provisioned host."""
# if there is no container we do nothing
Expand Down
4 changes: 3 additions & 1 deletion src/mrack/providers/utils/podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,16 @@ async def network_exists(self, network):
_stdout, _stderr, inspect = await self._run_podman(args, raise_on_err=False)
return inspect.returncode == 0

async def network_create(self, network):
async def network_create(self, network, options=None):
"""Create a podman network if it does not exist."""
if await self.network_exists(network):
logger.debug(f"{self.dsp_name} Network '{network}' is present")
return 0

logger.info(f"{self.dsp_name} Creating podman network '{network}'")
args = ["network", "create", network]
if options:
args.extend(options)
_stdout, _stderr, process = await self._run_podman(args, raise_on_err=False)

return process.returncode == 0
Expand Down
4 changes: 3 additions & 1 deletion src/mrack/transformers/podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class PodmanTransformer(Transformer):
"images",
"pubkey",
"default_network",
"network_options",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO I would remove this line, so the spec is optional, rather than required

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's ok then, as long as podman provisioner works when defining network options.

"podman_options",
]

Expand All @@ -38,8 +39,9 @@ async def init_provider(self):

await self._provider.init(
container_images=self.config["images"].values(),
ssh_key=self.config["pubkey"],
default_network=self.config["default_network"],
network_options=self.config.get("network_options", []),
ssh_key=self.config["pubkey"],
container_options=self.config["podman_options"],
extra_commands=self.config.get("extra_commands", []),
strategy=self.config.get("strategy", STRATEGY_ABORT),
Expand Down