@@ -141,7 +141,6 @@ def snapshot_create(**kwargs):
141141 # not uninstall workflow, raise exception
142142 raise cfy_exc .NonRecoverableError ("No network for backup" )
143143
144- snapshot_name = common .get_backupname (kwargs )
145144 libvirt_auth , _ = common .get_libvirt_params (** kwargs )
146145 conn = libvirt .open (libvirt_auth )
147146 if conn is None :
@@ -158,28 +157,7 @@ def snapshot_create(**kwargs):
158157 'Failed to find the network: {}' .format (repr (e ))
159158 )
160159
161- net_backup = network .XMLDesc ()
162- if kwargs .get ("snapshot_incremental" ):
163- backups = ctx .instance .runtime_properties .get ("backups" , {})
164- if snapshot_name in backups :
165- raise cfy_exc .NonRecoverableError (
166- "Snapshot {snapshot_name} already exists."
167- .format (snapshot_name = snapshot_name ,))
168- backups [snapshot_name ] = net_backup
169- ctx .instance .runtime_properties ["backups" ] = backups
170- ctx .logger .info ("Snapshot {snapshot_name} is created."
171- .format (snapshot_name = snapshot_name ,))
172- else :
173- if common .read_node_state (common .get_backupdir (kwargs ),
174- resource_id ):
175- raise cfy_exc .NonRecoverableError (
176- "Backup {snapshot_name} already exists."
177- .format (snapshot_name = snapshot_name ,))
178- common .save_node_state (common .get_backupdir (kwargs ), resource_id ,
179- net_backup )
180- ctx .logger .info ("Backup {snapshot_name} is created."
181- .format (snapshot_name = snapshot_name ,))
182- ctx .logger .debug ("Current config {}" .format (repr (net_backup )))
160+ common .xml_snapshot_create (kwargs , resource_id , network .XMLDesc ())
183161 finally :
184162 conn .close ()
185163
@@ -193,8 +171,6 @@ def snapshot_apply(**kwargs):
193171 # not uninstall workflow, raise exception
194172 raise cfy_exc .NonRecoverableError ("No network for restore" )
195173
196- snapshot_name = common .get_backupname (kwargs )
197-
198174 libvirt_auth , _ = common .get_libvirt_params (** kwargs )
199175 conn = libvirt .open (libvirt_auth )
200176 if conn is None :
@@ -211,29 +187,7 @@ def snapshot_apply(**kwargs):
211187 'Failed to find the network: {}' .format (repr (e ))
212188 )
213189
214- if kwargs .get ("snapshot_incremental" ):
215- backups = ctx .instance .runtime_properties .get ("backups" , {})
216- if snapshot_name not in backups :
217- raise cfy_exc .NonRecoverableError (
218- "No snapshots found with name: {snapshot_name}."
219- .format (snapshot_name = snapshot_name ,))
220- net_backup = backups [snapshot_name ]
221- else :
222- net_backup = common .read_node_state (common .get_backupdir (kwargs ),
223- resource_id )
224- if not net_backup :
225- raise cfy_exc .NonRecoverableError (
226- "No backups found with name: {snapshot_name}."
227- .format (snapshot_name = snapshot_name ,))
228-
229- if net_backup .strip () != network .XMLDesc ().strip ():
230- ctx .logger .info ("We have different configs,\n {}\n vs\n {}\n "
231- .format (
232- repr (net_backup .strip ()),
233- repr (network .XMLDesc ().strip ())))
234- else :
235- ctx .logger .info ("Already used such configuration: {}"
236- .format (snapshot_name ))
190+ common .xml_snapshot_apply (kwargs , resource_id , network .XMLDesc ())
237191 finally :
238192 conn .close ()
239193
@@ -247,23 +201,7 @@ def snapshot_delete(**kwargs):
247201 # not uninstall workflow, raise exception
248202 raise cfy_exc .NonRecoverableError ("No network for backup delete" )
249203
250- snapshot_name = common .get_backupname (kwargs )
251- if kwargs .get ("snapshot_incremental" ):
252- backups = ctx .instance .runtime_properties .get ("backups" , {})
253- if snapshot_name not in backups :
254- raise cfy_exc .NonRecoverableError (
255- "No snapshots found with name: {snapshot_name}."
256- .format (snapshot_name = snapshot_name ,))
257- del backups [snapshot_name ]
258- ctx .instance .runtime_properties ["backups" ] = backups
259- else :
260- if not common .read_node_state (common .get_backupdir (kwargs ),
261- resource_id ):
262- raise cfy_exc .NonRecoverableError (
263- "No backups found with name: {snapshot_name}."
264- .format (snapshot_name = snapshot_name ,))
265- common .delete_node_state (common .get_backupdir (kwargs ), resource_id )
266- ctx .logger .info ("Backup deleted: {}" .format (snapshot_name ))
204+ common .xml_snapshot_delete (kwargs , resource_id )
267205
268206
269207@operation
0 commit comments