PyEZ: RPC: Get route info for specific grandchild element - rpc

I want to get wia RPC info like this:
> show route output interface ae40.4181 | display xml rpc
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/17.4R2/junos">
<rpc>
<get-route-information>
<output>
<interface>ae40.4181</interface>
</output>
</get-route-information>
</rpc>
<cli>
<banner></banner>
</cli>
</rpc-reply>
How shloud I pass these parameters to dev.rpc.get_route_information?
Which are other possible ways to get this info?

try using dev.execute for this case
for example
rpc = '''<get-route-information>
<output><interface>ae40.4181</interface>
</output>
</get-route-information>'''
dev.execute(rpc)
let me know if you face any issue

Related

How to parse and edit XML in TypeScript without converting to JSON

I need to repair an XML file in TypeScript and I cannot find any info on it, since everyone who posts something like this has different needs. I'd like to be pointed in the right direction here.
I have an XML request as shown below. It is autogenerated by node-soap when given JSON. Using the WSDL, node-soap attempts to fill in the namespace prefixes for each property. The problem is, it gets them wrong a lot.
In this example below, q106 should be replaced with hep3.
<soap:Envelope q15="some-good-url" q106="some-good-url-1" q98-"some-good-url-2>
...
<q98:SalesOrderAuditInfo>
<q15:ConfirmedBy xsi:nil="true"></q15:ConfirmedBy>
<q15:ConfirmedDate>0001-01-01T00:00:00</q15:ConfirmedDate>
<q15:CreatedBy>
<q106:ID>103</q106:ID>
<q106:Value>System, System</q106:Value>
</q15:CreatedBy>
<q15:CreatedDate>2022-10-26T00:43:13.413</q15:CreatedDate>
<q15:SalesOrderType>Standard</q15:SalesOrderType>
</q98:SalesOrderAuditInfo>
I know which namespace prefixes are bad because I have a sample request that was supplied to me. It's just XML. It looks like this:
<soap:Envelope hep="some-good-url" hep1="some-good-url-1" hep2-"some-good-url-2 hep3="some-good-url-3">
...
<hep2:SalesOrderAuditInfo>
<hep:ConfirmedBy xsi:nil="true"></hep:ConfirmedBy>
<hep:ConfirmedBy:ConfirmedDate>0</hep:ConfirmedByConfirmedDate>
<hep:CreatedBy>
<hep3:ID>103</hep3:ID>
<hep3:Value>System, System</hep3:Value>
</hep:CreatedBy>
<hep:CreatedDate>0</hep:CreatedDate>
<hep:SalesOrderType>Standard</hep:SalesOrderType>
</hep2:SalesOrderAuditInfo>
Here is the part that really matters. The Sample Request is the entire possible request body. The supplied request (with incorrect namespaces) is a subset of the sample request. I need to loop through each of the elements in the supplied request, and check to make sure the URL of that element matches the URL of the respective element in the sample request.
So in this example, loop through each element of supplied request. Start with SalesOrderAuditInfo. It's namespace URL is some-good-url-2. If we check the Sample Request, we can see that SalesOrderAuditInfo also corresponds to some-good-url-2.
Continue until we hit the ID tag. This has a namespace set to some-good-url-1. If we check the Same ID (inside of CreatedBy, inside of SalesOrderAuditInfo), we can see the namespace should actually be set to some-good-url-3. So we replace q106 with hep3.
I also need to take all of the namespaces defined in the Sample Request Envelope and move them into the supplied request envelope so that this new hep3 will be defined.
At this point, I need to edit the namespace prefix. In this example, q106:ID would be replaced be the string hep3:ID. Same with all of the closing tags.
Which library can I use to accomplish this in XML? Is anyone familiar with node-soap screwing these namespaces up and know of any fix?
I am using node-soap v0.43

Can't specify AS_PATH attribute in BGP packet [Scapy]

When using Scapy, I am unable to set the AS_PATH attribute. I have tried following the answer provided in this StackOverflow page How to use AS_PATH attribute in scapy for BGP?, but it did not work. I have also tried inputting the following statements in the attribute parameter, but I have not been able to.
setAS=BGPPathAttr(type_flags="Transitive", type_code="AS_PATH", attribute="2")
setAS=BGPPathAttr(type_flags="Transitive", type_code="AS_PATH",attr_len=None,attribute=BGPPAAS4BytesPath(segments=BGPPAAS4BytesPath().ASPathSegment(segment_type=2,segment_length=None,segment_value=[2])))
My desired outcome is to send a packet with the AS_PATH value of 2.
AS_PATH is well-known mandatory, not transitive.

