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
):
35 parser
= argparse
.ArgumentParser(
36 prog
='ceph-volume drive-group',
37 formatter_class
=argparse
.RawDescriptionHelpFormatter
,
38 description
=self
.help,
44 help=('Path to file containing drive group spec or "-" to read from stdin'),
50 help=('drive-group json string')
56 help=('dry run, only print the batch command that would be run'),
58 self
.args
= parser
.parse_args(self
.argv
)
60 if self
.args
.path
== "-":
61 commands
= self
.from_json(sys
.stdin
)
63 with
open(self
.args
.path
, 'r') as f
:
64 commands
= self
.from_json(f
)
66 dg
= json
.loads(self
.args
.spec
)
67 commands
= self
.get_dg_spec(dg
)
69 # either --spec or path arg must be specified
70 parser
.print_help(sys
.stderr
)
74 logger
.error('DriveGroup didn\'t produce any commands')
77 logger
.info('Returning ceph-volume command (--dry-run was passed): {}'.format(cmd
))
80 logger
.info('Running ceph-volume command: {}'.format(cmd
))
81 batch_args
= cmd
.split(' ')[2:]
85 def from_json(self
, file_
):
88 return self
.get_dg_spec(dg
)
90 def get_dg_spec(self
, dg
):
91 dg_spec
= DriveGroupSpec
._from
_json
_impl
(dg
)
95 inventory
= i
.get_report()
96 devices
= [Device
.from_json(i
) for i
in inventory
]
97 selection
= DriveSelection(dg_spec
, devices
)
98 return to_ceph_volume(selection
)