Exemple #1
0
 def _req(self, method, resource, data=None, fmt='json', id=None):
     if id:
         path = '/%(resource)s/%(id)s.%(fmt)s' % locals()
     else:
         path = '/%(resource)s.%(fmt)s' % locals()
     content_type = 'application/%s' % fmt
     body = None
     if data:
         body = Serializer().serialize(data, content_type)
     return create_request(path, body, content_type, method)
Exemple #2
0
def new_network_request(tenant_id,
                        network_name='new_name',
                        format='xml',
                        custom_req_body=None):
    method = 'POST'
    path = "/tenants/%(tenant_id)s/networks.%(format)s" % locals()
    data = custom_req_body or {'network': {'name': '%s' % network_name}}
    content_type = "application/%s" % format
    body = Serializer().serialize(data, content_type)
    return create_request(path, body, content_type, method)
Exemple #3
0
def put_attachment_request(tenant_id,
                           network_id,
                           port_id,
                           attachment_id,
                           format='xml'):
    method = 'PUT'
    path = ("/tenants/%(tenant_id)s/networks/"
            "%(network_id)s/ports/%(port_id)s/"
            "attachment.%(format)s") % locals()
    data = {'attachment': {'id': attachment_id}}
    content_type = "application/%s" % format
    body = Serializer().serialize(data, content_type)
    return create_request(path, body, content_type, method)
Exemple #4
0
def update_port_request(tenant_id,
                        network_id,
                        port_id,
                        port_state,
                        format='xml',
                        custom_req_body=None):
    method = 'PUT'
    path = ("/tenants/%(tenant_id)s/networks"
            "/%(network_id)s/ports/%(port_id)s.%(format)s") % locals()
    data = custom_req_body or {'port': {'state': '%s' % port_state}}
    content_type = "application/%s" % format
    body = Serializer().serialize(data, content_type)
    return create_request(path, body, content_type, method)
Exemple #5
0
 def _path_req(self, path, method='GET', data=None,
               query_string=None,
               admin_context=True):
     content_type = 'application/%s' % self.fmt
     body = None
     if data is not None:  # empty dict is valid
         body = Serializer().serialize(data, content_type)
     if admin_context:
         return create_request(
             path, body, content_type, method, query_string=query_string)
     else:
         return create_request(
             path, body, content_type, method, query_string=query_string,
             context=context.Context('', 'tenant_id'))
Exemple #6
0
def new_port_request(tenant_id,
                     network_id,
                     port_state,
                     format='xml',
                     custom_req_body=None):
    method = 'POST'
    path = ("/tenants/%(tenant_id)s/networks/"
            "%(network_id)s/ports.%(format)s") % locals()
    data = (custom_req_body or port_state and {
        'port': {
            'state': '%s' % port_state
        }
    })
    content_type = "application/%s" % format
    body = data and Serializer().serialize(data, content_type)
    return create_request(path, body, content_type, method)