def update_or_create(cls, with_status=False, **kwargs): """ Update or create static netlink. DNS entry differences are not resolved, instead any entries provided will be the final state for this netlink. If the intent is to add/remove DNS entries you can use the :meth:`~domain_server_address` method to add or remove. :raises CreateElementFailed: failed creating element :return: element instance by type or 3-tuple if with_status set """ dns_address = kwargs.pop('domain_server_address', []) element, updated, created = super(StaticNetlink, cls).update_or_create( with_status=True, defer_update=True, **kwargs) if not created: if dns_address: new_entries = RankedDNSAddress([]) new_entries.add(dns_address) element.data.update(domain_server_address=new_entries.entries) updated = True if updated: element.update() if with_status: return element, updated, created return element
def create(cls, name, gateway, network, input_speed=None, output_speed=None, domain_server_address=None, provider_name=None, probe_address=None, standby_mode_period=3600, standby_mode_timeout=30, active_mode_period=5, active_mode_timeout=1, comment=None): """ Create a new StaticNetlink to be used as a traffic handler. :param str name: name of netlink Element :param gateway_ref: gateway to map this netlink to. This can be an element or str href. :type gateway_ref: Router,Engine :param list ref: network/s associated with this netlink. :type ref: list(str,Element) :param int input_speed: input speed in Kbps, used for ratio-based load-balancing :param int output_speed: output speed in Kbps, used for ratio-based load-balancing :param list domain_server_address: dns address for netlink. Engine DNS can override this field :type dns_addresses: list(str,Element) :param str provider_name: optional name to identify provider for this netlink :param list probe_address: list of IP addresses to use as probing addresses to validate connectivity :type probe_ip_address: list(str) :param int standby_mode_period: Specifies the probe period when standby mode is used (in seconds) :param int standby_mode_timeout: probe timeout in seconds :param int active_mode_period: Specifies the probe period when active mode is used (in seconds) :param int active_mode_timeout: probe timeout in seconds :raises ElementNotFound: if using type Element parameters that are not found. :raises CreateElementFailed: failure to create netlink with reason :rtype: StaticNetlink .. note:: To monitor the status of the network links, you must define at least one probe IP address. """ json = {'name': name, 'gateway_ref': element_resolver(gateway), 'ref': element_resolver(network), 'input_speed': input_speed, 'output_speed': output_speed, 'probe_address': probe_address, 'nsp_name': provider_name, 'comment': comment, 'standby_mode_period': standby_mode_period, 'standby_mode_timeout': standby_mode_timeout, 'active_mode_period': active_mode_period, 'active_mode_timeout': active_mode_timeout} if domain_server_address: r = RankedDNSAddress([]) r.add(domain_server_address) json.update(domain_server_address=r.entries) return ElementCreator(cls, json)
def create(cls, name, gateway, network, input_speed=None, output_speed=None, domain_server_address=None, provider_name=None, probe_address=None, standby_mode_period=3600, standby_mode_timeout=30, active_mode_period=5, active_mode_timeout=1, comment=None): """ Create a new StaticNetlink to be used as a traffic handler. :param str name: name of netlink Element :param gateway_ref: gateway to map this netlink to. This can be an element or str href. :type gateway_ref: Router,Engine :param list ref: network/s associated with this netlink. :type ref: list(str,Element) :param int input_speed: input speed in Kbps, used for ratio-based load-balancing :param int output_speed: output speed in Kbps, used for ratio-based load-balancing :param list domain_server_address: dns addresses for netlink. Engine DNS can override this field :type dns_addresses: list(str,Element) :param str provider_name: optional name to identify provider for this netlink :param list probe_address: list of IP addresses to use as probing addresses to validate connectivity :type probe_ip_address: list(str) :param int standby_mode_period: Specifies the probe period when standby mode is used (in seconds) :param int standby_mode_timeout: probe timeout in seconds :param int active_mode_period: Specifies the probe period when active mode is used (in seconds) :param int active_mode_timeout: probe timeout in seconds :raises ElementNotFound: if using type Element parameters that are not found. :raises CreateElementFailed: failure to create netlink with reason :rtype: StaticNetlink .. note:: To monitor the status of the network links, you must define at least one probe IP address. """ json = {'name': name, 'gateway_ref': element_resolver(gateway), 'ref': element_resolver(network), 'input_speed': input_speed, 'output_speed': output_speed, 'probe_address': probe_address, 'nsp_name': provider_name, 'comment': comment, 'standby_mode_period': standby_mode_period, 'standby_mode_timeout': standby_mode_timeout, 'active_mode_period': active_mode_period, 'active_mode_timeout': active_mode_timeout} if domain_server_address: r = RankedDNSAddress([]) r.add(domain_server_address) json.update(domain_server_address=r.entries) return ElementCreator(cls, json)
def update_or_create(cls, with_status=False, **kwargs): """ Update or create static netlink. :param dict kwargs: kwargs to satisfy the `create` constructor arguments if the element doesn't exist or attributes to change :raises CreateElementFailed: failed creating element :return: element instance by type or 3-tuple if with_status set """ updated = False element, created = super(StaticNetlink, cls).get_or_create(with_status=True, **kwargs) if not created: if 'domain_server_address' in kwargs: dns = kwargs.pop('domain_server_address', []) current_dns = element.domain_server_address new_entries = RankedDNSAddress([]) new_entries.add(dns) if len(new_entries) != len(current_dns): element.update(domain_server_address=new_entries.entries) updated = True else: if any(entry for entry in dns if entry not in current_dns): element.update(domain_server_address=new_entries.entries) updated = True gateway = element_resolver(kwargs.pop('gateway', None)) if gateway and gateway != element.data.get('gateway_ref'): element.data.update(gateway_ref=gateway) updated = True network = element_resolver(kwargs.pop('network', [])) if network and set(element.data.get('ref')) ^ set(network): element.data.update(ref=network) updated = True for name, value in kwargs.items(): if element.data.get(name) != value: element.data[name] = value updated = True if updated: element.update() if with_status: return element, updated, created return element
def domain_server_address(self): """ Configured DNS servers for this netlink :return: list of DNS servers; if elements are specifed, they will be returned as type Element :rtype: RankedDNSAddress """ return RankedDNSAddress(self.data.get('domain_server_address'))
def create( cls, name, gateway, network, connection_type=None, input_speed=None, output_speed=None, domain_server_address=None, provider_name=None, probe_address=None, standby_mode_period=3600, standby_mode_timeout=30, active_mode_period=5, active_mode_timeout=1, comment=None, ): """ Create a new StaticNetlink to be used as a traffic handler. :param str name: name of netlink Element :param gateway_ref: gateway to map this netlink to. This can be an element or str href. :type gateway_ref: Router,Engine :param connection_type: default QoS connection type. By default, we put Active. :type connection_type: ConnectionType,str :param list ref: network/s associated with this netlink. :type ref: list(str,Element) :param connection_type: the mandatory connection type from v6.5 :param int input_speed: input speed in Kbps, used for ratio-based load-balancing :param int output_speed: output speed in Kbps, used for ratio-based load-balancing :param list domain_server_address: dns addresses for netlink. Engine DNS can override this field :type dns_addresses: list(str,Element) :param str provider_name: optional name to identify provider for this netlink :param list probe_address: list of IP addresses to use as probing addresses to validate connectivity :type probe_ip_address: list(str) :param int standby_mode_period: Specifies the probe period when standby mode is used (in seconds) :param int standby_mode_timeout: probe timeout in seconds :param int active_mode_period: Specifies the probe period when active mode is used (in seconds) :param int active_mode_timeout: probe timeout in seconds :raises ElementNotFound: if using type Element parameters that are not found. :raises CreateElementFailed: failure to create netlink with reason :rtype: StaticNetlink .. note:: To monitor the status of the network links, you must define at least one probe IP address. """ json = { "name": name, "gateway_ref": element_resolver(gateway), "input_speed": input_speed, "output_speed": output_speed, "probe_address": probe_address, "nsp_name": provider_name, "comment": comment, "standby_mode_period": standby_mode_period, "standby_mode_timeout": standby_mode_timeout, "active_mode_period": active_mode_period, "active_mode_timeout": active_mode_timeout, } if is_api_version_less_than_or_equal("6.5"): json.update(ref=element_resolver(network)) else: json.update(network_ref=element_resolver(network)) # connection_type_ref available since # SMC6.8 api>=6.8 if not is_api_version_less_than_or_equal("6.7"): if not connection_type: # by default, Active is used json.update(connection_type_ref=element_resolver( ConnectionType("Active"))) else: json.update( connection_type_ref=element_resolver(connection_type)) if domain_server_address: r = RankedDNSAddress([]) r.add(domain_server_address) json.update(domain_server_address=r.entries) return ElementCreator(cls, json)