Commit 806ecf3e by Szabolcs Gelencser

initial implementation of add interface operation

parent ba26b3e5
......@@ -997,8 +997,8 @@ class VmAddInterfaceForm(OperationForm):
choices = kwargs.pop('choices')
super(VmAddInterfaceForm, self).__init__(*args, **kwargs)
field = forms.ModelChoiceField(
queryset=choices, required=False,
field = forms.ChoiceField(
choices=choices, required=False,
label=self.label)
if not choices:
field.widget.attrs['disabled'] = 'disabled'
......
......@@ -350,13 +350,13 @@ class VmAddInterfaceView(FormOperationMixin, VmOperationView):
with_reload = True
def get_form_kwargs(self):
inst = self.get_op().instance
choices = Vlan.get_objects_with_level(
"user", self.request.user).exclude(
vm_interface__instance__in=[inst])
val = super(VmAddInterfaceView, self).get_form_kwargs()
val.update({'choices': choices})
return val
context = super(VmAddInterfaceView, self).get_form_kwargs()
networks = openstack_api.neutron.network_list_for_tenant(self.request, self.request.user.tenant_id)
choices = ((n.id, n.name) for n in networks)
context.update({
'choices': choices
})
return context
#
# class VmDiskModifyView(FormOperationMixin, VmOperationView):
......
......@@ -159,6 +159,9 @@ class Server(base.APIResourceWrapper):
def host_server(self):
return getattr(self, 'OS-EXT-SRV-ATTR:host', '')
def __repr__(self):
return self.name
class Hypervisor(base.APIDictWrapper):
"""Simple wrapper around novaclient.hypervisors.Hypervisor."""
......
......@@ -186,9 +186,8 @@ class AddInterfaceOperation(InstanceOperation):
accept_states = ('SHUTOFF', 'ACTIVE') #TODO: try other states
os_policy_actions = (("compute", "compute:attach_interface"),)
def _operation(self, activity, user, system, vlan, managed=None):
print("Adding interface")
def _operation(self, request, user, system, vlan, managed=None):
openstack_api.nova.interface_attach(request, self.instance, net_id=vlan)
@register_operation
class CreateDiskOperation(InstanceOperation):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment