@@ -65,6 +65,15 @@ def get_parser(self, prog_name):
6565 help = _ ("Set a property to this snapshot "
6666 "(repeat option to set multiple properties)" ),
6767 )
68+ parser .add_argument (
69+ "--remote-source" ,
70+ metavar = "<key=value>" ,
71+ action = parseractions .KeyValueAction ,
72+ help = _ ("The attribute(s) of the exsiting remote volume snapshot "
73+ "(admin required) (repeat option to specify multiple "
74+ "attributes) e.g.: '--remote-source source-name=test_name "
75+ "--remote-source source-id=test_id'" ),
76+ )
6877 return parser
6978
7079 def take_action (self , parsed_args ):
@@ -74,13 +83,29 @@ def take_action(self, parsed_args):
7483 volume = parsed_args .snapshot_name
7584 volume_id = utils .find_resource (
7685 volume_client .volumes , volume ).id
77- snapshot = volume_client .volume_snapshots .create (
78- volume_id ,
79- force = parsed_args .force ,
80- name = parsed_args .snapshot_name ,
81- description = parsed_args .description ,
82- metadata = parsed_args .property ,
83- )
86+ if parsed_args .remote_source :
87+ # Create a new snapshot from an existing remote snapshot source
88+ if parsed_args .force :
89+ msg = (_ ("'--force' option will not work when you create "
90+ "new volume snapshot from an existing remote "
91+ "volume snapshot" ))
92+ LOG .warning (msg )
93+ snapshot = volume_client .volume_snapshots .manage (
94+ volume_id = volume_id ,
95+ ref = parsed_args .remote_source ,
96+ name = parsed_args .snapshot_name ,
97+ description = parsed_args .description ,
98+ metadata = parsed_args .property ,
99+ )
100+ else :
101+ # create a new snapshot from scratch
102+ snapshot = volume_client .volume_snapshots .create (
103+ volume_id ,
104+ force = parsed_args .force ,
105+ name = parsed_args .snapshot_name ,
106+ description = parsed_args .description ,
107+ metadata = parsed_args .property ,
108+ )
84109 snapshot ._info .update (
85110 {'properties' : utils .format_dict (snapshot ._info .pop ('metadata' ))}
86111 )
0 commit comments