Can I use two ciscoconfparse objects in a single Cisco IOS config file to get specific interfaces - python-3.x

Trying to use two of the conf objects find_objects_w_child &
find_objects_wo_child in a single file.
I need to find out "interfaces" from a Cisco config file which have a specific QoS "service-policy" command configured.
At the same time should not be a part of any Etherchannel.
Using object "find_objects_w_child" I can get all 'interface' objects having the command "service-policy" configured on it, and
Using object "find_objects_wo_child" to get all the 'interface' objects which do not have the command "channel-group".
Is it even possible to use these 2 objects on a same config file?

CiscoConfParse objects do not offer a method that allows you to find objects with specific children, but without other specific children. However, we can utilize a list comprehension to accomplish the same task with the IOSCfgLine object's re_search_children() method, as shown below:
from ciscoconfparse import CiscoConfParse
parse = CiscoConfParse("ios_cfg.txt")
phys_intfs_w_qos = [obj for obj in parse.find_objects_wo_child(r"^interface", "channel-group") if obj.re_search_children(r"service-policy")]
Because regex objects are truthy, the above list comprehension will only return IOSCfgLine objects representing interfaces that do not have channel-group configured, but does have service-policy configured.

Related

create dynamic object in GO operator controller

I am following the below blog which explains how to create operator and import another CR into existing one.
http://heidloff.net/article/accessing-third-party-custom-resources-go-operators/
here https://github.com/nheidloff/operator-sample-go/blob/aa9fd15605a54f712e1233423236bd152940f238/operator-application/controllers/application_controller.go#L276 , spec is created with hardcoded properties.
I want to import the spark operator types in my operator.
https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/blob/master/pkg/apis/sparkoperator.k8s.io/v1beta2/types.go
This spark operator is having say - 100+ types/properties. By following the above blog , i could create the Go object but it would be hardcoded. I want to create the dynamic object based on user provided values in CR YAML. e.g. - customer can provided 25 attributes , sometimes 50 for spark app. I need to have dynamic object created based on user YAML. Can anybody please help me out ?
If you set the spec type to be a json object, you can have the Spec contain arbitrary json/yaml. You don't have to have a strongly typed Spec object, your operator can then decode it and do whatever you want with it during your reconcile operation as long as its you as you can serialize and deserialize it from json. Should be able to set it to json.RawMesage I think?
What do you mean by hardcoded properties?
If I understood it correctly, you want to define an API for a resource which uses both types from an external operator and your customs. You can extend your API using the types from specific properties such as ScheduledSparkApplicationSpec from this. Here is an example API definition in Go:
type MyKindSpec struct {
// using external third party api (you need to import it)
SparkAppTemplate v1beta2.ScheduledSparkApplicationSpec `json:"sparkAppTemplate,omitempty"`
// using kubernetes core api (you need to import it)
Container v1.Container `json:"container,omitempty"`
// using custom types
MyCustomType MyCustomType `json:"myCustomType,omitempty"`
}
type MyCustomType struct {
FirstField string `json:"firstField,omitempty"`
SecondField []int `json:"secondField,omitempty"`
}

No MessageBodyWriter for Single

