Refactor rest-client for using one class for both types 'json' and 'xml'

Registered by Valeriy Ponomaryov

Current situation:
We have two rest-client classes, one for each container type - "json" and "xml".
Due to this structure, we need inherit for each service client different rest-clients,
it leads to write all service methods twice, even if it is the same.

The proposal is next:

Make one Rest-client class with conditions, where needed, for container type.
Dependencies for container type should be removed from __init__ method,
and placed to separate methods, which will read current value of TYPE option.

For example:

TYPE = 'json'

def _get_type(self):
    return self.TYPE

def get_headers(self):
    return {'Content-Type': 'application/%s' % self._get_type(),
                   'Accept': 'application/%s' % self._get_type()}

After that we can:
1) Create two service clients, where
2) json client inherits rest-client, and contains all service methods
3) xml client inherits json-client, redefines self.TYPE option and some methods, that are not similar.

In perfect case, we should have only several redefined methods, that decodes (parses) output and encodes request.

Finally, we can remove a lot of duplicated methods for each pair of service clients.

Blueprint information

Status:
Complete
Approver:
None
Priority:
Undefined
Drafter:
Valeriy Ponomaryov
Direction:
Needs approval
Assignee:
Valeriy Ponomaryov
Definition:
Approved
Series goal:
Proposed for icehouse
Implementation:
Implemented
Milestone target:
None
Started by
Valeriy Ponomaryov
Completed by
Valeriy Ponomaryov

Related branches

Sprints

Whiteboard

Gerrit topic: https://review.openstack.org/#q,topic:bp/refactor-rest-client,n,z

Addressed by: https://review.openstack.org/62923
    Refactor rest-client for using one class with 'json' and 'xml' types

Despite the initial work, merging is still going to cause lot of code duplication because of json/xml inconsistencies so this is closed (Dec 2013)

Addressed by: https://review.openstack.org/64948
    Refactor of nova server clients (v2)

-----------------------------

(vponomaryov): changed definition to 'new' instead 'obsolete' due to decision made on qa meeting (2014, jan 9)

Gerrit topic: https://review.openstack.org/#q,topic:bug/1269489,n,z

Addressed by: https://review.openstack.org/73869
    Remove using of deprecated self.headers (part1)

Addressed by: https://review.openstack.org/74090
    Remove using of deprecated self.headers (part2)

Addressed by: https://review.openstack.org/74954
    Removed RestClientXML class

(?)

Work Items

Work items:
Implement unified rest client: DONE
Remove usage of deprecated self.headers: DONE
Remove usage of deprecated xml-rest-client: DONE

This blueprint contains Public information 
Everyone can see this information.