Пример #1
0
 def server_nic_update_or_create(self, context, port_id, values):
     with _session_for_write() as session:
         query = model_query(context,
                             models.ServerNic).filter_by(port_id=port_id)
         nic = query.first()
         if not nic:
             nic = models.ServerNic()
         values.update(port_id=port_id)
         nic.update(values)
         session.add(nic)
         session.flush()
     return nic
Пример #2
0
    def server_create(self, context, values):
        if not values.get('uuid'):
            values['uuid'] = uuidutils.generate_uuid()

        server_nics = values.pop('nics', [])
        server = models.Server()
        server.update(values)
        nic_refs = []
        for nic in server_nics:
            nic_ref = models.ServerNic()
            nic_ref.update(nic)
            nic_refs.append(nic_ref)
        with _session_for_write() as session:
            try:
                session.add(server)
                for nic_r in nic_refs:
                    session.add(nic_r)
                session.flush()
            except db_exc.DBDuplicateEntry:
                raise exception.ServerAlreadyExists(name=values['name'])
            return server