11from __future__ import print_function
22from textwrap import dedent
33import logging
4+ import argparse
45from ceph_volume .util import system
56from ceph_volume .util .arg_validators import exclude_group_options
67from ceph_volume import decorators , terminal , objectstore
78from .common import create_parser , rollback_osd
9+ from typing import List , Optional
810
911logger = logging .getLogger (__name__ )
1012
@@ -13,31 +15,34 @@ class Create(object):
1315
1416 help = 'Create a new OSD from an LVM device'
1517
16- def __init__ (self , argv , args = None ):
17- self .objectstore = None
18+ def __init__ (self , argv : Optional [List [str ]] = None ,
19+ args : Optional [argparse .Namespace ] = None ) -> None :
20+ self .objectstore : Optional [objectstore .baseobjectstore .BaseObjectStore ] = None
1821 self .argv = argv
1922 self .args = args
2023
2124 @decorators .needs_root
22- def create (self ):
23- if not self .args .osd_fsid :
24- self .args .osd_fsid = system .generate_uuid ()
25- self .objectstore = objectstore .mapping ['LVM' ][self .args .objectstore ](args = self .args )
26- self .objectstore .safe_prepare ()
27- osd_id = self .objectstore .osd_id
28- try :
29- # we try this for activate only when 'creating' an OSD, because a rollback should not
30- # happen when doing normal activation. For example when starting an OSD, systemd will call
31- # activate, which would never need to be rolled back.
32- self .objectstore .activate ()
33- except Exception :
34- logger .exception ('lvm activate was unable to complete, while creating the OSD' )
35- logger .info ('will rollback OSD ID creation' )
36- rollback_osd (self .args , osd_id )
37- raise
38- terminal .success ("ceph-volume lvm create successful for: %s" % self .args .data )
25+ def create (self ) -> None :
26+ if self .args is not None :
27+ if not self .args .osd_fsid :
28+ self .args .osd_fsid = system .generate_uuid ()
29+ self .objectstore = objectstore .mapping ['LVM' ][self .args .objectstore ](args = self .args )
30+ if self .objectstore is not None :
31+ self .objectstore .safe_prepare ()
32+ osd_id = self .objectstore .osd_id
33+ try :
34+ # we try this for activate only when 'creating' an OSD, because a rollback should not
35+ # happen when doing normal activation. For example when starting an OSD, systemd will call
36+ # activate, which would never need to be rolled back.
37+ self .objectstore .activate ()
38+ except Exception :
39+ logger .exception ('lvm activate was unable to complete, while creating the OSD' )
40+ logger .info ('will rollback OSD ID creation' )
41+ rollback_osd (self .args , osd_id )
42+ raise
43+ terminal .success ("ceph-volume lvm create successful for: %s" % self .args .data )
3944
40- def main (self ):
45+ def main (self ) -> None :
4146 sub_command_help = dedent ("""
4247 Create an OSD by assigning an ID and FSID, registering them with the
4348 cluster with an ID and FSID, formatting and mounting the volume, adding
@@ -65,6 +70,8 @@ def main(self):
6570 prog = 'ceph-volume lvm create' ,
6671 description = sub_command_help ,
6772 )
73+ if self .argv is None :
74+ self .argv = []
6875 if len (self .argv ) == 0 :
6976 print (sub_command_help )
7077 return
0 commit comments