To upload the file `sonata-demo.son` (from son-schema repo) do:
-* `curl -i -X POST -F file=@sonata-demo.son http://127.0.0.1:8000/api/packages`
+* `curl -i -X POST -F file=@sonata-demo.son http://127.0.0.1:5000/api/packages`
To list all uploaded packages do:
-* `curl http://127.0.0.1:8000/api/packages`
+* `curl http://127.0.0.1:5000/api/packages`
To instantiate (start) a service do:
-* Specific service: `curl -X POST http://127.0.0.1:8000/api/instantiations -d "{\"service_uuid\":\"59446b64-f941-40a8-b511-effb0512c21b\"}"`
-* Last uploaded service (makes manual tests easier): `curl -X POST http://127.0.0.1:8000/api/instantiations -d "{}"`
+* Specific service: `curl -X POST http://127.0.0.1:5000/api/instantiations -d "{\"service_uuid\":\"59446b64-f941-40a8-b511-effb0512c21b\"}"`
+* Last uploaded service (makes manual tests easier): `curl -X POST http://127.0.0.1:5000/api/instantiations -d "{}"`
To list all running services do:
-* `curl http://127.0.0.1:8000/api/instantiations`
+* `curl http://127.0.0.1:5000/api/instantiations`
## API definition
<td>/api/packages</td>
<td>POST</td>
<td>-</td>
-<td>{file-content} as enctype=multipart/form-data</td>
+<td>{file-content} as "content-type": "multipart/form-data"</td>
<td>{"service_uuid": "c880aaab-f3b9-43ac-ac6b-3d27b46146b7", size=456, sha1=49ee6468dfa4ecbad440d669b249d523a38651be, error: null}</td>
</tr>
<tr>
# iterate over all deployment units within each VNFDs
for u in vnfd.get("virtual_deployment_units"):
# 1. get the name of the docker image to start and the assigned DC
- docker_name = u.get("vm_image")
+ docker_name = vnfd.get("vnf_name")
target_dc = vnfd.get("dc")
# 2. perform some checks to ensure we can start the container
assert(docker_name is not None)
def _load_docker_files(self):
"""
- Get all paths to Dockerfiles from MANIFEST.MF and store them in dict.
+ Get all paths to Dockerfiles from VNFDs and store them in dict.
:return:
"""
- if "package_content" in self.manifest:
- for df in self.manifest.get("package_content"):
- if df.get("content-type") == "application/sonata.docker_files":
+ for k, v in self.vnfds.iteritems():
+ for vu in v.get("virtual_deployment_units"):
+ if vu.get("vm_image_format") == "docker":
+ vm_image = vu.get("vm_image")
docker_path = os.path.join(
self.package_content_path,
- make_relative_path(df.get("name")))
- # FIXME: Mapping to docker image names is hardcoded because of the missing mapping in the example package
- self.local_docker_files[helper_map_docker_name(df.get("name"))] = docker_path
+ make_relative_path(vm_image))
+ self.local_docker_files[k] = docker_path
LOG.debug("Found Dockerfile: %r" % docker_path)
def _build_images_from_dockerfiles(self):
"""
try:
# get file contents
+ print request.files
son_file = request.files['file']
# generate a uuid to reference this package
service_uuid = str(uuid.uuid4())
def make_relative_path(path):
+ if path.startswith("file://"):
+ path = path.replace("file://", "", 1)
if path.startswith("/"):
- return path.replace("/", "", 1)
+ path = path.replace("/", "", 1)
return path
-def helper_map_docker_name(name):
- """
- Quick hack to fix missing dependency in example package.
- """
- # FIXME remove this when package description is fixed
- mapping = {
- "/docker_files/iperf/Dockerfile": "iperf_docker",
- "/docker_files/firewall/Dockerfile": "fw_docker",
- "/docker_files/tcpdump/Dockerfile": "tcpdump_docker"
- }
- return mapping.get(name)
-
-
if __name__ == '__main__':
"""
Lets allow to run the API in standalone mode.
zapi1.start()
# add the SONATA dummy gatekeeper to each DC
- sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 8000)
+ sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
sdkg1.connectDatacenter(dc1)
sdkg1.connectDatacenter(dc2)
# run the dummy gatekeeper (in another thread, don't block)
--- /dev/null
+import time
+import requests
+import os
+from emuvim.test.base import SimpleTestTopology
+from emuvim.api.sonata import SonataDummyGatekeeperEndpoint
+
+
+
+class testSonataDummyGatekeeper(SimpleTestTopology):
+
+ def testAPI(self):
+ # create network
+ self.createNet(nswitches=0, ndatacenter=2, nhosts=2, ndockers=0)
+ # setup links
+ self.net.addLink(self.dc[0], self.h[0])
+ self.net.addLink(self.dc[0], self.dc[1])
+ self.net.addLink(self.h[1], self.dc[1])
+ # connect dummy GK to data centers
+ sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
+ sdkg1.connectDatacenter(self.dc[0])
+ sdkg1.connectDatacenter(self.dc[1])
+ # run the dummy gatekeeper (in another thread, don't block)
+ sdkg1.start()
+ # start Mininet network
+ self.startNet()
+ time.sleep(1)
+
+ # download example from GitHub
+ print "downloading latest son-demo.son from GitHub"
+ download = requests.get("https://github.com/sonata-nfv/son-schema/blob/master/package-descriptor/examples/sonata-demo.son?raw=true")
+ with open("son-demo.son", 'wb') as f:
+ f.write(download.content)
+
+ print "starting tests"
+ # board package
+ files = {"file": open("son-demo.son", "rb")}
+ r = requests.post("http://127.0.0.1:5000/api/packages", files=files)
+ self.assertEqual(r.status_code, 200)
+ self.assertTrue(r.json().get("service_uuid") is not None)
+ os.remove("son-demo.son")
+
+ # instantiate service
+ service_uuid = r.json().get("service_uuid")
+ r2 = requests.post("http://127.0.0.1:5000/api/instantiations", json={"service_uuid": service_uuid})
+ self.assertEqual(r2.status_code, 200)
+
+ # give the emulator some time to instantiate everything
+ time.sleep(2)
+
+ # check get request APIs
+ r3 = requests.get("http://127.0.0.1:5000/api/packages")
+ self.assertEqual(len(r3.json().get("service_uuid_list")), 1)
+ r4 = requests.get("http://127.0.0.1:5000/api/instantiations")
+ self.assertEqual(len(r4.json().get("service_instance_list")), 1)
+
+ # check number of running nodes
+ assert(len(self.getDockernetContainers()) == 3)
+ assert(len(self.net.hosts) == 5)
+ assert(len(self.net.switches) == 2)
+ # check compute list result
+ assert(len(self.dc[0].listCompute()) == 3)
+ # check connectivity by using ping
+ for vnf in self.dc[0].listCompute():
+ assert(self.net.ping([self.h[0], vnf]) <= 0.0)
+ # stop Mininet network
+ self.stopNet()
+
+