Revision 7a3c66e1 kamaki/clients/cyclades/__init__.py

b/kamaki/clients/cyclades/__init__.py
112 112
        r = self.servers_action_post(server_id, json_data=req, success=200)
113 113
        return r.json['console']
114 114

  
115
    def get_firewall_profile(self, server_id):
116
        """
117
        :param server_id: integer (str or int)
118

  
119
        :returns: (str) ENABLED | DISABLED | PROTECTED
120

  
121
        :raises ClientError: 520 No Firewall Profile
122
        """
123
        r = self.get_server_details(server_id)
124
        try:
125
            return r['attachments'][0]['firewallProfile']
126
        except KeyError:
127
            raise ClientError(
128
                'No Firewall Profile',
129
                details='Server %s is missing a firewall profile' % server_id)
130

  
131
    def set_firewall_profile(self, server_id, profile):
132
        """Set the firewall profile for the public interface of a server
133

  
134
        :param server_id: integer (str or int)
135

  
136
        :param profile: (str) ENABLED | DISABLED | PROTECTED
137

  
138
        :returns: (dict) response headers
139
        """
140
        req = {'firewallProfile': {'profile': profile}}
141
        r = self.servers_action_post(server_id, json_data=req, success=202)
142
        return r.headers
143

  
144
    def list_server_nics(self, server_id):
145
        """
146
        :param server_id: integer (str or int)
147

  
148
        :returns: (dict) network interface connections
149
        """
150
        r = self.servers_ips_get(server_id)
151
        return r.json['attachments']
152

  
153 115
    def get_server_stats(self, server_id):
154 116
        """
155 117
        :param server_id: integer (str or int)
......
186 148
        return self._wait(
187 149
            server_id, current_status, get_status, delay, max_wait, wait_cb)
188 150

  
189
    def wait_firewall(
190
            self, server_id,
191
            current_status='DISABLED', delay=1, max_wait=100, wait_cb=None):
192
        """Wait while the public network firewall status is current_status
193

  
194
        :param server_id: integer (str or int)
195

  
196
        :param current_status: (str) DISABLED | ENABLED | PROTECTED
197

  
198
        :param delay: time interval between retries
199

  
200
        :max_wait: (int) timeout in secconds
201

  
202
        :param wait_cb: if set a progressbar is used to show progress
203

  
204
        :returns: (str) the new mode if succesfull, (bool) False if timed out
205
        """
206

  
207
        def get_status(self, server_id):
208
            return self.get_firewall_profile(server_id), None
209

  
210
        return self._wait(
211
            server_id, current_status, get_status, delay, max_wait, wait_cb)
212

  
213 151

  
214 152
class CycladesNetworkClient(NetworkClient):
215 153
    """Cyclades Network API extentions"""
......
252 190
        if fixed_ips:
253 191
            for fixed_ip in fixed_ips or []:
254 192
                if not 'ip_address' in fixed_ip:
255
                    raise ValueError(
256
                        'Invalid format for "fixed_ips"', details=[
257
                        'fixed_ips format: [{"ip_address": IPv4}, ...]'])
193
                    raise ValueError('Invalid fixed_ip [%s]' % fixed_ip)
258 194
            port['fixed_ips'] = fixed_ips
259 195
        r = self.ports_post(json_data=dict(port=port), success=201)
260 196
        return r.json['port']

Also available in: Unified diff