summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2014-04-29 15:24:58 +0200
committerMichal Minar <miminar@redhat.com>2014-04-29 15:24:58 +0200
commit724471e5325871ef4ffa4fdfce3019eb1e74f616 (patch)
treeb39d4d79434d7f1f108771fff7c2cd12a3b14c53
parent5b6f0b382629310557ac07ffebb0ee937419c89a (diff)
parent04573fca595da773e373de1febc2dd3c0af3ba93 (diff)
downloadopenlmi-scripts-724471e5325871ef4ffa4fdfce3019eb1e74f616.tar.gz
openlmi-scripts-724471e5325871ef4ffa4fdfce3019eb1e74f616.tar.xz
openlmi-scripts-724471e5325871ef4ffa4fdfce3019eb1e74f616.zip
Merge pull request #85 from rnovacek/fixes
networking: fix setting deactivation and add info messages
-rw-r--r--commands/networking/lmi/scripts/networking/__init__.py64
1 files changed, 62 insertions, 2 deletions
diff --git a/commands/networking/lmi/scripts/networking/__init__.py b/commands/networking/lmi/scripts/networking/__init__.py
index 893ca29..9da7110 100644
--- a/commands/networking/lmi/scripts/networking/__init__.py
+++ b/commands/networking/lmi/scripts/networking/__init__.py
@@ -33,7 +33,7 @@ LMI networking provider client library.
import time
from lmi.scripts.common.errors import LmiFailed, LmiInvalidOptions
-from lmi.scripts.common import get_logger
+from lmi.scripts.common import get_logger, versioncheck
import util
@@ -356,6 +356,16 @@ def get_static_routes(ns, setting):
'''
return setting.associators(AssocClass="LMI_OrderedIPAssignmentComponent", ResultClass="LMI_IPRouteSettingData")
+def _provider_check_required_device(ns):
+ '''
+ Check if provider requires device to be used in ApplySettingToIPNetworkConnection
+ '''
+ # Do a full fetch to obtain qualifiers
+ if not ns.LMI_IPConfigurationService.is_fetched(True):
+ ns.LMI_IPConfigurationService.fetch(True)
+ version = versioncheck.get_class_version(ns.connection, 'LMI_IPConfigurationService', ns.name)
+ return versioncheck.parser.cmp_version(version, '0.2.3')
+
def activate(ns, setting, device=None):
'''
Activate network setting on given device
@@ -390,6 +400,7 @@ def activate(ns, setting, device=None):
isCurrent = True
break
time.sleep(1)
+ LOG().info("Setting %s activated", setting.Caption)
return 0
devices = []
@@ -408,6 +419,7 @@ def activate(ns, setting, device=None):
Mode=service.ApplySettingToIPNetworkConnection.ModeValues.Mode32768)
if result.errorstr:
raise LmiFailed("Unable to activate setting: %s" % result.errorstr)
+ LOG().info("Setting %s activated", setting.Caption)
return 0
def deactivate(ns, setting, device=None):
@@ -419,6 +431,41 @@ def deactivate(ns, setting, device=None):
:type device: LMI_IPNetworkConnection or None
'''
service = ns.LMI_IPConfigurationService.first_instance()
+
+ if _provider_check_required_device(ns):
+ # old version of provider that doesn't support activation of setting without device
+ if device is None:
+ if setting.classname == 'LMI_BridgingMasterSettingData':
+ slave_class = 'LMI_BridgingSlaveSettingData'
+ elif setting.classname == 'LMI_BondingMasterSettingData':
+ slave_class = 'LMI_BondingSlaveSettingData'
+ else:
+ slave_class = None
+
+ # Autodetect and deactivate slaves
+ if slave_class:
+ affected_settings = setting.associators(AssocClass='LMI_OrderedIPAssignmentComponent', ResultClass=slave_class)
+ else:
+ affected_settings = [setting]
+
+ for slave_setting in affected_settings:
+ device = slave_setting.first_associator(AssocClass="LMI_IPElementSettingData", ResultClass="LMI_IPNetworkConnection")
+ result = service.SyncApplySettingToIPNetworkConnection(SettingData=slave_setting,
+ IPNetworkConnection=device,
+ Mode=service.ApplySettingToIPNetworkConnection.ModeValues.Mode32769)
+ if result.errorstr:
+ raise LmiFailed("Unable to deactivate setting: %s" % result.errorstr)
+ # TODO: rework using indications
+ isCurrent = True
+ while isCurrent:
+ for esd in slave_setting.references(ResultClass="LMI_IPElementSettingData"):
+ if esd.IsCurrent == ns.LMI_IPElementSettingData.IsCurrentValues.IsNotCurrent:
+ isCurrent = False
+ break
+ time.sleep(1)
+ LOG().info("Setting %s deactivated", setting.Caption)
+ return 0
+
if device is not None:
LOG().debug('Deactivating setting %s on device %s', setting.Caption, device.ElementName)
result = service.SyncApplySettingToIPNetworkConnection(SettingData=setting,
@@ -431,6 +478,7 @@ def deactivate(ns, setting, device=None):
Mode=service.ApplySettingToIPNetworkConnection.ModeValues.Mode32769)
if result.errorstr:
raise LmiFailed("Unable to deactivate setting: %s" % result.errorstr)
+ LOG().info("Setting %s deactivated", setting.Caption)
return 0
def enslave(ns, master_setting, device):
@@ -445,6 +493,7 @@ def enslave(ns, master_setting, device):
result = capability.LMI_CreateSlaveSetting(MasterSettingData=master_setting)
if result.rval != 0:
raise LmiFailed("Unable to create setting: %s" % result.errorstr)
+ LOG().info("Device %s enslaved to setting %s", device.ElementName, master_setting.Caption)
return 0
def create_setting(ns, caption, device, type, ipv4method, ipv6method):
@@ -468,6 +517,7 @@ def create_setting(ns, caption, device, type, ipv4method, ipv6method):
IPv6Type=ipv6method)
if result.rval != 0:
raise LmiFailed("Unable to create setting: %s" % result.errorstr)
+ LOG().info("Setting %s created", caption)
return 0
def delete_setting(ns, setting):
@@ -476,7 +526,9 @@ def delete_setting(ns, setting):
:param LMI_IPAssignmentSettingData setting: network setting.
'''
+ caption = setting.Caption
setting.delete()
+ LOG().info("Setting %s deleted", caption)
return 0
def add_ip_address(ns, setting, address, prefix, gateway=None):
@@ -513,6 +565,7 @@ def add_ip_address(ns, setting, address, prefix, gateway=None):
settingData.push()
if not found:
raise LmiInvalidOptions("Can't add IP address to setting: invalid setting type.")
+ LOG().info("IP address %s/%d added to setting %s", address, prefix, setting.Caption)
return 0
def remove_ip_address(ns, setting, address):
@@ -545,6 +598,7 @@ def remove_ip_address(ns, setting, address):
settingData.push()
if not found:
raise LmiInvalidOptions("Can't remove IP address from setting: invalid setting type or address doesn't exist.")
+ LOG().info("IP address %s removed from setting %s", address, setting.Caption)
return 0
def replace_ip_address(ns, setting, address, prefix, gateway=None):
@@ -581,6 +635,7 @@ def replace_ip_address(ns, setting, address, prefix, gateway=None):
settingData.push()
if not found:
raise LmiInvalidOptions("Can't add IP address to setting: invalid setting type.")
+ LOG().info("Existing addresses replaced with IP address %s/%d in setting %s", address, prefix, setting.Caption)
return 0
@@ -621,6 +676,7 @@ def add_static_route(ns, setting, address, prefix, metric=None, next_hop=None):
if next_hop is not None:
route.NextHop = next_hop
route.push()
+ LOG().info("Static route to %s/%d added to setting %s", address, prefix, setting.Caption)
return 0
def remove_static_route(ns, setting, address):
@@ -640,7 +696,7 @@ def remove_static_route(ns, setting, address):
settingData.delete()
if not found:
raise LmiInvalidOptions("No such route: %s" % address)
-
+ LOG().info("Static route to %s removed from setting %s", address, setting.Caption)
return 0
def replace_static_route(ns, setting, address, prefix, metric=None, next_hop=None):
@@ -665,6 +721,7 @@ def replace_static_route(ns, setting, address, prefix, metric=None, next_hop=Non
if settingData is None:
break
settingData.delete()
+ LOG().info("Static routes replaced with route to %s/%d in setting %s", address, prefix, setting.Caption)
return add_static_route(ns, setting, address, prefix, metric, next_hop)
def add_dns_server(ns, setting, address):
@@ -685,6 +742,7 @@ def add_dns_server(ns, setting, address):
break
else:
raise LmiInvalidOptions("Can't assign DNS address to setting %s, invalid setting type" % setting.Caption)
+ LOG().info("DNS server %s/%d added to setting %s", address, setting.Caption)
return 0
def remove_dns_server(ns, setting, address):
@@ -709,6 +767,7 @@ def remove_dns_server(ns, setting, address):
raise LmiInvalidOptions("No DNS with address %s found for setting %s" % (address, setting.Caption))
else:
raise LmiInvalidOptions("Can't remove DNS address to setting %s, invalid setting type" % setting.Caption)
+ LOG().info("DNS server %s removed from setting %s", address, setting.Caption)
return 0
def replace_dns_server(ns, setting, address):
@@ -729,4 +788,5 @@ def replace_dns_server(ns, setting, address):
return 0
else:
raise LmiInvalidOptions("Can't remove DNS address to setting %s, invalid setting type" % setting.Caption)
+ LOG().info("Existing DNS servers replaced with %s in setting %s", address, setting.Caption)
return 0