opendaylight: How to view config database - openflow

I am using OpenDaylight Carbon release and the openflow plugin. I am writing code to install a flow. The flow gets written to MDSAL and picked up and installed by the Southbound plugin. I want to see what is in the config database for the switch. How can I do this? Thanks.

With the MDSAL Openflow plugin (and general MDSAL usage overall), the flows get written to the config datastore (which is effectively the intention of what you want) then if there is a switch connected for these flows, the flows will be written to the switch and to the operational data store (which is where the result is stored).
Lets assume you're using OVS and have set the manager and controller to Opendaylight, you can query the flows in the config and operational data stores as follows:
Get the OVS datapath ID:
(needed below in the queries)
curl -H "Content-Type: application/json" -X GET --user admin:admin http://localhost:8181/restconf/config/opendaylight-inventory:nodes/ | python -m json.tool | grep "openflow:"
"id": "openflow:156930464280132",
"id": "openflow:156930464280132:1",
"id": "openflow:156930464280132:LOCAL",
Query the flows in the configuration data store:
curl -H "Content-Type: application/json" -X GET --user admin:admin http://localhost:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:156930464280132 | python -m json.tool
Query the flows in the operational data store:
curl -H "Content-Type: application/json" -X GET --user admin:admin http://localhost:8181/restconf/operational/opendaylight-inventory:nodes/node/openflow:156930464280132 | python -m json.tool
Notice, you can go into more detail with the URL to get flows in specific tables, for instance, do this to get table 4 flows:
curl -H "Content-Type: application/json" -X GET --user admin:admin http://localhost:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:156930464280132/table/4 | python -m json.tool
Also notice that using "python -m json.tool" formats the output so its not all on one line. Its not mandatory to use.

Related

Using CURL to list github repository tree (github API)

Using the github API, you can get a repository tree using (example done with CURL):
curl -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/{owner}/{repo}/git/trees/{tree_sha}
Assuming I have a repo called dev by owner NewCo, and I want to list the repo tree called XXXX, I would:
curl -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/NewCo/dev/git/trees/{tree_sha}
How can I find out the {tree_sha} value for tree XXXX? Any idea where can I find out this value?
You can use a commit sha from the commits endpoint for that: /repos/{owner}/{repo}/commits. For example:
#!/usr/bin/env bash
set -e
owner=zacanger
repo=fetchyeah
sha=$(curl -s -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$owner/$repo/commits?per_page=1 \
| jq -r '.[0].sha')
curl -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$owner/$repo/git/trees/$sha
You could also use the pull requests API, or any other endpoint that returns commit info (meaning, most of them except for user and org APIs).

Can I get a working curl command to remove a system from RHEL subscription?

I want to automate the addition and removal of VMs from the RHEL Subscription. I want to use a curl command if possible and keep it simple.
I tried executing curl commands on the api.access.redhat.com/management/v1/subscriptions endpoints but it is giving errors like "Authentication parameters missing".
Below is an example command I am using:
curl -X GET -s -k -u username:Password "https://api.access.redhat.com/management/v1/subscriptions" -H "accept: application/json"
Expected to see the list of Subscribed systems but getting the "Authentication parameters missing" message.
In order to get all the subscriptions you have, run the following command:
curl -H "Authorization: Bearer $access_token" "https://api.access.redhat.com/management/v1/subscriptions"
You can retrieve the access_token variable by running the following command:
curl https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token -d grant_type=refresh_token -d client_id=rhsm-api -d refresh_token=$offline_token
The offline_token, instead, has to be generated from the API Tokens Page.
Check this article for further details.

Bamboo Trigger Deployment plan with variables

Im trying to deploy a plan that has artefacts from external service for this I want to download via curl those files that I will pass as variables... however I am not able to set programmaticly the variables with the deploymet call
curl -k -u user:passord -X POST -d "bamboo.myVariable=someurl" BASE_BAMBOO_URL/bamboo/rest/api/latest/queue/PROJECT-ID
Trying to do the same with the deployment API fails
curl BASE_BAMBOO_URL/bamboo/rest/api/latest/deploy/project/1321123123 -u user:passord-X POST -d "bamboo.myVariable=callMEwithDATA"
Trying to add that into the API fails as does trying to pass it thru JSON
curl -X POST BASE_BAMBOO/bamboo/rest/api/latest/deploy/project/1320058 -u user:passord -H "Accepts: application/json" -H "Content-Type: application/json" -d '{"name":"release-1", "myVariable":"ARTEFACT_URL"}'
To continue with a request the variables have to be passed as query params... a sad sad reality is that the Bamboo API is very messed up
bamboourl&executeAllStages=true&bamboo.variable.MYVAR=1234

Is there a solution to log all messages in rabbitmq but don't using rabbitmq_management?

I do know rabbitmq_tracing, which is a plugin of RabbitMQ, can provides a GUI to capture traced messages and log them in text or JSON format files. But the plugin is performance costing, is there a way to log all messages without this plugin?
Or is there a eclectic way to log messages automatically without using the management plugin? Because configuring traces on the GUI is not tolerant for some customers.
Any response would be appreciated.
I can't find a good solution to log all messages without rabbitmq_management. But with this plugin turned on, add and delete rabbitmq trace via command line:
Add a new trace:
[windows:] curl -i -u guest:guest -H "content-type:application/json" -XPUT ^ http://localhost:15672/api/traces/%2f/my-trace ^ -d"{""format"":""json"",""pattern"":""#"",""max_payload_bytes"":1000}"
[linux:] curl -i -u guest:guest -H "content-type:application/json" -XPUT \ http://localhost:15672/api/traces/%2f/my-trace \ -d'{"format":"text","pattern":"#", "max_payload_bytes":1000}'
Delete a trace:
[windows:] curl -i -u guest:guest -H "content-type:application/json" -XDELETE ^ http://localhost:15672/api/traces/%2f/my-trace
[linux:] curl -i -u guest:guest -H "content-type:application/json" -XDELETE \ http://localhost:15672/api/traces/%2f/my-trace

