~ubuntu-branches/ubuntu/quantal/horizon/quantal-security

« back to all changes in this revision

Viewing changes to horizon/dashboards/nova/networks/tables.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-03-09 11:50:22 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120309115022-ymiww5i58rbg97my
Tags: 2012.1~rc1~20120308.1479-0ubuntu1
* New upstream version.
* debian/rules: Fix symlink when installing horizon.
  (LP: #947118)
* debian/control: Add python-django-nose as a dep. (LP: #944235)
* debian/control: Fix broken depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import logging
2
 
 
3
 
from django.core.urlresolvers import reverse
4
 
from django.utils.translation import ugettext_lazy as _
5
 
 
6
 
from horizon import api
7
 
from horizon import tables
8
 
 
9
 
 
10
 
LOG = logging.getLogger(__name__)
11
 
 
12
 
 
13
 
class RenameNetworkLink(tables.LinkAction):
14
 
    name = "rename_network"
15
 
    verbose_name = _("Rename Network")
16
 
    url = "horizon:nova:networks:rename"
17
 
    attrs = {"class": "ajax-modal"}
18
 
 
19
 
 
20
 
class CreateNetworkLink(tables.LinkAction):
21
 
    name = "create_network"
22
 
    verbose_name = _("Create New Network")
23
 
    url = "horizon:nova:networks:create"
24
 
    classes = ("ajax-modal",)
25
 
 
26
 
 
27
 
class DeleteNetworkAction(tables.DeleteAction):
28
 
    data_type_singular = _("Network")
29
 
    data_type_plural = _("Networks")
30
 
 
31
 
    def delete(self, request, obj_id):
32
 
        api.quantum_delete_network(request, obj_id)
33
 
 
34
 
 
35
 
class NetworksTable(tables.DataTable):
36
 
    id = tables.Column('id', verbose_name=_('Network Id'),
37
 
                       link="horizon:nova:networks:detail")
38
 
    name = tables.Column('name', verbose_name=_('Name'))
39
 
    used = tables.Column('used', verbose_name=_('Used'))
40
 
    available = tables.Column('available', verbose_name=_('Available'))
41
 
    total = tables.Column('total', verbose_name=_('Total'))
42
 
    #tenant = tables.Column('tenant', verbose_name=_('Project'))
43
 
 
44
 
    def get_object_id(self, datum):
45
 
        return datum['id']
46
 
 
47
 
    def get_object_display(self, obj):
48
 
        return obj['name']
49
 
 
50
 
    class Meta:
51
 
        name = "networks"
52
 
        verbose_name = _("Networks")
53
 
        row_actions = (DeleteNetworkAction, RenameNetworkLink,)
54
 
        table_actions = (CreateNetworkLink, DeleteNetworkAction,)
55
 
 
56
 
 
57
 
class CreatePortLink(tables.LinkAction):
58
 
    name = "create_port"
59
 
    verbose_name = _("Create Ports")
60
 
    url = "horizon:nova:networks:port_create"
61
 
    classes = ("ajax-modal",)
62
 
 
63
 
    def get_link_url(self, datum=None):
64
 
        network_id = self.table.kwargs['network_id']
65
 
        return reverse(self.url, args=(network_id,))
66
 
 
67
 
 
68
 
class DeletePortAction(tables.DeleteAction):
69
 
    data_type_singular = _("Port")
70
 
    data_type_plural = _("Ports")
71
 
 
72
 
    def delete(self, request, obj_id):
73
 
        api.quantum_delete_port(request,
74
 
                                self.table.kwargs['network_id'],
75
 
                                obj_id)
76
 
 
77
 
 
78
 
class DetachPortAction(tables.BatchAction):
79
 
    name = "detach_port"
80
 
    action_present = _("Detach")
81
 
    action_past = _("Detached")
82
 
    data_type_singular = _("Port")
83
 
    data_type_plural = _("Ports")
84
 
 
85
 
    def action(self, request, datum_id):
86
 
        body = {'port': {'state': 'DOWN'}}
87
 
        api.quantum_set_port_state(request,
88
 
                                   self.table.kwargs['network_id'],
89
 
                                   datum_id, body)
90
 
 
91
 
 
92
 
class AttachPortAction(tables.LinkAction):
93
 
    name = "attach_port"
94
 
    verbose_name = _("Attach Port")
95
 
    url = "horizon:nova:networks:port_attach"
96
 
    attrs = {"class": "ajax-modal"}
97
 
 
98
 
    def get_link_url(self, datum=None):
99
 
        network_id = self.table.kwargs['network_id']
100
 
        return reverse(self.url, args=(network_id, datum['id']))
101
 
 
102
 
 
103
 
class NetworkDetailsTable(tables.DataTable):
104
 
    id = tables.Column('id', verbose_name=_('Port Id'))
105
 
    state = tables.Column('state', verbose_name=_('State'))
106
 
    attachment = tables.Column('attachment', verbose_name=_('Attachment'))
107
 
 
108
 
    def get_object_id(self, datum):
109
 
        return datum['id']
110
 
 
111
 
    def get_object_display(self, obj):
112
 
        return obj['id']
113
 
 
114
 
    class Meta:
115
 
        name = "network_details"
116
 
        verbose_name = _("Network Port Details")
117
 
        row_actions = (DeletePortAction, AttachPortAction, DetachPortAction)
118
 
        table_actions = (CreatePortLink, DeletePortAction,)