Showing posts from January, 2016

[Python] How to get key and value from a custom header or from a form data with django rest framework

The following python code is part of handling a post method of my Restful API. I only excerpt it because I want to only hightlight my experiment of dealing with key and value from a custom HTTP header or from a form data.

""" Deal with the header property """ header_property_kwargs = {} for field in request.META: logger.debug("...[Testing]...field,value==> %s,%s" % (field, request.META[field])) if'HTTP_X_EXTRA_PROPERTY_'in field: new_field = field.replace('HTTP_X_EXTRA_PROPERTY_','').lower() header_property_kwargs[new_field] = request.META[field] logger.debug("...[Testing]...header_properties==> %s" % header_property_kwargs) """ Deal with the extra_property """ extra_property_kwargs = {} if'extra_property'in request.DATA.keys(): extra_property = request.DATA['extra_property'] try: property_list = extra_property.spli…

[Python] The a little thing about argument and kwargs
You can use **kwargs to let your functions take an arbitrary number of keyword arguments: >>>def print_keyword_args(**kwargs):...# kwargs is adict of the keyword args passed to the function...for key, value inkwargs.iteritems():...print"%s = %s"%(key, value)...>>> print_keyword_args(first_name="John", last_name="Doe") first_name =John last_name =DoeYou can also use the **kwargs syntax when calling functions by constructing a dictionary of keyword arguments and passing it to your function:

[Neutron] The Neutron Networking trace records

This article maybe is not given too much explanation or description about the script and result is because it is my trace record for my study from my OpenStack environment, which is based on the following references:

This picture is quite important because it tells the neutron networking architecture clearly.

So, I have a VM/instance, which is "mi--lbod6yoctnm3-0-jbcgnagn4dck-instance-xvti2docwkl4" and we can get

> nova --os-tenant-name danny list
| ID                                   | Name                                                  | Status | Task State | Power State | Netw…