def undo(self): """ Overrides parent method. Roll back a failed transaction. """ LOG.debug('Roll back invoked for IfcfgFileOVSBuilder. Rolling back ' 'device %s', self.ovs_port_name) # Roll back OVS port if self.remove_on_undo: # Prevent empty file from hanging around on disk LOG.debug('Removing ifcfg: %s', self.fnamepath) commandlet.remove_file_as_root(self.fnamepath) elif(self.source_ovs_port_restore is not None and len(self.source_ovs_port_restore)): self.commandex.send_ifcfg(self.ovs_port_name, self.source_ovs_port_restore) LOG.debug('Roll back completed for device %s', self.ovs_port_name)
def execute(self): """ Overrides parent method. Updates the OVSPort bond ifcfg files. """ LOG.debug("In the execute of IfCfgBondFileBuilder") # Read the OVSPort ifcfg file and save the contents for undo self.fnamepath, self.source_ovs_port_restore = \ self.commandex.get_ifcfg(self.ovs_port_name) # Create new configuration for OVSPort bond, if the bond has children ovs_port_dict = {} if len(self.bond_cmp_names): ovs_port_dict[agent.IFCFG_DEVICE] = self.ovs_port_name ovs_port_dict[agent.IFCFG_ONBOOT] = 'yes' ovs_port_dict[agent.IFCFG_DEV_TYPE] = 'ovs' ovs_port_dict[agent.IFCFG_TYPE] = move_ip_address.OVS_BOND ovs_port_dict[agent.IFCFG_OVS_BRIDGE] = self.ovs_name ovs_port_dict[agent.IFCFG_BOOTPROTO] = 'none' ovs_port_dict[agent.IFCFG_BOND_IFACES] = '"%s"' % ( ' '.join(self.bond_cmp_names)) ovs_port_dict[agent.IFCFG_OVS_OPTIONS] = '"bond_mode=balance-slb"' ovs_port_dict[agent.IFCFG_HOTPLUG] = 'no' # Send OVSPort ifcfg file back to disk LOG.debug('Sending ifcfg for device: %s', ovs_port_dict) name = self.commandex.send_ifcfg(self.ovs_port_name, ovs_port_dict) # Store the pathname that was used in case we need to undo self.fnamepath = name elif self.fnamepath and len(self.fnamepath): # The bond has no children, so the bond is being removed LOG.debug('Removing ifcfg: %s', self.fnamepath) commandlet.remove_file_as_root(self.fnamepath) LOG.debug("Execute from IfCfgBondFileBuilder was a success")