~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/api/controllers/v1/port.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-01-05 12:21:37 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20150105122137-171bqrdpcxqipunk
Tags: 2015.1~b1-0ubuntu1
* New upstream beta release:
  - d/control: Align version requirements with upstream release.
* d/watch: Update uversionmangle to deal with kilo beta versioning
  changes.
* d/control: Bumped Standards-Version to 3.9.6, no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
            self._node_uuid = wtypes.Unset
73
73
 
74
74
    uuid = types.uuid
75
 
    "Unique UUID for this port"
 
75
    """Unique UUID for this port"""
76
76
 
77
77
    address = wsme.wsattr(types.macaddress, mandatory=True)
78
 
    "MAC Address for this port"
 
78
    """MAC Address for this port"""
79
79
 
80
80
    extra = {wtypes.text: types.MultiType(wtypes.text, six.integer_types)}
81
 
    "This port's meta data"
 
81
    """This port's meta data"""
82
82
 
83
83
    node_uuid = wsme.wsproperty(types.uuid, _get_node_uuid, _set_node_uuid,
84
84
                                mandatory=True)
85
 
    "The UUID of the node this port belongs to"
 
85
    """The UUID of the node this port belongs to"""
86
86
 
87
87
    links = wsme.wsattr([link.Link], readonly=True)
88
 
    "A list containing a self link and associated port links"
 
88
    """A list containing a self link and associated port links"""
89
89
 
90
90
    def __init__(self, **kwargs):
91
91
        self.fields = []
92
 
        fields = list(objects.Port.fields.keys())
 
92
        fields = list(objects.Port.fields)
93
93
        # NOTE(lucasagomes): node_uuid is not part of objects.Port.fields
94
94
        #                    because it's an API-only attribute
95
95
        fields.append('node_uuid')
98
98
            if not hasattr(self, field):
99
99
                continue
100
100
            self.fields.append(field)
101
 
            setattr(self, field, kwargs.get(field))
 
101
            setattr(self, field, kwargs.get(field, wtypes.Unset))
102
102
 
103
103
        # NOTE(lucasagomes): node_id is an attribute created on-the-fly
104
104
        # by _set_node_uuid(), it needs to be present in the fields so
105
105
        # that as_dict() will contain node_id field when converting it
106
106
        # before saving it in the database.
107
107
        self.fields.append('node_id')
108
 
        setattr(self, 'node_uuid', kwargs.get('node_id'))
 
108
        setattr(self, 'node_uuid', kwargs.get('node_id', wtypes.Unset))
109
109
 
110
 
    @classmethod
111
 
    def convert_with_links(cls, rpc_port, expand=True):
112
 
        port = Port(**rpc_port.as_dict())
 
110
    @staticmethod
 
111
    def _convert_with_links(port, url, expand=True):
113
112
        if not expand:
114
113
            port.unset_fields_except(['uuid', 'address'])
115
114
 
116
115
        # never expose the node_id attribute
117
116
        port.node_id = wtypes.Unset
118
117
 
119
 
        port.links = [link.Link.make_link('self', pecan.request.host_url,
 
118
        port.links = [link.Link.make_link('self', url,
120
119
                                          'ports', port.uuid),
121
 
                      link.Link.make_link('bookmark',
122
 
                                          pecan.request.host_url,
 
120
                      link.Link.make_link('bookmark', url,
123
121
                                          'ports', port.uuid,
124
122
                                          bookmark=True)
125
123
                     ]
126
124
        return port
127
125
 
128
126
    @classmethod
129
 
    def sample(cls):
 
127
    def convert_with_links(cls, rpc_port, expand=True):
 
128
        port = Port(**rpc_port.as_dict())
 
129
        return cls._convert_with_links(port, pecan.request.host_url, expand)
 
130
 
 
131
    @classmethod
 
132
    def sample(cls, expand=True):
130
133
        sample = cls(uuid='27e3153e-d5bf-4b7e-b517-fb518e17f34c',
131
134
                     address='fe:54:00:77:07:d9',
132
135
                     extra={'foo': 'bar'},
135
138
        # NOTE(lucasagomes): node_uuid getter() method look at the
136
139
        # _node_uuid variable
137
140
        sample._node_uuid = '7ae81bb3-dec3-4289-8d6c-da80bd8001ae'
138
 
        return sample
 
141
        return cls._convert_with_links(sample, 'http://localhost:6385', expand)
139
142
 
140
143
 
141
144
class PortCollection(collection.Collection):
142
145
    """API representation of a collection of ports."""
143
146
 
144
147
    ports = [Port]
145
 
    "A list containing ports objects"
 
148
    """A list containing ports objects"""
146
149
 
147
150
    def __init__(self, **kwargs):
148
151
        self._type = 'ports'
149
152
 
150
 
    @classmethod
151
 
    def convert_with_links(cls, rpc_ports, limit, url=None,
152
 
                           expand=False, **kwargs):
 
153
    @staticmethod
 
154
    def convert_with_links(rpc_ports, limit, url=None, expand=False, **kwargs):
153
155
        collection = PortCollection()
154
156
        collection.ports = [Port.convert_with_links(p, expand)
155
157
                            for p in rpc_ports]
159
161
    @classmethod
160
162
    def sample(cls):
161
163
        sample = cls()
162
 
        sample.ports = [Port.sample()]
 
164
        sample.ports = [Port.sample(expand=False)]
163
165
        return sample
164
166
 
165
167
 
326
328
            except AttributeError:
327
329
                # Ignore fields that aren't exposed in the API
328
330
                continue
 
331
            if patch_val == wtypes.Unset:
 
332
                patch_val = None
329
333
            if rpc_port[field] != patch_val:
330
334
                rpc_port[field] = patch_val
331
335