Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nrm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
16
Issues
16
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
argo
nrm
Commits
346eed43
Commit
346eed43
authored
Dec 14, 2017
by
Swann Perarnau
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'containers-cmd' into 'master'
Add more container commands See merge request
!4
parents
848a9755
63c2dea8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
2 deletions
+84
-2
bin/cmd
bin/cmd
+50
-0
nrm/containers.py
nrm/containers.py
+18
-0
nrm/daemon.py
nrm/daemon.py
+16
-2
No files found.
bin/cmd
View file @
346eed43
...
...
@@ -78,6 +78,46 @@ class CommandLineInterface(object):
self
.
logger
.
info
(
"container response: %r"
,
msg
)
break
def
do_list
(
self
,
argv
):
"""Connect to the NRM and ask to list the containers present on the
system.
The NRM should respond to us on the pub socket with one message listing
all containers."""
command
=
{
'command'
:
'list'
,
}
while
(
True
):
self
.
upstream_pub_socket
.
send_json
(
command
)
msg
=
self
.
upstream_sub_socket
.
recv_json
()
self
.
logger
.
info
(
"new message: %r"
,
msg
)
# ignore other messages
if
isinstance
(
msg
,
dict
)
and
msg
.
get
(
'type'
)
==
'container'
:
if
msg
[
'event'
]
==
'list'
:
self
.
logger
.
info
(
"list response: %r"
,
msg
)
break
def
do_kill
(
self
,
argv
):
"""Connect to the NRM and ask to kill a container by uuid.
The NRM should respond to us on the pub socket with a message
containing the exit status of the top process of the container."""
command
=
{
'command'
:
'kill'
,
'uuid'
:
argv
.
uuid
}
while
(
True
):
self
.
upstream_pub_socket
.
send_json
(
command
)
msg
=
self
.
upstream_sub_socket
.
recv_json
()
self
.
logger
.
info
(
"new message: %r"
,
msg
)
# ignore other messages
if
isinstance
(
msg
,
dict
)
and
msg
.
get
(
'type'
)
==
'container'
:
if
msg
[
'event'
]
==
'exit'
and
msg
[
'uuid'
]
==
argv
.
uuid
:
self
.
logger
.
info
(
"container exit: %r"
,
msg
)
break
def
do_setpower
(
self
,
argv
):
""" Connect to the NRM and ask to change the power limit.
...
...
@@ -117,6 +157,15 @@ class CommandLineInterface(object):
nargs
=
argparse
.
REMAINDER
)
parser_run
.
set_defaults
(
func
=
self
.
do_run
)
# kill container
parser_kill
=
subparsers
.
add_parser
(
"kill"
)
parser_kill
.
add_argument
(
"uuid"
,
help
=
"uuid of the container"
)
parser_kill
.
set_defaults
(
func
=
self
.
do_kill
)
# list containers
parser_list
=
subparsers
.
add_parser
(
"list"
)
parser_list
.
set_defaults
(
func
=
self
.
do_list
)
# setpowerlimit
parser_setpower
=
subparsers
.
add_parser
(
"setpower"
)
parser_setpower
.
add_argument
(
"-f"
,
"--follow"
,
...
...
@@ -126,6 +175,7 @@ class CommandLineInterface(object):
help
=
"set new power limit"
,
type
=
float
)
parser_setpower
.
set_defaults
(
func
=
self
.
do_setpower
)
args
=
parser
.
parse_args
()
if
args
.
verbose
:
self
.
logger
.
setLevel
(
logging
.
DEBUG
)
...
...
nrm/containers.py
View file @
346eed43
...
...
@@ -4,9 +4,11 @@ from aci import ImageManifest
from
collections
import
namedtuple
import
logging
import
os
import
signal
from
subprograms
import
ChrtClient
,
NodeOSClient
,
resources
import
sys
Container
=
namedtuple
(
'Container'
,
[
'uuid'
,
'manifest'
,
'pid'
])
...
...
@@ -92,3 +94,19 @@ class ContainerManager(object):
c
=
self
.
containers
[
uuid
]
del
self
.
containers
[
uuid
]
del
self
.
pids
[
c
.
pid
]
def
kill
(
self
,
uuid
):
"""Kill all the processes of a container."""
if
uuid
in
self
.
containers
:
c
=
self
.
containers
[
uuid
]
self
.
logger
.
debug
(
"killing %r:"
,
c
)
try
:
os
.
kill
(
c
.
pid
,
signal
.
SIGKILL
)
except
OSError
:
pass
def
list
(
self
):
"""List the containers in the system."""
fields
=
[
'uuid'
,
'pid'
]
ret
=
[
c
.
_asdict
()
for
c
in
self
.
containers
.
values
()]
return
[{
k
:
d
[
k
]
for
k
in
fields
}
for
d
in
ret
]
nrm/daemon.py
View file @
346eed43
...
...
@@ -123,6 +123,7 @@ class Daemon(object):
self.containerpids[pid] = msg['uuid']
# TODO: obviously we need to send more info than that
update = {'type': 'container',
'event': 'start',
'uuid': msg['uuid'],
'errno': 0,
'pid': pid,
...
...
@@ -130,10 +131,23 @@ class Daemon(object):
self.upstream_pub.send_json(update)
else:
update = {'type': 'container',
'event': 'start',
'uuid': msg['uuid'],
'errno': pid,
}
self.upstream_pub.send_json(update)
elif command == 'kill':
self.logger.info("
asked
to
kill
container
:
%
r", msg)
response = self.container_manager.kill(msg['uuid'])
# no update here, as it will trigger child exit
elif command == 'list':
self.logger.info("
asked
for
container
list
:
%
r", msg)
response = self.container_manager.list()
update = {'type': 'container',
'event': 'list',
'payload': response,
}
self.upstream_pub.send_json(update)
else:
self.logger.error("
invalid
command
:
%
r", command)
...
...
@@ -186,13 +200,13 @@ class Daemon(object):
# check if its a pid we care about
if pid in self.containerpids:
# check if this is an exit
if os.WIFEXITED(status):
if os.WIFEXITED(status)
or os.WIFSIGNALED(status)
:
uuid = self.containerpids[pid]
self.container_manager.delete(uuid)
msg = {'type': 'container',
'event': 'exit',
'status': status,
'uuid':
None
,
'uuid':
uuid
,
}
self.upstream_pub.send_json(msg)
else:
...
...
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