Ejemplo n.º 1
0
    def update(self, provider, entity):
        """ Update the entity

            Args:
               - provider: An instance of ydk.providers.ServiceProvider
               - entity: An an entity class defined under the ydk.models package or subpackages

           Note:
               - A given member of an entity can be deleted by setting its attribute to an instance of ydk.types.Delete class.
               - An entity can only be updated if it exists on the server. Otherwise a YPYServiceError will be raised

           Returns:
                 None

           Raises:
              `YPYModelError <ydk.errors.html#ydk.errors.YPYModelError>`_ if validation failed.
              `YPYServiceError <ydk.errors.html#ydk.errors.YPYServiceError>`_ if other error has occurred. Possible errors could be a service side error
              or if there isn't enough information in the entity to prepare the message (missing keys for example)

        """
        # first read the object
        if None in (provider, entity):
            self.service_logger.error('Passed in a None arg')
            err_msg = "'provider' and 'entity' cannot be None"
            raise YPYServiceError(error_msg=err_msg)
        if self._entity_exists(provider, entity):
            # read has succeeded so do an edit-config
            MetaService.normalize_meta(provider._get_capabilities(), entity)
            self._execute_crud_operation_on_provider(provider, entity, 'UPDATE', False)
Ejemplo n.º 2
0
    def update(self, provider, entity):
        """ Update the entity 

            Args:
               - provider: An instance of ydk.providers.ServiceProvider
               - entity: An an entity class defined under the ydk.models package or subpackages

           Note:
               - A given member of an entity can be deleted by setting its attribute to an instance of ydk.types.Delete class.
               - An entity can only be updated if it exists on the server. Otherwise a YPYError will be raised

           Returns:
                 None

           Raises:
              `YPYDataValidationError <ydk.errors.html#ydk.errors.YPYDataValidationError>`_ if validation failed.
              `YPYError <ydk.errors.html#ydk.errors.YPYError>`_ if other error has occurred. Possible errors could be a service side error
              or if there isn't enough information in the entity to prepare the message (missing keys for example)
                  
        """
        # first read the object
        if self._entity_exists(provider, entity):
            # read has succeeded so do an edit-config
            MetaService.normalize_meta(provider._get_capabilities(), entity)
            self._execute_crud_operation_on_provider(provider, entity,
                                                     'UPDATE', False)
Ejemplo n.º 3
0
    def read(self, provider, read_filter, only_config=False):
        """ Read the entity or entities
            
            Args:
                - provider: An instance of ydk.providers.ServiceProvider
                - read_filter: A read_filter is an instance of an entity class.
                
                         An entity class is a class defined under the ydk.models package that is not an Enum , Identity of subclass of FixedBitsDict) .
                         Attributes of this entity class may contain values that act as match expressions or can be explicitly marked as to be read by assigning an instance of ydk.types.READ class to them.
                
                - only_config: Flag that indicates that only data that represents configuration data is to be fetched.
                        
                            Default is set to False i.e. both oper and config data will be fetched.
                
           Returns:
                 The entity or entities as identified by the read_filter.
        
           Raises:
              `YPYDataValidationError <ydk.errors.html#ydk.errors.YPYDataValidationError>`_ if validation failed.
              `YPYError <ydk.errors.html#ydk.errors.YPYError>`_ if other error has occurred. Possible errors could be
                  - a server side error
                  - if there isn't enough information in the entity to prepare the message (missing keys for example)
                  - if the type to be returned cannot be determined.
                  
        """
        MetaService.normalize_meta(provider._get_capabilities(), read_filter)
        self._perform_read_filter_check(read_filter)
        payload = self._execute_crud_operation_on_provider(
            provider, read_filter, 'READ', only_config)

        return provider.decode(payload, read_filter)
Ejemplo n.º 4
0
    def read(self, provider, read_filter, only_config=False):
        """ Read the entity or entities

            Args:
                - provider: An instance of ydk.providers.ServiceProvider
                - read_filter: A read_filter is an instance of an entity class.

                         An entity class is a class defined under the ydk.models package that is not an Enum , Identity of subclass of FixedBitsDict) .
                         Attributes of this entity class may contain values that act as match expressions or can be explicitly marked as to be read by assigning an instance of ydk.types.READ class to them.

                - only_config: Flag that indicates that only data that represents configuration data is to be fetched.

                            Default is set to False i.e. both oper and config data will be fetched.

           Returns:
                 The entity or entities as identified by the read_filter.

           Raises:
              `YPYModelError <ydk.errors.html#ydk.errors.YPYModelError>`_ if validation failed.
              `YPYServiceError <ydk.errors.html#ydk.errors.YPYServiceError>`_ if other error has occurred. Possible errors could be
                  - a server side error
                  - if there isn't enough information in the entity to prepare the message (missing keys for example)
                  - if the type to be returned cannot be determined.

        """
        if None in (provider, read_filter):
            self.service_logger.error('Passed in a None arg')
            err_msg = "'provider' and 'read_filter' cannot be None"
            raise YPYServiceError(error_msg=err_msg)
        MetaService.normalize_meta(provider._get_capabilities(), read_filter)
        self._perform_read_filter_check(read_filter)
        payload = self._execute_crud_operation_on_provider(provider, read_filter, 'READ', only_config)

        return provider.decode(payload, read_filter)