I'm trying to use resteasy-rxjava2 to provide an XML document using jaxb, within a vertx application (using a non-vertx legacy library we have). But I get:
Could not find MessageBodyWriter for response object of type:
org.jboss.resteasy.rxjava2.propagation.ContextPropagatorOnSingleAssemblyAction$ContextPropagatorSingle of media type:
application/xml;charset=UTF-8
From what I can tell, this comes down to the difference between a MessageBodyWriter and the AsyncResponseProvider that is in the resteasy-rxjava2 dependency for a Single (SingleProvider).
I have the following resteasy service definition
#GET
#Path(FdsnwsPaths.QUERY)
#Produces(MediaType.APPLICATION_XML)
#Stream
// CHECKSTYLE:OFF too many parameters
public Response getQuery(...)
How do I get resteasy to properly serve the data asynchrously, using the SingleProvider or otherwise.
The #Get method must return the Single explicitly or it doesn't work. (Can't use Response or Object). In my case, the Single contains the jaxb xml root element.
#GET
#Path(FdsnwsPaths.QUERY)
#Produces(MediaType.APPLICATION_XML)
#Stream
public Single<FDSNStationXML> getQuery(...)
Then, to make things more complicated, in order to handle specific exception types and map them to specific response status codes, I have to create a custom ExceptionMapper which creates the Response object I used to be able to create directly in the method. (in resteasy-vertx, I found no documentation on how to do this, but in my case, I am creating my own VertxRestEasyDeployment object so I can register the class of the ExceptionMapper(s) like this:
VertxResteasyDeployment deployment = new VertxResteasyDeployment();
deployment.getActualProviderClasses().addAll(providerClasses);
For reference, this is all being done with:
RestEasy 5.0.3.Final (including resteasy-rxjava2)
RxJava 2.2.20
Vertx 3.9.5

How to create an array of interface of different size in system verilog

I have a configurable module which contains an interface for one of the ports. I use a generate statement and a for loop to create different configuration of each module instance and I bring the interface ports out in an array. My issue is the individual interfaces are different based of the config of each module instance. Is there a way to configure each interface in the array individually? This is how I correctly configure the interface
test_if #(.NUM_CUTS(NUM_CUTS_WRITE_CLIENT),.AW(AW_WRITE_CLIENT),.DW(DW_WRITE_CLIENT)) mem_test_if [NUM_OF_MEMS-1:0]();
Is it possible to do something like this with an array of interfaces
test_if #(.NUM_CUTS(2),.AW(AW_WRITE_CLIENT),.DW(DW_WRITE_CLIENT)) mem_test_if [0]();
test_if #(.NUM_CUTS(4),.AW(AW_WRITE_CLIENT),.DW(DW_WRITE_CLIENT)) mem_test_if [1]();
test_if #(.NUM_CUTS(6),.AW(AW_WRITE_CLIENT),.DW(DW_WRITE_CLIENT)) mem_test_if [2]();
I don't want to have to instantiate each module instance separately outside of the generate statement.
You should be able to do this nested inside your generate
for(genvar MEM=0;MEM<NO_OF_MEMS;MEM++) begin : ID
test_if #(.NUM_CUTS((MEM+1)*2),.AW(AW_WRITE_CLIENT),.DW(DW_WRITE_CLIENT)) mem_test_if();
end

Any reason Origen::Parameter set contexts are hidden from the user?

Is there any reason the Origen::Parameters sets do not have a public method for retrieving all of the possible set ids? I do see a public method that works, though it isn't named like it is meant to be used publicly. Why is this not more visible?
[6] pry(#<PPEKit::Product>)> $dut.func._parameter_sets.ids
=> [:default,
:func_default,
:func_harvest_default,
EDIT
#Ginty, I tried your suggestion but it doesn't return the keys I am looking for. In the first sentence in the Parameter docs, the keys I am looking for are referred to 'parameter contexts'. The reason these would be useful would be to do something like this:
my_param_key = :my_param_key
if Origen.top_level.func.has_context? my_param_key
...
Specifically, I am creating parameter contexts from the information in my flow file and would like to verify that they exist before trying to access them. Essentially it is a handshake between my test flow and the test method parameters I am storing using unique (hopefully) parameter IDs/contexts.
thx
In your example, dut.func.params should return a hash-like object which contains all the parameter sets, so to get the IDs is just: dut.func.params.keys
EDIT
I see now that you want a collection containing the available contexts, but it doesn't seem like that is currently provided via an API.
I don't think there is any particular reason for that, probably hasn't been needed until now.
params.context returns the currently active context, I would recommend we add params.contexts and/or params.available_contexts to return an array of the available context names.
Origen now supports knowing the available parameter contexts.

How to use UVM factory's set_inst_override_by_name to override sequence item

I have two sequence item class a_packet and its extended class called bad_packet.
By default, a_packet type is used.
Trying to override a_packet instance with bad_packet, I am able to do it successfully by using set_inst_override_by_name in my uvm test,
factory.set_inst_override_by_name("a_packet","bad_packet", "*");
Now my question is: what if I don't want to use "*", how to know the full hierarchical path of the sequence item instance?
I was trying to utilise get_full_name() from inside the sequence item, right after it is received by the driver, to know the exact hierarchical path. It displayed:
uvm_test_top.env.a_agt.a_seqr.a_sequence.a_packet
But when I replaced the * with above path, the overriding is not happening.
factory.set_inst_override_by_name("a_packet","bad_packet","uvm_test_top.env.a_agt.a_seqr.a_sequence.a_packet");
Did I do something wrong?
Where you create your packet, you'll need to to specify the full path to the corresponding call to create(..):
packet = a_packet::type_id::create("packet", , get_full_name());
If you were using the uvm_do macro, you'll have to change to using the explicit sequence API:
packet = a_packet::type_id::create("packet", , get_full_name());
start_item(packet);
// ... randomize ...
finish_item(packet);
Idea is from this DVCon Paper, section IV.A.

Resources