Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docker rest api 1 #193

Merged
merged 4 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ stages:
images:
- imagename: "hyperledger/cello-ansible-agent"
dockerfile: "build_image/docker/agent/ansible/Dockerfile.in"
- name: fabricoperator
images:
- imagename: "hyperledger/cello-k8s-operator-agent"
dockerfile: "src/agent/fabric-operator/agent/Dockerfile"
- imagename: "hyperledger/cello-k8s-operator-controller"
dockerfile: "src/agent/fabric-operator/Dockerfile"
# - name: fabricoperator
# images:
# - imagename: "hyperledger/cello-k8s-operator-agent"
# dockerfile: "src/agent/fabric-operator/agent/Dockerfile"
# - imagename: "hyperledger/cello-k8s-operator-controller"
# dockerfile: "src/agent/fabric-operator/Dockerfile"
27 changes: 22 additions & 5 deletions src/agent/docker-rest-agent/intergration-test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,45 @@
'name': 'cello-hlf-peer'
}

# Test creating a node
print('-'*20)
print('Test creating a node')
print()
n = post('http://localhost:5001/api/v1/nodes', data=data)
print(n.text)
txt = json.loads(n.text)
nid = txt['data']['id']
print('-'*20)

# Test starting a node
print('Test starting a node')
print()
data = {'action': 'start'}
response = post('http://localhost:5001/api/v1/nodes/'+nid, data=data)
print(response.text)
print('-'*20)

# Test restarting a node
print('Test restarting a node')
print()
data = {'action': 'restart'}
response = post('http://localhost:5001/api/v1/nodes/'+nid, data=data)
print(response.text)
print('-'*20)

# Test stopping a node
print('Test stopping a node')
print()
data = {'action': 'stop'}
response = post('http://localhost:5001/api/v1/nodes/'+nid, data=data)
print(response.text)
print('-'*20)

# Test deleting a node

print('Get status of a node')
print()
response = get('http://localhost:5001/api/v1/nodes/'+nid)
print(response.text)
print('-'*20)

print('Test deleting a node')
print()
data = {'action': 'delete'}
response = post('http://localhost:5001/api/v1/nodes/'+nid, data=data)
print(response.text)
2 changes: 1 addition & 1 deletion src/agent/docker-rest-agent/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask
flask-restful
requests
requests
10 changes: 7 additions & 3 deletions src/agent/docker-rest-agent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,28 @@ def create_node():
res['data']['id'] = container.id
res['data']['public-grpc'] = '127.0.0.1:7050' # TODO: read the info from config file
res['data']['public-raft'] = '127.0.0.1:7052'
res['msg'] = 'node created'
return jsonify(res)

@app.route('/api/v1/nodes/<id>', methods=['GET', 'POST'])
def operate_node(id):

container = client.containers.get(id)
if request.method == 'POST':
act = request.form.get('action') # only with POST

try:
if act == 'start':
container.start()
res['msg'] = 'node started'
elif act == 'restart':
container.restart()
res['msg'] = 'node restarted'
elif act == 'stop':
container.stop()
res['msg'] = 'node stopped'
elif act == 'delete':
container.remove()
res['msg'] = 'node deleted'
else:
res['msg'] = 'undefined action'
except:
Expand All @@ -69,8 +73,8 @@ def operate_node(id):
raise
else:
# GET
res['data']['status'] = container.status()
res['data']['status'] = container.status

res['code'] = PASS_CODE
return jsonify(res)

Expand Down