Revision 75ae8a08 kamaki/clients/cyclades/__init__.py

b/kamaki/clients/cyclades/__init__.py
35 35
from kamaki.clients.network import NetworkClient
36 36
from kamaki.clients.utils import path4url
37 37
from kamaki.clients import ClientError, Waiter
38

  
38
import json
39 39

  
40 40
class CycladesClient(CycladesRestClient, Waiter):
41 41
    """Synnefo Cyclades Compute API client"""
42 42

  
43 43
    def create_server(
44 44
            self, name, flavor_id, image_id,
45
            metadata=None, personality=None, networks=None):
45
            metadata=None, personality=None, networks=None, project=None):
46 46
        """Submit request to create a new server
47 47

  
48 48
        :param name: (str)
......
64 64
            ATTENTION: Empty list is different to None. None means ' do not
65 65
            mention it', empty list means 'automatically get an ip'
66 66

  
67
        :param project: the project where to assign the server
68

  
67 69
        :returns: a dict with the new virtual server details
68 70

  
69 71
        :raises ClientError: wraps request errors
......
78 80

  
79 81
        return super(CycladesClient, self).create_server(
80 82
            name, flavor_id, image_id,
81
            metadata=metadata, personality=personality, networks=networks)
83
            metadata=metadata, personality=personality, networks=networks,
84
            project=project)
82 85

  
83 86
    def set_firewall_profile(self, server_id, profile, port_id):
84 87
        """Set the firewall profile for the public interface of a server
......
123 126
        r = self.servers_action_post(server_id, json_data=req, success=200)
124 127
        return r.json['console']
125 128

  
129
    def reassign_server(self, server_id, project):
130
        req = {'reassign': {'project': project}}
131
        r = self.servers_action_post(server_id, json_data=req, success=200)
132
        return r.headers
133

  
126 134
    def get_server_stats(self, server_id):
127 135
        """
128 136
        :param server_id: integer (str or int)
......
180 188
        r = self.get(path, success=200)
181 189
        return r.json['networks']
182 190

  
183
    def create_network(self, type, name=None, shared=None):
191
    def create_network(self, type, name=None, shared=None, project=None):
184 192
        req = dict(network=dict(type=type, admin_state_up=True))
185 193
        if name:
186 194
            req['network']['name'] = name
187 195
        if shared not in (None, ):
188 196
            req['network']['shared'] = bool(shared)
197
        if project is not None:
198
            req['network']['project'] = project
189 199
        r = self.networks_post(json_data=req, success=201)
190 200
        return r.json['network']
191 201

  
202
    def networks_action_post(
203
            self, network_id='', json_data=None, success=202, **kwargs):
204
        """POST base_url/networks/<network_id>/action
205

  
206
        :returns: request response
207
        """
208
        if json_data:
209
            json_data = json.dumps(json_data)
210
            self.set_header('Content-Type', 'application/json')
211
            self.set_header('Content-Length', len(json_data))
212
        path = path4url('networks', network_id, 'action')
213
        return self.post(path, data=json_data, success=success, **kwargs)
214

  
215
    def reassign_network(self, network_id, project):
216
        req = {'reassign': {'project': project}}
217
        r = self.networks_action_post(network_id, json_data=req, success=200)
218
        return r.headers
219

  
192 220
    def list_ports(self, detail=None):
193 221
        path = path4url('ports', 'detail' if detail else '')
194 222
        r = self.get(path, success=200)
......
216 244
        return r.json['port']
217 245

  
218 246
    def create_floatingip(
219
            self, floating_network_id=None, floating_ip_address=''):
247
            self,
248
            floating_network_id=None, floating_ip_address='', project_id=None):
220 249
        """
221 250
        :param floating_network_id: if not provided, it is assigned
222 251
            automatically by the service
223
        :param floating_ip_address: only if the IP is availabel in network
224
            pool
252
        :param floating_ip_address: only if the IP is availabel in network pool
253
        :param project_id: specific project to get resource quotas from
225 254
        """
226 255
        floatingip = {}
227 256
        if floating_network_id:
228 257
            floatingip['floating_network_id'] = floating_network_id
229 258
        if floating_ip_address:
230 259
            floatingip['floating_ip_address'] = floating_ip_address
260
        if project_id:
261
            floatingip['project'] = project_id
231 262
        r = self.floatingips_post(
232 263
            json_data=dict(floatingip=floatingip), success=200)
233 264
        return r.json['floatingip']
265

  
266
    def reassign_floating_ip(self, floating_network_id, project_id):
267
        """Change the project where this ip is charged"""
268
        path = path4url('floatingips', floating_network_id, 'action')
269
        json_data = dict(reassign=dict(project=project_id))
270
        self.post(path, json=json_data, success=202)

Also available in: Unified diff