Commit 86e3d16c by Nótai István

commands: init command extended with default node, users, groups, permissions…

commands: init command extended with default node, users, groups, permissions and detects kvm hardware acceleration presence.
parent 2203ceab
Pipeline #619 passed with stage
in 0 seconds
...@@ -178,40 +178,23 @@ class Command(BaseCommand): ...@@ -178,40 +178,23 @@ class Command(BaseCommand):
priority=1, enabled=True, schedule_enabled=True) priority=1, enabled=True, schedule_enabled=True)
# creating groups # creating groups
admins = self.create(Group, 'name', name='Administrators') susers = self.create(Group, 'name', name='Superusers')
pusers = self.create(Group, 'name', name='Powerusers') pusers = self.create(Group, 'name', name='Powerusers')
users = self.create(Group, 'name', name='Users') users = self.create(Group, 'name', name='Users')
# creating group profiles # creating group profiles
self.create(GroupProfile, 'group', group=admins) self.create(GroupProfile, 'group', group=susers)
self.create(GroupProfile, 'group', group=pusers) self.create(GroupProfile, 'group', group=pusers)
self.create(GroupProfile, 'group', group=users) self.create(GroupProfile, 'group', group=users)
# specifying group permissions # specifying group permissions
user_permissions = [ user_permissions = [
'add_diskresizeaction',
'change_diskresizeaction',
'delete_diskresizeaction',
'add_extendleaseaction',
'change_extendleaseaction',
'delete_extendleaseaction',
'add_resourcechangeaction',
'change_resourcechangeaction',
'delete_resourcechangeaction',
'add_templateaccessaction',
'change_templateaccessaction',
'delete_templateaccessaction',
'add_templateaccesstype',
'change_templateaccesstype',
'delete_templateaccesstype',
'create_vm', 'create_vm',
'config_ports', 'config_ports',
] ]
puser_permissions = [ puser_permissions = [
'add_extendleaseaction', 'use_autocomplete',
'change_extendleaseaction',
'delete_extendleaseaction',
'config_ports', 'config_ports',
'create_vm', 'create_vm',
'create_empty_disk', 'create_empty_disk',
...@@ -221,42 +204,27 @@ class Command(BaseCommand): ...@@ -221,42 +204,27 @@ class Command(BaseCommand):
'change_resources', 'change_resources',
'set_resources', 'set_resources',
'change_template_resources', 'change_template_resources',
'add_instancetemplate', 'create_template',
] ]
admin_permissions = [ suser_permissions = [
'add_group', 'add_group',
'change_group',
'delete_group',
'add_user',
'change_user',
'delete_user',
'add_message',
'change_message',
'delete_message',
'use_autocomplete', 'use_autocomplete',
'add_group',
'change_group',
'delete_group',
'create_empty_disk', 'create_empty_disk',
'download_disk', 'download_disk',
'resize_disk',
'access_console', 'access_console',
'change_resources', 'change_resources',
'config_ports', 'config_ports',
'create_vm', 'create_vm',
'emergency_change_state',
'recover', 'recover',
'redeploy',
'set_resources', 'set_resources',
'change_template_resources', 'change_template_resources',
'create_base_template', 'create_base_template',
'create_template', 'create_template'
'create_leases',
] ]
# set group permissions # set group permissions
admins.permissions.set(self._get_permissions(admin_permissions)) susers.permissions.set(self._get_permissions(suser_permissions))
pusers.permissions.set(self._get_permissions(puser_permissions)) pusers.permissions.set(self._get_permissions(puser_permissions))
users.permissions.set(self._get_permissions(user_permissions)) users.permissions.set(self._get_permissions(user_permissions))
...@@ -268,33 +236,33 @@ class Command(BaseCommand): ...@@ -268,33 +236,33 @@ class Command(BaseCommand):
self.create(Profile, 'user', user=useruser) self.create(Profile, 'user', user=useruser)
poweruser = self.create(User, 'username', username="poweruser", poweruser = self.create(User, 'username', username="poweruser",
is_superuser=True, is_staff=False) is_superuser=False, is_staff=False)
poweruser.set_password("poweruser") poweruser.set_password("poweruser")
poweruser.save() poweruser.save()
self.create(Profile, 'user', user=poweruser) self.create(Profile, 'user', user=poweruser)
adminuser = self.create(User, 'username', username="admin", superuser = self.create(User, 'username', username="superuser",
is_superuser=True, is_staff=False) is_superuser=False, is_staff=False)
adminuser.set_password("admin") superuser.set_password("superuser")
adminuser.save() superuser.save()
self.create(Profile, 'user', user=adminuser) self.create(Profile, 'user', user=superuser)
# adding users o groups # adding users o groups
users.user_set.add(useruser) users.user_set.add(useruser)
pusers.user_set.add(poweruser) pusers.user_set.add(poweruser)
admins.user_set.add(adminuser) susers.user_set.add(superuser)
# add groups to vm vlan # add groups to vm vlan
vm.set_level(users, 'user') vm.set_level(users, 'user')
vm.set_level(pusers, 'user') vm.set_level(pusers, 'user')
vm.set_level(admins, 'user') vm.set_level(susers, 'user')
# notify admin if there is no harware virtualization # notify admin if there is no harware virtualization
if options['kvm_present']: if not options['kvm_present']:
adminuser.profile.notify("hardware virtualization", admin.profile.notify("hardware virtualization",
"No hardware virtualization detected, " "No hardware virtualization detected, "
"your hardware does not support it or " "your hardware does not support it or "
"not enabled in BIOS.") "not enabled in BIOS.")
self.print_state() self.print_state()
def _get_permissions(self, code_names): def _get_permissions(self, code_names):
......
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