Best way to validate DICOM connection request with pynetdicom

What is the preferred way to validate requested DICOM connection against a list of known hosts?
I can connect to the EVT_CONN_OPEN event. But in that, the event.assoc.requestor.info.ae_title element is always empty (b'').
I see from a TCP network analysis, that the name is transmitted. So, where is it?
What is the right way to validate the requesting host?
You could try using EVT_REQUESTED instead, it gets triggered after an association request is received/sent and the AE title information should be available at that point. Unfortunately EVT_CONN_OPEN is triggered on TCP connection which occurs prior to the association request.
If you don't like the host's details you can use the handler to send an association rejection message using event.assoc.acse.send_reject() or abort with event.assoc.abort().
If you're only interested in validating against the AE title you can use the AE.require_calling_aet property to restrict associations to those with matching AE titles.
For the benefit of anyone else looking this up, the correct stage to look this up is in the EVT_REQUESTED event. However you will likely find the details aren't filled in (they are populated AFTER the handler has been called).
So if you want to locate the callers AE in EVT_REQUESTED, you need to locate the A_ASSOCIATE primitive and read them from there. So for example in your handler you can do this to reject remotes:
def handle_request(event):
req_title = event.assoc.requestor.primitive.calling_ae_title.decode('ascii')
if req_title != 'MyAET':
event.assoc.acse.send_reject(0x01, 0x01, 0x03)
return
At least for 1.5.7.

#SNMP No contextName in V3 response

We are using #SNMP to created an SNMP V3 agent.
I would like to know if it is normal that the SecureSnmpContext class does not use the given ContextName when using GeneratedResponse for example ?
The ContextName is available into the request object ?
In the code, OctetString.Empty is used instead of ContextName.
new Scope(Group.EngineId,
OctetString.Empty,
new ResponsePdu(
Request.RequestId(),
ErrorCode.NoError,
0,
variables)),
Is the ContextName not required in the response maybe ?
Thanks
The design of the snmpd sample follows Net-SNMP agent, which does not use the context name much.
If you have requirements to set that field, feel free to modify the code base to suit your needs please.
Remember that you also need to modify the authentication part to verify context name of the incoming messages if you do set a context name.

Iterating DSS response in BPEL (WSO2 BPS)

I am using WSO2 BPS and WSO2 DSS.
DSS has 2 services as below:
(1) Returns list of status and
(2) Inserts a record into table.
I succeeded invoking both the DSS services from BPEL Workflow. But I need to achieve the following thing.
My 1st DSS will return "List of Status". I have to iterate(using 'forEach' or 'while' or ...) that response and pick particular node(StatusDescription) from it and use it for the next DSS call. My 1st DSS response is below.
<Response xmlns="http://ws.wso2.org/dataservice">
<Status>
<StatusId>1</StatusId>
<StatusDescription>Active</StatusDescription>
</Status>
<Status>
<StatusId>2</StatusId>
<StatusDescription>Inactive</StatusDescription>
</Status>
</Response>
Can anyone suggest some tutorial or code snippet that would iterate through above DSS response? i.e, My bpel:finalCounterValue will be '2' as there are 2 'Status' nodes in the above XML.
Thanks in Advance.
I found the the way to iterate the nodes. Please find the code snippet below.
<bpel:forEach parallel="no" counterName="Counter" name="ForEach">
<bpel:startCounterValue>
<![CDATA[1]]>
</bpel:startCounterValue>
<bpel:finalCounterValue>
<![CDATA[count($GetStatusPLResponse.parameters/ns:Status)]]>
</bpel:finalCounterValue>
<bpel:scope>
<!-- Some activity goes here. Say Assign or Invoke or .... -->
</bpel:scope>
</bpel:forEach>
The count method available under the namespace xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable" helps us to find count of nodes('Status').
The count method returns the value '2' and so 'forEach' iterates twice.
Have Happy Learning.

Resources