Ejemplo n.º 5
0
    def execute_rpc(self, provider, rpc):
        """ Execute the RPC
        
            Args:
                provider: An instance of ydk.providers.ServiceProvider
                rpc: An instance of an RPC class defined under the ydk.models package or subpackages

           Returns:
                 None
        
           Raises:
              `YPYDataValidationError <ydk.errors.html#ydk.errors.YPYDataValidationError>`_ if validation.
              `YPYError <ydk.errors.html#ydk.errors.YPYError>`_ if other error has occurred. Possible errors could be 
                  - a server side error
                  - if there isn't enough information in the entity to prepare the message (missing keys for example)
        """
        try:
            rpc = MetaService.normalize_meta(provider.get_capabilities(), rpc)
            return self.execute_payload(
                                        provider,
                                        '',
                                        provider.sp_instance.encode_rpc(rpc)
                                        )
        finally:
            self.executor_logger.info('Netconf operation completed')
Ejemplo n.º 6
0
    def execute_rpc(self, provider, rpc):
        """ Execute the RPC

            Args:
                provider: An instance of ydk.providers.ServiceProvider
                rpc: An instance of an RPC class defined under the ydk.models package or subpackages

           Returns:
                 None

           Raises:
              `YPYModelError <ydk.errors.html#ydk.errors.YPYModelError>`_ if validation.
              `YPYServiceError <ydk.errors.html#ydk.errors.YPYServiceError>`_ if other error has occurred. Possible errors could be
                  - a server side error
                  - if there isn't enough information in the entity to prepare the message (missing keys for example)
        """
        if None in (provider, rpc):
            self.service_logger.error('Passed in a None arg')
            err_msg = "'provider' and 'rpc' cannot be None"
            raise YPYServiceError(error_msg=err_msg)
        try:
            rpc = MetaService.normalize_meta(provider._get_capabilities(), rpc)
            return provider.execute(
                                    provider.sp_instance.encode_rpc(rpc),
                                    ''
                                    )
        finally:
            self.service_logger.info('Netconf operation completed')
Ejemplo n.º 7
0
    def delete(self, provider, entity):
        """ Delete the entity 
        
            Args:
                provider: An instance of ydk.providers.ServiceProvider
                entity: An an entity class defined under the ydk.models package or subpackages
                
           

           Returns:
                 None
        
           Raises:
              `YPYDataValidationError <ydk.errors.html#ydk.errors.YPYDataValidationError>`_ if validation failed. 
              `YPYError <ydk.errors.html#ydk.errors.YPYError>`_ if other error has occurred. Possible errors could be a service side error
              or if there isn't enough information in the entity to prepare the message (missing keys for example)
                  
        """
        MetaService.normalize_meta(provider._get_capabilities(), entity)
        self._execute_crud_operation_on_provider(provider, entity, 'DELETE', False)
Ejemplo n.º 8
0
    def delete(self, provider, entity):
        """ Delete the entity 
        
            Args:
                provider: An instance of ydk.providers.ServiceProvider
                entity: An an entity class defined under the ydk.models package or subpackages
                
           

           Returns:
                 None
        
           Raises:
              `YPYDataValidationError <ydk.errors.html#ydk.errors.YPYDataValidationError>`_ if validation failed. 
              `YPYError <ydk.errors.html#ydk.errors.YPYError>`_ if other error has occurred. Possible errors could be a service side error
              or if there isn't enough information in the entity to prepare the message (missing keys for example)
                  
        """
        MetaService.normalize_meta(provider._get_capabilities(), entity)
        self._execute_crud_operation_on_provider(provider, entity, 'DELETE',
                                                 False)
Ejemplo n.º 9
0
    def delete(self, provider, entity):
        """ Delete the entity

            Args:
                provider: An instance of ydk.providers.ServiceProvider
                entity: An an entity class defined under the ydk.models package or subpackages



           Returns:
                 None

           Raises:
              `YPYModelError <ydk.errors.html#ydk.errors.YPYModelError>`_ if validation failed.
              `YPYServiceError <ydk.errors.html#ydk.errors.YPYServiceError>`_ if other error has occurred. Possible errors could be a service side error
              or if there isn't enough information in the entity to prepare the message (missing keys for example)

        """
        if None in (provider, entity):
            self.service_logger.error('Passed in a None arg')
            err_msg = "'provider' and 'entity' cannot be None"
            raise YPYServiceError(error_msg=err_msg)
        MetaService.normalize_meta(provider._get_capabilities(), entity)
        self._execute_crud_operation_on_provider(provider, entity, 'DELETE', False)
Ejemplo n.º 10
0
    def execute_rpc(self, provider, rpc):
        """ Execute the RPC
        
            Args:
                provider: An instance of ydk.providers.ServiceProvider
                rpc: An instance of an RPC class defined under the ydk.models package or subpackages

           Returns:
                 None
        
           Raises:
              `YPYDataValidationError <ydk.errors.html#ydk.errors.YPYDataValidationError>`_ if validation.
              `YPYError <ydk.errors.html#ydk.errors.YPYError>`_ if other error has occurred. Possible errors could be 
                  - a server side error
                  - if there isn't enough information in the entity to prepare the message (missing keys for example)
        """
        try:
            rpc = MetaService.normalize_meta(provider._get_capabilities(), rpc)
            return provider.execute(provider.sp_instance.encode_rpc(rpc), '')
        finally:
            self.service_logger.info('Netconf operation completed')
Ejemplo n.º 11
0
 def _encode_entity(entity, encoder):
     MetaService.normalize_meta([], entity)
     payload = encoder._encode(entity)
     return payload
Ejemplo n.º 12
0
 def encode(self, encoder, entity):
     assert encoder is not None, 'Encoder should be valid object'
     MetaService.normalize_meta([], entity)
     return encoder.encode(entity)
Ejemplo n.º 13
0
 def encode(self, encoder, entity):
     assert encoder is not None, 'Encoder should be valid object'
     MetaService.normalize_meta([], entity)
     payload = encoder._encode(entity)
     self.service_logger.info('Encoding operation completed\n')
     return payload