Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f03239bb
authored
Jun 02, 2020
by
Máhonfai Bálint
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an optional argument for an additional admin user
parent
81054e66
Pipeline
#1152
passed with stage
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
8 deletions
+14
-8
circle/vm/management/commands/mass_create_vms.py
+11
-5
circle/vm/models/instance.py
+3
-3
No files found.
circle/vm/management/commands/mass_create_vms.py
View file @
f03239bb
...
...
@@ -21,14 +21,20 @@ from vm.models import Instance, InstanceTemplate
class
Command
(
BaseCommand
):
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'template_id'
,
type
=
int
)
parser
.
add_argument
(
'users_path'
)
parser
.
add_argument
(
'-t'
,
'--template'
,
type
=
int
,
required
=
True
)
parser
.
add_argument
(
'-u'
,
'--users'
,
required
=
True
)
parser
.
add_argument
(
'-a'
,
'--admin'
)
def
handle
(
self
,
*
args
,
**
options
):
template
=
InstanceTemplate
.
objects
.
get
(
id
=
options
[
'template_id'
])
with
open
(
options
[
'users_path'
])
as
f
:
template
=
InstanceTemplate
.
objects
.
get
(
id
=
options
[
'template'
])
with
open
(
options
[
'users'
])
as
f
:
users
=
f
.
read
()
.
splitlines
()
missing_users
=
Instance
.
mass_create_for_users
(
template
,
users
)
missing_users
=
Instance
.
mass_create_for_users
(
template
,
users
,
options
[
'admin'
]
)
if
len
(
missing_users
)
>
0
:
self
.
stdout
.
write
(
'These users do not exist:'
)
for
user
in
missing_users
:
...
...
circle/vm/models/instance.py
View file @
f03239bb
...
...
@@ -440,7 +440,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
for
cps
in
customized_params
]
@classmethod
def
mass_create_for_users
(
cls
,
template
,
users
,
**
kwargs
):
def
mass_create_for_users
(
cls
,
template
,
users
,
admin
=
None
,
**
kwargs
):
"""
Create and deploy an instance of a template for each user
in a list of users. Returns the user IDs of missing users.
...
...
@@ -453,11 +453,11 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
except
User
.
DoesNotExist
:
missing_users
.
append
(
user_id
)
instances
=
[]
for
user
in
user_instances
:
instance
=
cls
.
create_from_template
(
template
,
user
,
**
kwargs
)
if
admin
:
instance
.
set_level
(
User
.
objects
.
get
(
username
=
admin
),
'owner'
)
instance
.
deploy
(
user
=
user
)
instances
.
append
(
instance
)
return
missing_users
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment