How to get route table/acl content using boto? - boto

I'm trying to get the contents of route table and acl like Destination, target...etc using boto. i'm able to fetch the IDs not the content, Please suggest a way to resolve this.

To retrieve the data you need to follow the following steps :
First import VPC CONNECTION which is
from boto.vpc import VPCConnection
Connect to the region you want
conn=boto.vpc.connect_to_region("ap-southeast-1")
Now get all the route tables in an object using the conn object you made. This object will return a list of route tables.
c=conn.get_all_route_tables()
c has objects of class RouteTable , which further has 1 data member of class Route . From that data member you need to retrieve the details :
for c1 in c:
for a in c1.routes:
print a.destination_cidr_block
print a.instance_id
print a.gateway_id
print a.state
print a.dry_run
If you are getting confused in point 4 , you can see here : http://pydoc.net/Python/boto/2.1.1/boto.vpc.routetable/
Hope it helps !

Related

Merging two JSON Objects in Node-Red

I am having some trouble trying to merge two JSON objects retrieved from my SQL Server database into a single object in Node-Red.
The flow I have created is the following:
For each call to the database I am receiving the following objects:
Plans:
[{"PlanID":2,"Status":0,"EndTime":"0001-01-01T00:00:00.000Z"}]
Goals:
[{"GoalID":1,"PlanID":2, "Type":2,"Message":"Walk 1000 km","Difficulty":0}]
I have created two functions which assign these objects into flow variables ('plans' and 'goals'), and now I was trying to merge both objects into a single JSON object.
I don't know if I have to use the Join node for this purpose and if so how to configure it, but my idea was to create a JSON object in this format:
[{"GoalID":1,"Plan":{"PlanID":2,"Status":0,"EndTime":"0001-01-01T00:00:00.000Z"}, "Type":2,"Message":"Walk 1000 km","Difficulty":0}]
First I wouldn't set them as flow variables as these will get over written if you get a second request in to the http-in node while the Database look ups are happening. Better to add them as msg variables then they flow with the msg and can't be overwritten.
Given you are not just combining the 2 objects to get the super set of keys and values you are probably best off just using either a function node or the change to assemble to the output object yourself.
Assuming the input looks something like:
msg.plans = [{"PlanID":2,"Status":0,"EndTime":"0001-01-01T00:00:00.000Z"}]
msg.goals = [{"GoalID":1,"PlanID":2, "Type":2,"Message":"Walk 1000 km","Difficulty":0}]
then the function node would look something like:
msg.payload = msg.goals[0];
msg.payload.plan = msg.plans[0];
delete msg.goals;
delete msg.plans;
return msg;
The change node rules would looks something like
The join node would work to get the 2 objects into an array or an object using the topics as keys to hold the 2 input messages.

How to filter data using angular 4 route params

Can anybody please explain how I can use Angular (4) route params to filter a JSON object to only return 1 record (so I only want to show more specific details, bit like an admin panel). All the examples I've seen just seem to show you how to console.log the param id from the url and don't really go much further (or if they do it isn't explained as clearly as I would like).
What I want to do is I have a JSON object say
{id: 1, name:"Dave"}, {id:2, name: "Steve"}
How can I use the route param in a service to show only the name based upon the id I pass in the url?
name/1
So this example would give me access to the first set of records.
Thanks

Adding query Parameters to Go Json Rest

I am using the library go-json-rest. I'm trying to recognize queries parameters in the code for example localhost:8080/reminders?hello=world I want to access {hello: world} . I have the following code:
//in another function
&rest.Route{"GET", "/reminders", i.GetAllReminders},
func (i *Impl) GetAllReminders(w rest.ResponseWriter, r *rest.Request) {
reminders := []Reminder{}
i.DB.Find(&reminders)
w.WriteJson(&reminders)
}
I know that r.PathParams holds the url parameters but I cannot seem to find how to the query parameters past the "?" in the url.
Given that go-json-rest is a thin wrapper on top of net/http, have you looked at that package's documentation? Specifically, the Request object has a field Form that contains a parsed map of query string values as well as POST data, that you can access as a url.Values (map[string][]string), or retrieve one in particular from FormValue.

How to access all the entries in MySQL table in Django View?

I am designing a Web Application using Django Framework. I have written the model code, urls.py and view code which can be seen Here.
I have added some data into the database table. But when I try to access the object using the code below, it just shows bookInfo objects five times. I don't think I am successful enough in pulling the data from the database. Kindly help.
View
def showbooks(request):
booklist = bookInfo.objects.order_by('Name')[:10]
output = ','.join([str(id) for id in booklist])
return HttpResponse(output)
You are iterating through the object list, you just need to reference the column/attribute you want:
output = ','.join([obj.id for obj in booklist])
Alternatively you can more more finely craft you original db call, then the iterable you use will work. In this case we'll pull out a list of the 'id' attribute.
booklist = bookInfo.objects.order_by('Name').values_list('id', flat=True)[:10]
output = ','.join([id for id in booklist])
I think you are successful in pulling the data. It is just that booklist contains objects, not numeric ids. You can add __unicode__ method to you class BookInfo that is supposed to return a string representation of the object (probably book name in this case). This method is going to be invoked when str() is applied. You can find more info about __unicode__ here.

CakePHP Accessing Dynamically Created Tables?

As part of a web application users can upload files of data, which generates a new table in a dedicated MySQL database to store the data in. They can then manipulate this data in various ways.
The next version of this app is being written in CakePHP, and at the moment I can't figure out how to dynamically assign these tables at runtime.
I have the different database config's set up and can create the tables on data upload just fine, but once this is completed I cannot access the new table from the controller as part of the record CRUD actions for the data manipulate.
I hoped that it would be along the lines of
function controllerAction(){
$this->uses[] = 'newTable';
$data = $this->newTable->find('all');
//use data
}
But it returns the error
Undefined property:
ReportsController::$newTable
Fatal error: Call to a member function
find() on a non-object in
/app/controllers/reports_controller.php
on line 60
Can anyone help.
You need to call $this->loadModel('newTable') to initialize it properly. Cake needs to initialize $this->newTable properly, and call all the callbacks.
Of course, you don't need $this->uses[] = 'newTable';, that doesn't do anything except add another value to the $uses array.
try:
function controllerAction() {
$data = ClassRegistry::init('ModelNameForNewTable')->find('all');
}
If your table is called 'new_tables', your model name should be 'NewTable'