mule server auto deployment details

I am using mmc for deployment of mule based application. All deployed application through mmc goes to apps directory under mule server. If I put an application directly under mule-server/apps, launch the application, application runs successfully, but I am not able to view the deployment details in mmc. Where I need to make the changes in mule server to view the deployed application details in mmc?
I need to make a auto deployment through shell script. For this, I am creating a sample project, create zip file, copy this zip file under mule server apps direction. Finally, once mmc is launched, I need to see the deployed application in mmc for viewing flows, running application, flow analyzer etc.
EDIT
Based on answer given below to deploy a new application, I have given my url as:
curl --basic -u admin:admin -F file=#C:/apps/testserver-1.0.0-SNAPSHOT.zip -F name=test-app -F version=2.0 --header 'Content-Type: multipart/form-data' http://almule1.ux.corp.local:8585/mmc/api/repository
Response I received:
curl: (6) Could not resolve host: multipart {"versionId":"local$5015b8d6-b149-4245-a218-55c12aecc8e7","applicationId":"local$74616cb9-9ecb-4fd6-b167-bf153c8e59fb"}
I am using windows env to deploy in unix server.
MMC retrieves information from Mule ESB, so you shouldn't make any changes. Anyway I think that deploying an application outside MMC is not a good idea. For scripting purposes I would prefer to use MMC Deployments REST API. You can deploy an application by simply running:
Upload zipped application
This uploads your application to MMC.
curl --basic -u admin:admin -F file=#my-zipped-app.zip -F name=test-app -F version=2.0 --header 'Content-Type: multipart/form-data' http://localhost:8080/mmc/api/repository
List available servers
curl --basic -u admin:admin http://localhost:8080/mmc-console-3.4.0/api/servers
There you should get the server Id (let's suppose it is local$26f2fea8-3b7c-45a7-84a8-d1509e73fca4), then use it in this command:
Create deployment
Before starting your application you need to create a deployment telling MMC to which server, and the id of the uploaded application.
curl --basic -u admin:admin -d '{"name" : "ExampleDeployment" , "servers": [ "local$26f2fea8-3b7c-45a7-84a8-d1509e73fca4" ], "applications": [ "local$32bb47d3-d180-4bb9-8906-2378dad9ae21" ]}' --header 'Content-Type: application/json' http://localhost:8080/mmc/api/deployments
Perform deploy
Once you have a server and a deployment you can finally start the application.
curl --basic -u admin:admin -X POST 'http://localhost:8080/mmc/api/deployments/local$97e3c184-09ed-423e-a5a5-9b94713a9e36/deploy'
Here is the auto deployment on windows environment which deploys in Unix server.
Application Name: testserver-1.0.zip
step1: Upload
curl --basic -u admin:admin -F file=#C:/apps/testserver-1.0.zip -F name=auto-deploy-server -F version=1.0 --header "Content-Type: multipart/form-data" http://allmule1.ux.corp.local:8585/mmc/api/repository
Response:
{"versionId":"local$fd507b45-25c2-4cc9-afe9-9f020f685867","applicationId":"local$47bcf1f3-72bc-4c08-ba50-4fe33422199c"}
step2: Get server details:
curl --basic -u admin:admin http://allmule1.ux.corp.local:8585/mmc/api/servers
Response:
{"total":1,"data":[{"agents":[{......,"agentUrl":"https://localhost:7777/mmc-support","version":"3.4.2","name":"Mule-3.4.2","id":"local$5a6c4f81-7b35-425d-95bd-200224f60a2b"}]}
Note: Here server id is: local$5a6c4f81-7b35-425d-95bd-200224f60a2b
Get the VERSION ID (not application id) from step 1
step3: deployments
curl --basic -u admin:admin -d "{\"name\" : \"Auto-Deployment\" , \"servers\": [ \"local$5a6c4f81-7b35-425d-95bd-200224f60a2b\" ], \"applications\": [ \"local$fd507b45-25c2-4cc9-afe9-9f020f685867\" ]}" --header "Content-Type: application/json" http://allmule1.ux.corp.local:8585/mmc/api/deployments
Response:
{"applications":["local$fd...,"name":"Auto-Deployment","id":"local$9062bbe7-75ab-4658-b021-8314b1681511","lastModified":"Wed, 18 Jun 2014 12:27:30.610 PDT"}
Note here Deployment Id: local$9062bbe7-75ab-4658-b021-8314b1681511
Step4: Deploy
curl --basic -u admin:admin -X POST http://allmule1.ux.corp.local:8585/mmc/api/deployments/local$9062bbe7-75ab-4658-b021-8314b1681511/deploy
Response: The deployments were deployed
verify your server console, application might have deployed.
Redeploy
curl --basic -u admin:admin -X POST http://allmule1.ux.corp.local:8585/mmc/api/deployments/local$9062bbe7-75ab-4658-b021-8314b1681511/redeploy
Undeploy:
curl --basic -u admin:admin -X POST http://allmule1.ux.corp.local:8585/mmc/api/deployments/local$9062bbe7-75ab-4658-b021-8314b1681511/undeploy
Automated Deployment with Mule Management Console and Maven
https://dzone.com/articles/automated-deployment-mule?mz=38541-devops