Skip to content

Commit

Permalink
cephadm: podman inspect: image field was called ImageID:
Browse files Browse the repository at this point in the history
See containers/podman#4195

Signed-off-by: Michael Fritch <[email protected]>
  • Loading branch information
mgfritch committed Jan 22, 2020
1 parent 0573918 commit 812d8f0
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions src/cephadm/cephadm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import tempfile
import time
import errno
try:
from typing import Dict, List, Tuple, Optional, Union
from typing import Dict, List, Tuple, Optional, Union, Any
except ImportError:
pass
import uuid
Expand All @@ -70,7 +70,7 @@ if sys.version_info >= (3, 2):
else:
from ConfigParser import SafeConfigParser

container_path = None
container_path = ''

class Error(Exception):
pass
Expand Down Expand Up @@ -373,11 +373,11 @@ class FileLock(object):
##################################
# Popen wrappers, lifted from ceph-volume

def call(command,
desc=None,
verbose=False,
verbose_on_failure=True,
timeout=DEFAULT_TIMEOUT,
def call(command, # type: List[str]
desc=None, # type: Optional[str]
verbose=False, # type: bool
verbose_on_failure=True, # type: bool
timeout=DEFAULT_TIMEOUT, # type: Optional[int]
**kwargs):
"""
Wrap subprocess.Popen to
Expand Down Expand Up @@ -436,9 +436,11 @@ def call(command,
)
for fd in reads:
try:
message = os.read(fd, 1024)
if not isinstance(message, str):
message = message.decode('utf-8')
message_b = os.read(fd, 1024)
if isinstance(message_b, bytes):
message = message_b.decode('utf-8')
if isinstance(message_b, str):
message = message_b
if fd == process.stdout.fileno():
out += message
message = out_buffer + message
Expand Down Expand Up @@ -489,6 +491,7 @@ def call(command,


def call_throws(command, **kwargs):
# type: (List[str], Any) -> Tuple[str, str, int]
out, err, ret = call(command, **kwargs)
if ret:
raise RuntimeError('Failed command: %s' % ' '.join(command))
Expand Down Expand Up @@ -590,6 +593,19 @@ def pathify(p):
return os.path.join(os.getcwd(), p)
return p


def get_podman_version():
# type: () -> List[int]
if 'podman' not in container_path:
raise ValueError('not using podman')
version_str, _, _ = call_throws(
[
container_path, 'version',
'--format', '{{.Version}}'
], verbose_on_failure=False)
return list(map(int, version_str.split('.')))


def get_hostname():
# type: () -> str
return socket.gethostname()
Expand Down Expand Up @@ -2179,10 +2195,18 @@ def list_daemons(detail=True, legacy_dir=None):
image_name = None
image_id = None
version = None

image_field = '.Image'
try:
if 'podman' in container_path and get_podman_version() < [1, 6, 2]:
image_field = '.ImageID'
except:
pass

out, err, code = call(
[
container_path, 'inspect',
'--format', '{{.Id}},{{.Config.Image}},{{.Image}}',
'--format', '{{.Id}},{{.Config.Image}},{{%s}}' % image_field,
'ceph-%s-%s' % (fsid, j)
],
verbose_on_failure=False)
Expand Down

0 comments on commit 812d8f0

Please sign in to comment.