corenova / yang-js

YANG parser and composer
Apache License 2.0
56 stars 18 forks source link

Schema binding #88

Closed kimguji closed 5 years ago

kimguji commented 5 years ago

When I tried to bind schema in this way, it worked well. e.g., 1

newType=Yang.parse(` namespace "urn:vnf:cache:ston"; prefix ston; import ietf-yang-types {prefix yang;} revision 2019-04-03; typedef access-type{ type enumeration { enum size; enum time; } } container Server { container Log{ leaf Dir { type string; description "log directory"; } container Access{ leaf Type { type access-type;

                    }
            }
    }
}

`

);
serverConf=newType({
    Server:{
        Log: {
          Dir: '/var/log/ston',
          Access: 'size'
        }
    }
}) ;   

//console.log(model);
console.log(serverConf.Server);

});

This binds schema very well. However, if I add schema includes 'module command', it doesn't work. For example, with same code above, put schema like ` module ston-config{ namespace "urn:vnf:cache:ston"; prefix ston; import ietf-yang-types {prefix yang;} revision 2019-04-03; typedef access-type{ type enumeration { enum size; enum time; } } container Server { container Log{ leaf Dir { type string; description "log directory"; } container Access{ leaf Type { type access-type;

                    }
            }
    }
}

} ` It doesn't work at all. I think most case the Yang module is read from file, it is embarrassing that it doesn't work when schema includes 'module $name'. If I do something wrong, please correct.

I tried another approach.

newType=Yang.parse(YangSchema).bind(); serverConf=newType({ 'ston-config:Server':{ Log: { Dir: '/var/log/ston', Access: 'size' } } }) ;
console.log(serverConfig.Server); It prints undefined.

I'm little bit confused here. Thanks in advance.

quantang commented 5 years ago

Hi @kimguji

I also got some problems with the latest version. I guess you can try yang-js@0.18.19, which is the version that works right now.

Cheers.

sekur commented 5 years ago

Hi @kimguji

When you parse/eval a module xxx schema, the return value is an instance of Model class instead of a native JS object.

In your example, the serverConf would be an instance of Model and you'd need to do something like:

console.log(serverConf.get('Server'));

Hope this helps.

Peter