~bgh/nova/qmanager-dhcp

« back to all changes in this revision

Viewing changes to nova/network/quantum/melange_connection.py

  • Committer: Brad Hall
  • Date: 2011-10-02 00:34:49 UTC
  • Revision ID: brad@nicira.com-20111002003449-c93594f62o8zpt2l
Add DHCP support to the QuantumManager

This introduces a new flag "quantum_use_dhcp=<boolean>" which indicates
whether or not to enable dhcp for all of the networks.  If it is set then we
start dnsmasq (and provide it with the IP/MACs from Melange) similar to how
this was done in linux_net before.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
        else:
67
67
            return httplib.HTTPConnection(self.host, self.port)
68
68
 
69
 
    def do_request(self, method, path, body=None, headers=None, params=None):
 
69
    def do_request(self, method, path, body=None, headers=None, params=None,
 
70
            content_type=".json"):
70
71
        headers = headers or {}
71
72
        params = params or {}
72
73
 
73
 
        url = "/%s/%s.json" % (self.version, path)
 
74
        url = "/%s/%s%s" % (self.version, path, content_type)
74
75
        if params:
75
76
            url += "?%s" % urllib.urlencode(params)
76
77
        try:
98
99
        return json.loads(response)['ip_addresses']
99
100
 
100
101
    def create_block(self, network_id, cidr,
101
 
                    project_id=None, dns1=None, dns2=None):
 
102
                    project_id=None, gateway=None, dns1=None, dns2=None):
102
103
        tenant_scope = "/tenants/%s" % project_id if project_id else ""
103
104
 
104
105
        url = "ipam%(tenant_scope)s/ip_blocks" % locals()
105
106
 
106
107
        req_params = dict(ip_block=dict(cidr=cidr, network_id=network_id,
107
 
                                    type='private', dns1=dns1, dns2=dns2))
 
108
                                    type='private', gateway=gateway,
 
109
                                    dns1=dns1, dns2=dns2))
108
110
        self.post(url, body=json.dumps(req_params),
109
111
                                headers=json_content_type)
110
112
 
132
134
        response = self.get(url, headers=json_content_type)
133
135
        return json.loads(response)['ip_addresses']
134
136
 
 
137
    def get_allocated_ips_for_network(self, network_id, project_id=None):
 
138
        tenant_scope = "/tenants/%s" % project_id if project_id else ""
 
139
        url = ("ipam%(tenant_scope)s/allocated_ip_addresses" % locals())
 
140
        # TODO(bgh): This request fails if you add the ".json" to the end so
 
141
        # it has to call do_request itself.  Melange bug?
 
142
        response = self.do_request("GET", url, content_type="")
 
143
        return json.loads(response)['ip_addresses']
 
144
 
135
145
    def deallocate_ips(self, network_id, vif_id, project_id=None):
136
146
        tenant_scope = "/tenants/%s" % project_id if project_id else ""
137
147