def _to_real_type_helper(self, elem, member, entity): _type = member.ptype text = elem.text if text is None: return Empty() elif _type == 'int': if is_digit(text): return int(text) else: return text elif _type == 'str': return text elif _type == 'bool': if text == 'false': return False else: return True elif _type == 'Decimal64': return Decimal64(text) elif _type == 'bits': pass else: pass
def _to_real_union_type_helper(cls, rt, member, entity): potential_str_value = '' for contained_member in member.members: if contained_member.mtype == REFERENCE_UNION: return XmlDecoder._to_real_union_type_helper( rt, contained_member, entity) elif contained_member.mtype == REFERENCE_LEAFLIST: result = XmlDecoder._to_real_list_type(rt, contained_member, entity) if result is not None: return result else: continue elif contained_member.mtype == REFERENCE_ENUM_CLASS: clazz = get_class(contained_member.pmodule_name, contained_member.clazz_name) meta_info = getattr(clazz, '_meta_info')() enum_literal_key = rt[0].text if enum_literal_key in meta_info.literal_map: enum_literal = meta_info.literal_map[enum_literal_key] return getattr(clazz, enum_literal) elif contained_member.mtype == REFERENCE_IDENTITY_CLASS: return XmlDecoder._bind_to_identity_helper( rt[0], member, entity) elif contained_member.mtype == REFERENCE_BITS: return XmlDecoder._bind_to_bits_helper(rt[0], member, entity) elif contained_member.ptype == 'bool' and rt[0] in [ 'false', 'true' ]: if rt[0] == 'false': return False else: return True elif contained_member.ptype == 'str': if is_digit(rt[0].text): potential_str_value = rt[0].text continue return rt[0].text elif contained_member.ptype == 'int' and rt[ 0].text is not None and is_digit(rt[0].text): return int(rt[0].text) elif contained_member.ptype == 'Decimal64' and rt[ 0].text is not None: try: float(rt[0].text) return Decimal64(rt[0].text) except ValueError: ydk_logger = logging.getLogger(__name__) ydk_logger.error( 'Got a ValueError converting a Decimal64 type to float' ) pass elif contained_member.ptype == 'Empty' and rt[0].text is None: return Empty() if len(potential_str_value) > 0: return potential_str_value return None
def test_leafref(self): # changed to tye decimal64 runner = ysanity.Runner() runner.ytypes.built_in_t.leaf_ref = Decimal64('3.14') self.crud.create(self.ncc, runner) runner_read = ysanity.Runner() runner_read = self.crud.read(self.ncc, runner_read) self.assertEqual(runner, runner_read)
def test_leafref(self): runner = self._create_runner() runner.ytypes.built_in_t.leaf_ref = Decimal64('3.14') self.crud.create(self.ncc, runner) runner1 = ysanity.Runner() runner1 = self.crud.read(self.ncc, runner1) result = is_equal(runner, runner1) self.assertEqual(result, True)
def test_decimal64(self): runner = Runner() runner.ytypes.built_in_t.deci64 = Decimal64('3.14') self.crud.create(self.ncc, runner) # Read into Runner1 runner1 = Runner() runner1 = self.crud.read(self.ncc, runner1) # Compare runners self.assertEqual(runner, runner1)
def test_decimal64(self): runner = self._create_runner() runner.ytypes.built_in_t.deci64 = Decimal64('3.14') self.crud.create(self.ncc, runner) # Read into Runner2 runner1 = Runner() runner1 = self.crud.read(self.ncc, runner1) # Compare runners result = is_equal(runner, runner1) self.assertEqual(result, True)
def _to_real_type_helper(cls, elem, member, entity): if elem.text is None: return Empty() elif member.ptype == 'int' and is_digit(elem.text): return int(elem.text) elif member.ptype == 'str': return elem.text elif member.ptype == 'bool': return False if elem.text == 'false' else True elif member.ptype == 'Decimal64': return Decimal64(elem.text) elif member.ptype == 'bits': return XmlDecoder._bind_to_bits_helper(elem, member, entity) elif 'Enum' in member.ptype: return XmlDecoder._bind_to_enum_helper(elem, member) elif 'Identity' in member.ptype: return XmlDecoder._bind_to_identity_helper(elem, member, entity) return None
def config_components(components): """ Add config data for optical channels (lines) and map into real ports This is where you define output power and the wavelength """ component = components.Component() component.name = '0/0-OpticalChannel0/0/0/6' optical_channel_config = component.optical_channel.Config() optical_channel_config.line_port = '0/0-Optics0/0/0/6' ## mode1 == FEC7%, mode 2 == FEC20% optical_channel_config.operational_mode = 2 ## output power is expressed in increments of 0.01 dBm optical_channel_config.target_output_power = Decimal64('0') ## frequency of the optical channel, expressed in MHz optical_channel_config.frequency = 191300000 component.optical_channel.config = optical_channel_config components.component.append(component)
def config_components(components): """ Add config data for optical channels (lines) This is where you define output power and the wavelength """ for LINE in [[ '0/0-OpticalChannel0/0/0/5', '0/0-Optics0/0/0/5', '0', 191300000 ], ['0/0-OpticalChannel0/0/0/6', '0/0-Optics0/0/0/6', '0', 196100000]]: component = components.Component() component.name = LINE[0] optical_channel_config = component.optical_channel.Config() optical_channel_config.line_port = LINE[1] ## mode1 == FEC7%, mode 2 == FEC20% optical_channel_config.operational_mode = 2 ## output power is expressed in increments of 0.01 dBm optical_channel_config.target_output_power = Decimal64(LINE[2]) ## frequency of the optical channel, expressed in MHz optical_channel_config.frequency = LINE[3] component.optical_channel.config = optical_channel_config components.component.append(component)
def _to_real_union_type_helper(self, rt, member, entity): potential_str_value = '' for contained_member in member.members: if contained_member.mtype == REFERENCE_UNION: return XmlDecoder._to_real_union_type_helper(rt, contained_member, entity) elif contained_member.mtype == REFERENCE_LEAFLIST: return XmlDecoder._to_real_list_type(rt, contained_member, entity) elif contained_member.mtype == REFERENCE_ENUM_CLASS: exec_import = 'from ' + contained_member.pmodule_name + ' import ' + contained_member.clazz_name.split('.')[0] exec exec_import # first get the enum_class meta_info = eval('%s._meta_info()' % contained_member.clazz_name) enum_literal_key = rt[0].text if enum_literal_key in meta_info.literal_map: enum_literal = meta_info.literal_map[enum_literal_key] return eval('%s.%s' % (contained_member.clazz_name, enum_literal)) elif contained_member.mtype == REFERENCE_IDENTITY_CLASS: identity_mod_name = None identity_name = None if ':' in rt[0]: (prefix, identity_name) = rt[0].text.split(':') identity_ns = rt[0].nsmap[prefix] identity_mod_name = None # find the module name corresponding to this identity_ns for mod_name in _yang_ns._namespaces: if identity_ns == _yang_ns._namespaces[mod_name]: identity_mod_name = mod_name break else: identity_mod_name = entity.i_meta.module_name identity_name = rt[0].text if (identity_mod_name, identity_name) in _yang_ns._identity_map: (py_mod_name, identity_clazz_name) = _yang_ns._identity_map[(identity_mod_name, identity_name)] exec_import = 'from ' + py_mod_name + ' import ' + identity_clazz_name exec exec_import eval_getinstance = identity_clazz_name + '()' instance = eval(eval_getinstance) return instance elif contained_member.mtype == REFERENCE_BITS: exec_import = 'from ' + contained_member.pmodule_name + ' import ' + contained_member.clazz_name.split('.')[0] exec exec_import keys = rt[0].text.split(" ") for key in keys: entity.__dict__[member.presentation_name][key] = True return entity.__dict__[member.presentation_name] elif contained_member.ptype == 'bool' and rt[0] in ['false', 'true']: if rt[0] == 'false': return False else: return True elif contained_member.ptype == 'str': if is_digit(rt[0].text): potential_str_value = rt[0].text continue return rt[0].text elif contained_member.ptype == 'long' and rt[0].text is not None and is_digit(rt[0].text): return long(rt[0].text) elif contained_member.ptype == 'int' and rt[0].text is not None and is_digit(rt[0].text): return int(rt[0].text) elif contained_member.ptype == 'Decimal64' and rt[0].text is not None: try: float(rt[0].text) return Decimal64(rt[0].text) except ValueError: ydk_logger = logging.getLogger('ydk.providers.NetconfServiceProvider') ydk_logger.error('Got a ValueError converting a Decimal64 type to float') pass elif contained_member.ptype == 'Empty' and rt[0].text is None: return Empty() if len(potential_str_value) > 0: return potential_str_value return None
def config_terminal_device(terminal_device): """ Add config data for correlation between client ports, logical channels and optical channels. "5x100G client -> 2x200G line" slice mode. In that mode, in each slice, first 2 client ports are mapped to the first line port and last 2 client ports are mapped to the second line port. The port in the middle is split across each line in 50/50 ratio """ ## Define logical mapping between logical ethernet channels ## and logical OTN channels ## Creation of the logical number(index) for the 1st, 2nd, 4th and ## 5th client ports of slice0 for j in [[0, '0/0-Optics0/0/0/0', 200], [10, '0/0-Optics0/0/0/1', 200], [30, '0/0-Optics0/0/0/3', 201], [40, '0/0-Optics0/0/0/4', 201]]: NUM = 100 channel = terminal_device.logical_channels.Channel() ## indexing can be any, except 0. channel.index = NUM + j[0] ## defining the Ethernet logical channel (speed, status, Eth mode) channel_config = channel.Config() channel_config.rate_class = oc_tr_types.Trib_Rate_100GIdentity() channel_config.admin_state = oc_tr_types.AdminStateTypeEnum.ENABLED channel_config.trib_protocol = oc_tr_types.Prot_100G_MlgIdentity() channel_config.logical_channel_type = oc_tr_types.Prot_EthernetIdentity( ) channel.config = channel_config ## mapping of the client physical port into the ## assigned logical number (index) channel_ingress = channel.Ingress() channel_ingress_tr = channel_ingress.Config() channel_ingress_tr.transceiver = j[1] channel_ingress.config = channel_ingress_tr channel.ingress = channel_ingress ## mapping the ethernet logical channel into the OTN logical channel channel_assignment = channel.logical_channel_assignments.Assignment() ## mapping the logical channel and the client port channel_assignment.index = 1 channel_assignment_config = channel_assignment.Config() ## Defining the allocation of client speed into the line port channel_assignment_config.allocation = Decimal64('100') channel_assignment_config.assignment_type = channel_assignment.\ config.AssignmentTypeEnum.\ LOGICAL_CHANNEL ## defining the number of a line to be used for that client port ## the line is also indexed and will be defined later channel_assignment_config.logical_channel = j[2] channel_assignment.config = channel_assignment_config channel.logical_channel_assignments.assignment.append( channel_assignment) terminal_device.logical_channels.channel.append(channel) NUM = NUM + 1 ## Creation of the logical number(index) for the third client port of slice0 channel = terminal_device.logical_channels.Channel() ## indexing can be any, except 0. channel.index = 120 ## defining the Ethernet logical channel (speed, status, Eth mode) channel_config = channel.Config() channel_config.rate_class = oc_tr_types.Trib_Rate_100GIdentity() channel_config.admin_state = oc_tr_types.AdminStateTypeEnum.ENABLED channel_config.trib_protocol = oc_tr_types.Prot_100G_MlgIdentity() channel_config.logical_channel_type = oc_tr_types.Prot_EthernetIdentity() channel.config = channel_config ## mapping of the client physical port into the assigned logical number (index) channel_ingress = channel.Ingress() channel_ingress_tr = channel_ingress.Config() channel_ingress_tr.transceiver = '0/0-Optics0/0/0/2' channel_ingress.config = channel_ingress_tr channel.ingress = channel_ingress ## mapping the ethernet logical channel into the OTN logical channel ## with this mode half of the channel goes to the line 200 and second half ## goes to the line 201 for i in [0, 1]: channel_assignment = channel.logical_channel_assignments.Assignment() channel_assignment.index = 1 + i channel_assignment_config = channel_assignment.Config() ## Defining the allocation of client speed into line port channel_assignment_config.allocation = Decimal64('50') channel_assignment_config.assignment_type = channel_assignment.\ config.AssignmentTypeEnum.\ LOGICAL_CHANNEL ## defining the number of a line to be used for that client port ## the line is also indexed and will be defined later channel_assignment_config.logical_channel = 200 + i channel_assignment.config = channel_assignment_config channel.logical_channel_assignments.assignment.append( channel_assignment) terminal_device.logical_channels.channel.append(channel) ## Creation of the logical number (index) for the line ports of slice0 NUM = 200 for LINE in ['0/0-OpticalChannel0/0/0/5', '0/0-OpticalChannel0/0/0/6']: channel = terminal_device.logical_channels.Channel() channel.index = NUM ## OTN logical channel definition (OTN type, Enabled) channel_config = channel.Config() channel_config.admin_state = oc_tr_types.AdminStateTypeEnum.ENABLED channel_config.logical_channel_type = oc_tr_types.Prot_OtnIdentity() channel.config = channel_config ## defining the speed of that port channel_assignment = channel.logical_channel_assignments.Assignment() channel_assignment.index = 1 channel_assignment_config = channel_assignment.Config() channel_assignment_config.allocation = Decimal64('250') channel_assignment_config.assignment_type = channel_assignment.config.\ AssignmentTypeEnum.\ OPTICAL_CHANNEL ## and mapping into the optical channel channel_assignment_config.optical_channel = LINE channel_assignment.config = channel_assignment_config channel.logical_channel_assignments.assignment.append( channel_assignment) terminal_device.logical_channels.channel.append(channel) NUM = NUM + 1
def config_terminal_device(terminal_device): """ Add config data for correlation between client ports, logical channels and optical channels. "20x10G client -> 1x200G line" slice mode. In that mode in each client port is mapped to the single (second) line port. """ ## Define logical mapping between logical ethernet channels ## and logical OTN channels ## Creation of the logical number (index) for the client ports (4x10GE) ## of slice0 for j in [[0, '0/0-Optics0/0/0/0'], [10, '0/0-Optics0/0/0/1'], [20, '0/0-Optics0/0/0/2'], [30, '0/0-Optics0/0/0/3'], [40, '0/0-Optics0/0/0/4']]: NUM = 100 for i in range(1,5): channel = terminal_device.logical_channels.Channel() ## indexing can be any, except 0. channel.index = NUM + j[0] ## defining the Ethernet logical channel (speed, status, Eth mode) channel_config = channel.Config() channel_config.rate_class = oc_tr_types.Trib_Rate_10GIdentity() channel_config.trib_protocol = oc_tr_types.Prot_10Ge_LanIdentity() channel_config.logical_channel_type = oc_tr_types.Prot_EthernetIdentity() channel.config = channel_config ## mapping of the client physical port into the ## assigned logical number (index) channel_ingress = channel.Ingress() channel_ingress_tr = channel_ingress.Config() channel_ingress_tr.transceiver = j[1] channel_ingress_tr.physical_channel.append(i) channel_ingress.config = channel_ingress_tr channel.ingress = channel_ingress ## mapping the ethernet logical channel into the OTN logical channel channel_assignment = channel.logical_channel_assignments.Assignment() ## mapping the logical channel and the client port channel_assignment.index = 1 channel_assignment_config = channel_assignment.Config() ## Defining the allocation of client speed into the line port channel_assignment_config.allocation = Decimal64('10') channel_assignment_config.assignment_type = channel_assignment.\ config.AssignmentTypeEnum.\ LOGICAL_CHANNEL ## defining the number of a line to be used for that client port ## line is also indexed and will be defined later channel_assignment_config.logical_channel = 200 channel_assignment.config = channel_assignment_config channel.logical_channel_assignments.assignment.append(channel_assignment) terminal_device.logical_channels.channel.append(channel) NUM = NUM + 1 ## Creation of the logical number(index) for the line port of slice0 channel = terminal_device.logical_channels.Channel() channel.index = 200 ## OTN logical channel definition (OTN type, Enabled) channel_config = channel.Config() channel_config.admin_state = oc_tr_types.AdminStateTypeEnum.ENABLED channel_config.logical_channel_type = oc_tr_types.Prot_OtnIdentity() channel.config = channel_config ## defining the speed of that port channel_assignment = channel.logical_channel_assignments.Assignment() channel_assignment.index = 1 channel_assignment_config = channel_assignment.Config() channel_assignment_config.allocation = Decimal64('200') channel_assignment_config.assignment_type = channel_assignment.config.\ AssignmentTypeEnum.\ OPTICAL_CHANNEL ## and mapping into the optical channel channel_assignment_config.optical_channel = '0/0-OpticalChannel0/0/0/6' channel_assignment.config = channel_assignment_config channel.logical_channel_assignments.assignment.append(channel_assignment) terminal_device.logical_channels.channel.append(channel)
def config_terminal_device(terminal_device): """ Add config data for correlation between client ports, logical channels and optical channels. "2x100G client -> 2x100G line" slice mode. In that mode in each slice first client port is mapped to the first line port and last client port is mapped to the second line port. """ ## Define logical mapping between logical ethernet channels ## and logical OTN channels ## Creation of the logical number(index) for the client ports of slice0 NUM = 100 for CLIENT in ['0/0-Optics0/0/0/0', '0/0-Optics0/0/0/4']: channel = terminal_device.logical_channels.Channel() ## indexing can be any, except 0 channel.index = NUM ## defining the Ethernet logical channel (speed, status, Eth mode) channel_config = channel.Config() channel_config.rate_class = oc_tr_types.Trib_Rate_100GIdentity() channel_config.admin_state = oc_tr_types.AdminStateTypeEnum.ENABLED channel_config.trib_protocol = oc_tr_types.Prot_100G_MlgIdentity() channel_config.logical_channel_type = oc_tr_types.Prot_EthernetIdentity( ) channel.config = channel_config ## mapping of the client physical port into the ## assigned logical number (index) channel_ingress = channel.Ingress() channel_ingress_tr = channel_ingress.Config() channel_ingress_tr.transceiver = CLIENT channel_ingress.config = channel_ingress_tr channel.ingress = channel_ingress ## mapping the ethernet logical channel into the OTN logical channel channel_assignment = channel.logical_channel_assignments.Assignment() ## mapping the logical channel and the client port channel_assignment.index = 1 channel_assignment_config = channel_assignment.Config() ## Defining the allocation of client speed into the line port channel_assignment_config.allocation = Decimal64('100') channel_assignment_config.assignment_type = channel_assignment.\ config.AssignmentTypeEnum.\ LOGICAL_CHANNEL ## defining the number of a line to be used for that client port ## the line is also indexed and will be defined later channel_assignment_config.logical_channel = NUM + 100 channel_assignment.config = channel_assignment_config channel.logical_channel_assignments.assignment.append( channel_assignment) terminal_device.logical_channels.channel.append(channel) NUM = NUM + 1 NUM = 200 for LINE in ['0/0-OpticalChannel0/0/0/5', '0/0-OpticalChannel0/0/0/6']: ## Creation of the logical number (index) for the line ports of slice0 channel = terminal_device.logical_channels.Channel() channel.index = NUM ## OTN logical channel definition (OTN type, Enabled) channel_config = channel.Config() channel_config.admin_state = oc_tr_types.AdminStateTypeEnum.ENABLED channel_config.logical_channel_type = oc_tr_types.Prot_OtnIdentity() channel.config = channel_config ## defining the speed of the line channel_assignment = channel.logical_channel_assignments.Assignment() channel_assignment.index = 1 channel_assignment_config = channel_assignment.Config() channel_assignment_config.allocation = Decimal64('100') channel_assignment_config.assignment_type = channel_assignment.config.\ AssignmentTypeEnum.\ OPTICAL_CHANNEL ## and mapping into the optical channel channel_assignment_config.optical_channel = LINE channel_assignment.config = channel_assignment_config channel.logical_channel_assignments.assignment.append( channel_assignment) terminal_device.logical_channels.channel.append(channel) NUM = NUM + 1