class ControllerNetwork(PlCoreBase): objects = ControllerLinkManager() deleted_objects = ControllerLinkDeletionManager() # Stores the openstack ids at various controllers network = models.ForeignKey(Network, related_name='controllernetworks') controller = models.ForeignKey(Controller, related_name='controllernetworks') net_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum network") router_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum router id") subnet_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum subnet id") subnet = models.CharField(max_length=32, blank=True) @staticmethod def select_by_user(user): if user.is_admin: qs = ControllerNetwork.objects.all() else: slices = Slice.select_by_user(user) networks = Network.objects.filter(owner__in=slices) qs = ControllerNetwork.objects.filter(network__in=networks) return qs
class ControllerUser(PlCoreBase): objects = ControllerLinkManager() deleted_objects = ControllerLinkDeletionManager() user = models.ForeignKey(User, related_name='controllerusers') controller = models.ForeignKey(Controller, related_name='controllersusers') kuser_id = models.CharField(null=True, blank=True, max_length=200, help_text="Keystone user id") def __unicode__(self): return u'%s %s' % (self.controller, self.user) @staticmethod def select_by_user(user): if user.is_admin: qs = ControllerUser.objects.all() else: users = Users.select_by_user(user) qs = ControllerUser.objects.filter(user__in=users) return qs def can_update(self, user): return user.can_update_root()
class ControllerSlice(PlCoreBase): objects = ControllerLinkManager() deleted_objects = ControllerLinkDeletionManager() controller = models.ForeignKey(Controller, related_name='controllerslices') slice = models.ForeignKey(Slice, related_name='controllerslices') tenant_id = StrippedCharField(null=True, blank=True, max_length=200, help_text="Keystone tenant id") class Meta: unique_together = ('controller', 'slice') def __unicode__(self): return u'%s %s' % (self.slice, self.controller) @staticmethod def select_by_user(user): if user.is_admin: qs = ControllerSlice.objects.all() else: slices = Slice.select_by_user(user) qs = ControllerSlice.objects.filter(slice__in=slices) return qs def get_cpu_stats(self): filter = 'project_id=%s'%self.tenant_id return monitor.get_meter('cpu',filter,None) def get_bw_stats(self): filter = 'project_id=%s'%self.tenant_id return monitor.get_meter('network.outgoing.bytes',filter,None) def get_node_stats(self): return len(self.slice.instances)
class ControllerSlicePrivilege(PlCoreBase): objects = ControllerLinkManager() deleted_objects = ControllerLinkDeletionManager() controller = models.ForeignKey('Controller', related_name='controllersliceprivileges') slice_privilege = models.ForeignKey('SlicePrivilege', related_name='controllersliceprivileges') role_id = StrippedCharField(null=True, blank=True, max_length=200, db_index=True, help_text="Keystone id") xos_links = [ModelLink(Controller,via='controller'), ModelLink(SlicePrivilege,via='slice_privilege')] class Meta: unique_together = ('controller', 'slice_privilege') def __unicode__(self): return u'%s %s' % (self.controller, self.slice_privilege) def can_update(self, user): if user.is_readonly: return False if user.is_admin: return True cprivs = ControllerSlicePrivilege.objects.filter(slice_privilege__user=user) for cpriv in dprivs: if cpriv.role.role == ['admin', 'Admin']: return True return False @staticmethod def select_by_user(user): if user.is_admin: qs = ControllerSlicePrivilege.objects.all() else: cpriv_ids = [cp.id for cp in ControllerSlicePrivilege.objects.filter(slice_privilege__user=user)] qs = ControllerSlicePrivilege.objects.filter(id__in=cpriv_ids) return qs
class ControllerImages(PlCoreBase): objects = ControllerLinkManager() deleted_objects = ControllerLinkDeletionManager() image = models.ForeignKey(Image,related_name='controllerimages') controller = models.ForeignKey(Controller,related_name='controllerimages') glance_image_id = models.CharField(null=True, blank=True, max_length=200, help_text="Glance image id") def __unicode__(self): return u'%s %s' % (self.image, self.controller)
class ControllerImages(PlCoreBase): objects = ControllerLinkManager() deleted_objects = ControllerLinkDeletionManager() image = models.ForeignKey(Image,related_name='controllerimages') controller = models.ForeignKey(Controller,related_name='controllerimages') glance_image_id = StrippedCharField(null=True, blank=True, max_length=200, help_text="Glance image id") xos_links = [ModelLink(Image,'image'),ModelLink(Controller,'controller')] class Meta: unique_together = ('image', 'controller') def __unicode__(self): return u'%s %s' % (self.image, self.controller)
class ControllerNetwork(PlCoreBase): objects = ControllerLinkManager() deleted_objects = ControllerLinkDeletionManager() # Stores the openstack ids at various controllers network = models.ForeignKey(Network, related_name='controllernetworks') controller = models.ForeignKey(Controller, related_name='controllernetworks') subnet = models.CharField(max_length=32, blank=True) start_ip = models.CharField(max_length=32, blank=True) stop_ip = models.CharField(max_length=32, blank=True) net_id = models.CharField(null=True, blank=True, max_length=256, help_text="Neutron network") # feedback state router_id = models.CharField( null=True, blank=True, max_length=256, help_text="Neutron router id") # feedback state subnet_id = models.CharField( null=True, blank=True, max_length=256, help_text="Neutron subnet id") # feedback state gateway = models.CharField(max_length=32, blank=True, null=True) # feedback state segmentation_id = models.CharField(max_length=32, blank=True, null=True) # feedback state xos_links = [ ModelLink(Controller, via='controller'), ModelLink(Network, via='network') ] class Meta: unique_together = ('network', 'controller') def tologdict(self): d = super(ControllerNetwork, self).tologdict() try: d['network_name'] = self.network.name d['controller_name'] = self.controller.name except: pass return d @staticmethod def select_by_user(user): if user.is_admin: qs = ControllerNetwork.objects.all() else: slices = Slice.select_by_user(user) networks = Network.objects.filter(owner__in=slices) qs = ControllerNetwork.objects.filter(network__in=networks) return qs
class ControllerCredential(PlCoreBase): objects = ControllerLinkManager() deleted_objects = ControllerLinkDeletionManager() controller = models.ForeignKey( Controller, related_name='controllercredentials', help_text="The User this credential is associated with") name = models.SlugField(help_text="The credential type, e.g. ec2", max_length=128) key_id = models.CharField(help_text="The backend id of this credential", max_length=1024) enc_value = EncryptedCharField( help_text="The key value of this credential", max_length=1024) def __unicode__(self): return self.name