Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
23ed986c
authored
Jun 13, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: add agent.update task
parent
3bcecbcd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
7 deletions
+60
-7
circle/circle/settings/base.py
+13
-1
circle/vm/tasks/agent_tasks.py
+5
-0
circle/vm/tasks/local_agent_tasks.py
+42
-6
No files found.
circle/circle/settings/base.py
View file @
23ed986c
...
@@ -18,8 +18,10 @@
...
@@ -18,8 +18,10 @@
"""Common settings and globals."""
"""Common settings and globals."""
# flake8: noqa
# flake8: noqa
from
os
import
environ
from
os
import
environ
from
os.path
import
abspath
,
basename
,
dirname
,
join
,
normpath
,
isfile
from
os.path
import
(
abspath
,
basename
,
dirname
,
join
,
normpath
,
isfile
,
expanduser
)
from
sys
import
path
from
sys
import
path
from
subprocess
import
check_output
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.exceptions
import
ImproperlyConfigured
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
...
@@ -418,6 +420,16 @@ if get_env_variable('DJANGO_SAML', 'FALSE') == 'TRUE':
...
@@ -418,6 +420,16 @@ if get_env_variable('DJANGO_SAML', 'FALSE') == 'TRUE':
LOGIN_REDIRECT_URL
=
"/"
LOGIN_REDIRECT_URL
=
"/"
AGENT_DIR
=
get_env_variable
(
'DJANGO_AGENT_DIR'
,
join
(
unicode
(
expanduser
(
"~"
)),
'agent'
))
try
:
git_env
=
{
'GIT_DIR'
:
join
(
AGENT_DIR
,
'.git'
)}
AGENT_VERSION
=
check_output
(
(
'git'
,
'log'
,
'-1'
,
r'--pretty=format:
%
h'
,
'HEAD'
),
env
=
git_env
)
except
:
AGENT_VERSION
=
None
LOCALE_PATHS
=
(
join
(
SITE_ROOT
,
'locale'
),
)
LOCALE_PATHS
=
(
join
(
SITE_ROOT
,
'locale'
),
)
COMPANY_NAME
=
"BME IK 2014"
COMPANY_NAME
=
"BME IK 2014"
SOUTH_MIGRATION_MODULES
=
{
SOUTH_MIGRATION_MODULES
=
{
...
...
circle/vm/tasks/agent_tasks.py
View file @
23ed986c
...
@@ -51,3 +51,8 @@ def cleanup(vm):
...
@@ -51,3 +51,8 @@ def cleanup(vm):
@celery.task
(
name
=
'agent.start_access_server'
)
@celery.task
(
name
=
'agent.start_access_server'
)
def
start_access_server
(
vm
):
def
start_access_server
(
vm
):
pass
pass
@celery.task
(
name
=
'agent.update'
)
def
update
(
vm
,
data
):
pass
circle/vm/tasks/local_agent_tasks.py
View file @
23ed986c
...
@@ -18,8 +18,13 @@
...
@@ -18,8 +18,13 @@
from
manager.mancelery
import
celery
from
manager.mancelery
import
celery
from
vm.tasks.agent_tasks
import
(
restart_networking
,
change_password
,
from
vm.tasks.agent_tasks
import
(
restart_networking
,
change_password
,
set_time
,
set_hostname
,
start_access_server
,
set_time
,
set_hostname
,
start_access_server
,
cleanup
)
cleanup
,
update
)
import
time
import
time
from
base64
import
encodestring
from
StringIO
import
StringIO
from
tarfile
import
TarFile
,
TarInfo
from
django.conf
import
settings
from
celery.result
import
TimeoutError
def
send_init_commands
(
instance
,
act
,
vm
):
def
send_init_commands
(
instance
,
act
,
vm
):
...
@@ -38,22 +43,53 @@ def send_init_commands(instance, act, vm):
...
@@ -38,22 +43,53 @@ def send_init_commands(instance, act, vm):
queue
=
queue
,
args
=
(
vm
,
instance
.
primary_host
.
hostname
))
queue
=
queue
,
args
=
(
vm
,
instance
.
primary_host
.
hostname
))
def
create_agent_tar
():
def
exclude
(
tarinfo
):
if
tarinfo
.
name
.
startswith
(
'./.git'
):
return
None
else
:
return
tarinfo
f
=
StringIO
()
with
TarFile
.
open
(
fileobj
=
f
,
mode
=
'w|gz'
)
as
tar
:
tar
.
add
(
settings
.
AGENT_DIR
,
arcname
=
'.'
,
filter
=
exclude
)
version_fileobj
=
StringIO
(
settings
.
AGENT_VERSION
)
version_info
=
TarInfo
(
name
=
'version.txt'
)
version_info
.
size
=
len
(
version_fileobj
.
buf
)
tar
.
addfile
(
version_info
,
version_fileobj
)
return
encodestring
(
f
.
getvalue
())
.
replace
(
'
\n
'
,
''
)
@celery.task
@celery.task
def
agent_started
(
vm
):
def
agent_started
(
vm
,
version
=
None
):
from
vm.models
import
Instance
,
instance_activity
,
InstanceActivity
from
vm.models
import
Instance
,
instance_activity
,
InstanceActivity
instance
=
Instance
.
objects
.
get
(
id
=
int
(
vm
.
split
(
'-'
)[
-
1
]))
instance
=
Instance
.
objects
.
get
(
id
=
int
(
vm
.
split
(
'-'
)[
-
1
]))
queue
=
instance
.
get_remote_queue_name
(
"agent"
)
initialized
=
InstanceActivity
.
objects
.
filter
(
initialized
=
InstanceActivity
.
objects
.
filter
(
instance
=
instance
,
activity_code
=
'vm.Instance.agent'
)
.
exists
()
instance
=
instance
,
activity_code
=
'vm.Instance.agent
.cleanup
'
)
.
exists
()
with
instance_activity
(
code_suffix
=
'agent'
,
instance
=
instance
)
as
act
:
with
instance_activity
(
code_suffix
=
'agent'
,
instance
=
instance
)
as
act
:
with
act
.
sub_activity
(
'starting'
):
with
act
.
sub_activity
(
'starting'
):
pass
pass
if
version
and
version
!=
settings
.
AGENT_VERSION
:
try
:
with
act
.
sub_activity
(
'update'
):
update
.
apply_async
(
queue
=
queue
,
args
=
(
vm
,
create_agent_tar
()))
.
get
(
timeout
=
10
)
return
except
TimeoutError
:
pass
if
not
initialized
:
if
not
initialized
:
send_init_commands
(
instance
,
act
,
vm
)
send_init_commands
(
instance
,
act
,
vm
)
with
act
.
sub_activity
(
'start_access_server'
):
with
act
.
sub_activity
(
'start_access_server'
):
queue
=
instance
.
get_remote_queue_name
(
"agent"
)
start_access_server
.
apply_async
(
queue
=
queue
,
args
=
(
vm
,
))
start_access_server
.
apply_async
(
queue
=
queue
,
args
=
(
vm
,
))
@celery.task
@celery.task
...
...
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