Merge lp:~mpontillo/maas/change-owner-in-admin-form into lp:maas/trunk

Proposed by Mike Pontillo
Status: Rejected
Rejected by: MAAS Lander
Proposed branch: lp:~mpontillo/maas/change-owner-in-admin-form
Merge into: lp:maas/trunk
Diff against target: 34 lines (+10/-0)
1 file modified
src/maasserver/forms.py (+10/-0)
To merge this branch: bzr merge lp:~mpontillo/maas/change-owner-in-admin-form
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Needs Information
Review via email: mp+298838@code.launchpad.net

Commit message

Allow node owner to be changed by administrators.

Description of the change

This branch allows actions like the following using the API:

maas admin machine update 4y3hab owner=user2

This came about due to a discussion on FreeNode #maas where a customer wants to transfer ownership of a deployed node without releasing it first (which would require the node to be re-imaged). The customer is using a large (~4 GB) custom image and does not want to redeploy the node in order to transfer ownership (which would traditionally require releasing the node first).

This seemed like an easy change which could solve the problem. This obviously isn't shippable yet (no tests, etc) but I wanted to get some feedback from the team regarding if this was viable or not.

To post a comment you must log in.
5150. By Mike Pontillo on 2016-06-30

Allow administrators to change the wowner of a node.

Mike Pontillo (mpontillo) wrote :

Wondering what implications this has for cloud-init. I guess it would be best if the old owner releases the node, so that cloud-init can grab the new SSH keys?

Andres Rodriguez (andreserl) wrote :

Why should we allow this? We shouldn't allow this unless the machine is
allocated only. Machines in any other state cannot change owner... Or maybe
only to an admin, but even then, you would be messing with resources owned
to someone else../

On Thursday, June 30, 2016, Mike Pontillo <email address hidden>
wrote:

> Wondering what implications this has for cloud-init. I guess it would be
> best if the old owner releases the node, so that cloud-init can grab the
> new SSH keys?
> --
>
> https://code.launchpad.net/~mpontillo/maas/change-owner-in-admin-form/+merge/298838
> You are subscribed to branch lp:maas.
>

--
Andres Rodriguez (RoAkSoAx)
Ubuntu Server Developer
MSc. Telecom & Networking
Systems Engineer

Andres Rodriguez (andreserl) wrote :

Also, if there are such requests from customers on the field, could you please have them file a bug *first*. Requests like this should ideally be discussed before we make any effort or changes.

review: Needs Information
Mike Pontillo (mpontillo) wrote :

Understood. I think it was worth the ~5 minutes of effort to spur discussion, though. =)

This is specifically if you want to change the ownership of a deployed node, in order to reassign the resource to someone else. The change was to the AdminNodeForm, so would only be an allowed action for an admin.

It's a bit of a hack, but it seems like a reasonable thing to do. For example, if someone is leaving an organization and you want to move their deployed nodes to someone else's user account.

MAAS Lander (maas-lander) wrote :

Transitioned to Git.

lp:maas has now moved from Bzr to Git.
Please propose your branches with Launchpad using Git.

git clone https://git.launchpad.net/maas

Unmerged revisions

5150. By Mike Pontillo on 2016-06-30

Allow administrators to change the wowner of a node.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/forms.py'
2--- src/maasserver/forms.py 2016-06-16 15:17:32 +0000
3+++ src/maasserver/forms.py 2016-06-30 21:31:25 +0000
4@@ -846,6 +846,11 @@
5 initial=Zone.objects.get_default_zone,
6 queryset=Zone.objects.all(), to_field_name='name')
7
8+ owner = forms.ModelChoiceField(
9+ label="Owner", required=False,
10+ initial=None,
11+ queryset=User.objects.all(), to_field_name='username')
12+
13 cpu_count = forms.IntegerField(
14 required=False, initial=0, label="CPU Count")
15 memory = forms.IntegerField(
16@@ -866,6 +871,8 @@
17 data=data, instance=instance, **kwargs)
18 self.request = request
19 self.set_up_initial_zone(instance)
20+ if instance is not None:
21+ self.initial['owner'] = instance.owner.username
22 # The zone field is not required because we want to be able
23 # to omit it when using that form in the API.
24 # We don't want the UI to show an entry for the 'empty' zone,
25@@ -890,6 +897,9 @@
26 zone = self.cleaned_data.get('zone')
27 if zone:
28 node.zone = zone
29+ owner = self.cleaned_data.get('owner')
30+ if zone:
31+ node.owner = owner
32 if kwargs.get('commit', True):
33 node.save(*args, **kwargs)
34 self.save_m2m() # Save many to many relations.