-from core.models import Slice, SlicePrivilege, Sliver, Site, Node
+from core.models import Slice, SlicePrivilege, SliceRole, Sliver, Site, Node, User
from plus import PlusObjectMixin
from operator import itemgetter, attrgetter
qs = SlicePlus.objects.filter(id__in=slice_ids)
return qs
- def get_site_node_allocation(self, siteList):
+ def get_node_allocation(self, siteList):
siteIDList = [site.id for site in siteList]
nodeList = []
for node in Node.objects.all():
if self._update_site_allocation:
self.save_site_allocation(noAct=True)
+
+ if self._update_users:
+ self.save_users(noAct=True)
+
+ if self._update_site_allocation:
self.save_site_allocation()
+ if self._update_users:
+ self.save_users()
+
def save_site_allocation(self, noAct = False):
new_site_allocation = self._update_site_allocation
- all_slice_slivers = self.slivers.all() # Sliver.objects.filter(slice=self)
+ all_slice_slivers = self.slivers.all()
for site_name in new_site_allocation.keys():
desired_allocation = new_site_allocation[site_name]
# add more slivers
if (len(slivers) < desired_allocation):
site = Site.objects.get(name = site_name)
- nodes = self.get_site_node_allocation([site])
+ nodes = self.get_node_allocation([site])
if (not nodes):
raise ValueError("no nodes in site %s" % site_name)
node.sliverCount = node.sliverCount + 1
+ def save_users(self, noAct = False):
+ new_users = self._update_users
+
+ default_role = SliceRole.objects.get(role="default")
+
+ slice_privs = self.sliceprivileges.all()
+ slice_user_ids = [priv.user.id for priv in slice_privs]
+
+ for user_id in new_users:
+ if (user_id not in slice_user_ids):
+ print "XXX", user_id
+ priv = SlicePrivilege(slice=self, user=User.objects.get(id=user_id), role=default_role)
+ if (not noAct):
+ priv.save()
+
+ print "added user id", user_id
+
+ for priv in slice_privs:
+ if (priv.role.id != default_role.id):
+ # only mess with 'default' users; don't kill an admin
+ continue
+
+ if (priv.user.id not in new_users):
+ if (not noAct):
+ priv.delete()
+
+ print "deleted user id", user_id
+
+
+
+
putToSlice: function(slice) {
slice.attributes.site_allocation = {};
for (index in this.models) {
- model = this.models[index];
+ var model = this.models[index];
slice.attributes.site_allocation[ model.attributes.name ] = model.attributes.allocated;
}
},
saveClicked: function(e) {
model = this.options.linkedView.model;
model.tenantSiteCollection.putToSlice(model);
+ model.attributes.users = model.usersBuffer;
this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
},
});
modal: true,
width: 640,
buttons : {
- "Save" : function() {
+ "Create Slice" : function() {
var addDialog = this;
console.log("SAVE!!!");
detailView.synchronous = true;
modal: true,
width: 640,
buttons : {
- "Save" : function() {
+ "Ok" : function() {
var editDialog = this;
user_ids = all_options($("#tenant-edit-users-dialog").find(".select-picker-to"));
user_ids = user_ids.map( function(x) { return parseInt(x,10); } );
- model.attributes.users = user_ids;
+ model.usersBuffer = user_ids;
$(editDialog).dialog("close");
},
"Cancel" : function() {
\r
tenantSites = new XOSTenantSiteCollection();\r
tenantSites.getFromSlice(model);\r
+ model.usersBuffer = model.attributes.users; /* save a copy of 'users' that we can edit. This prevents another view (developer) from overwriting our copy with a fetch from the server */\r
model.tenantSiteCollection = tenantSites;\r
XOSTenantApp.tenantSites = tenantSites;\r
\r