1 # -*- coding: utf-8 -*-
8 from ceph
.deployment
.drive_group
import DriveGroupSpec
9 from ceph
.deployment
.drive_selection
.selector
import DriveSelection
10 from ceph
.deployment
.translate
import to_ceph_volume
11 from ceph
.deployment
.inventory
import Device
12 from ceph_volume
.inventory
import Inventory
13 from ceph_volume
.devices
.lvm
.batch
import Batch
15 logger
= logging
.getLogger(__name__
)
20 Deploy OSDs according to a drive groups specification.
22 The DriveGroup specification must be passed in json.
23 It can either be (preference in this order)
24 - in a file, path passed as a positional argument
25 - read from stdin, pass "-" as a positional argument
26 - a json string passed via the --spec argument
28 Either the path postional argument or --spec must be specifed.
31 def __init__(self
, argv
):
32 logger
.error(f
'argv: {argv}')
36 parser
= argparse
.ArgumentParser(
37 prog
='ceph-volume drive-group',
38 formatter_class
=argparse
.RawDescriptionHelpFormatter
,
39 description
=self
.help,
45 help=('Path to file containing drive group spec or "-" to read from stdin'),
51 help=('drive-group json string')
57 help=('dry run, only print the batch command that would be run'),
59 self
.args
= parser
.parse_args(self
.argv
)
61 if self
.args
.path
== "-":
62 commands
= self
.from_json(sys
.stdin
)
64 with
open(self
.args
.path
, 'r') as f
:
65 commands
= self
.from_json(f
)
67 dg
= json
.loads(self
.args
.spec
)
68 commands
= self
.get_dg_spec(dg
)
70 # either --spec or path arg must be specified
71 parser
.print_help(sys
.stderr
)
75 logger
.error('DriveGroup didn\'t produce any commands')
78 logger
.info('Returning ceph-volume command (--dry-run was passed): {}'.format(cmd
))
81 logger
.info('Running ceph-volume command: {}'.format(cmd
))
82 batch_args
= cmd
.split(' ')[2:]
86 def from_json(self
, file_
):
89 return self
.get_dg_spec(dg
)
91 def get_dg_spec(self
, dg
):
92 dg_spec
= DriveGroupSpec
._from
_json
_impl
(dg
)
96 inventory
= i
.get_report()
97 devices
= [Device
.from_json(i
) for i
in inventory
]
98 selection
= DriveSelection(dg_spec
, devices
)
99 return to_ceph_volume(selection
)