|
@ -12,7 +12,6 @@ |
|
|
# License for the specific language governing permissions and limitations |
|
|
# License for the specific language governing permissions and limitations |
|
|
# under the License. |
|
|
# under the License. |
|
|
|
|
|
|
|
|
import copy |
|
|
|
|
|
import json |
|
|
import json |
|
|
import random |
|
|
import random |
|
|
import uuid |
|
|
import uuid |
|
@ -75,14 +74,20 @@ def get_random_task(): |
|
|
float(CONF.command.max_yb)) |
|
|
float(CONF.command.max_yb)) |
|
|
|
|
|
|
|
|
task = { |
|
|
task = { |
|
|
|
|
|
'data': { |
|
|
|
|
|
'type': 'fractal', |
|
|
|
|
|
'attributes': { |
|
|
'uuid': str(uuid.uuid4()), |
|
|
'uuid': str(uuid.uuid4()), |
|
|
'width': width, |
|
|
'width': width, |
|
|
'height': height, |
|
|
'height': height, |
|
|
'iterations': iterations, 'xa': xa, |
|
|
|
|
|
|
|
|
'iterations': iterations, |
|
|
|
|
|
'xa': xa, |
|
|
'xb': xb, |
|
|
'xb': xb, |
|
|
'ya': ya, |
|
|
'ya': ya, |
|
|
'yb': yb |
|
|
'yb': yb |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return task |
|
|
return task |
|
|
|
|
|
|
|
@ -93,25 +98,31 @@ def do_get_fractal(): |
|
|
|
|
|
|
|
|
def do_show_fractal(): |
|
|
def do_show_fractal(): |
|
|
LOG.info("showing fractal %s" % CONF.command.uuid) |
|
|
LOG.info("showing fractal %s" % CONF.command.uuid) |
|
|
|
|
|
headers = {'Content-Type': 'application/vnd.api+json', |
|
|
|
|
|
'Accept': 'application/vnd.api+json'} |
|
|
result = requests.get("%s/v1/fractal/%s" % |
|
|
result = requests.get("%s/v1/fractal/%s" % |
|
|
(CONF.endpoint_url, CONF.command.uuid)) |
|
|
|
|
|
|
|
|
(CONF.endpoint_url, CONF.command.uuid), |
|
|
|
|
|
headers=headers) |
|
|
|
|
|
LOG.debug("result: %s" % result.text) |
|
|
|
|
|
|
|
|
if result.status_code == 200: |
|
|
if result.status_code == 200: |
|
|
data = json.loads(result.text) |
|
|
data = json.loads(result.text) |
|
|
|
|
|
fractal_data = data['data']['attributes'] |
|
|
output = PrettyTable(["Parameter", "Value"]) |
|
|
output = PrettyTable(["Parameter", "Value"]) |
|
|
output.align["Parameter"] = "l" |
|
|
output.align["Parameter"] = "l" |
|
|
output.align["Value"] = "l" |
|
|
output.align["Value"] = "l" |
|
|
output.add_row(["uuid", data['uuid']]) |
|
|
|
|
|
output.add_row(["duration", "%f seconds" % data['duration']]) |
|
|
|
|
|
|
|
|
output.add_row(["uuid", fractal_data['uuid']]) |
|
|
|
|
|
output.add_row(["duration", "%f seconds" % fractal_data['duration']]) |
|
|
output.add_row(["dimensions", "%d x %d pixels" % |
|
|
output.add_row(["dimensions", "%d x %d pixels" % |
|
|
(data['width'], data['height'])]) |
|
|
|
|
|
output.add_row(["iterations", data['iterations']]) |
|
|
|
|
|
output.add_row(["xa", data['xa']]) |
|
|
|
|
|
output.add_row(["xb", data['xb']]) |
|
|
|
|
|
output.add_row(["ya", data['ya']]) |
|
|
|
|
|
output.add_row(["yb", data['yb']]) |
|
|
|
|
|
output.add_row(["size", "%d bytes" % data['size']]) |
|
|
|
|
|
output.add_row(["checksum", data['checksum']]) |
|
|
|
|
|
output.add_row(["generated_by", data['generated_by']]) |
|
|
|
|
|
|
|
|
(fractal_data['width'], fractal_data['height'])]) |
|
|
|
|
|
output.add_row(["iterations", fractal_data['iterations']]) |
|
|
|
|
|
output.add_row(["xa", fractal_data['xa']]) |
|
|
|
|
|
output.add_row(["xb", fractal_data['xb']]) |
|
|
|
|
|
output.add_row(["ya", fractal_data['ya']]) |
|
|
|
|
|
output.add_row(["yb", fractal_data['yb']]) |
|
|
|
|
|
output.add_row(["size", "%d bytes" % fractal_data['size']]) |
|
|
|
|
|
output.add_row(["checksum", fractal_data['checksum']]) |
|
|
|
|
|
output.add_row(["generated_by", fractal_data['generated_by']]) |
|
|
print(output) |
|
|
print(output) |
|
|
else: |
|
|
else: |
|
|
LOG.error("fractal '%s' not found" % CONF.command.uuid) |
|
|
LOG.error("fractal '%s' not found" % CONF.command.uuid) |
|
@ -123,34 +134,43 @@ def do_list_fractals(): |
|
|
fractals = get_fractals() |
|
|
fractals = get_fractals() |
|
|
output = PrettyTable(["UUID", "Dimensions", "Filesize"]) |
|
|
output = PrettyTable(["UUID", "Dimensions", "Filesize"]) |
|
|
for fractal in fractals: |
|
|
for fractal in fractals: |
|
|
|
|
|
fractal_data = fractal['attributes'] |
|
|
output.add_row([ |
|
|
output.add_row([ |
|
|
fractal["uuid"], |
|
|
|
|
|
"%d x %d pixels" % (fractal["width"], fractal["height"]), |
|
|
|
|
|
"%d bytes" % (fractal["size"] or 0), |
|
|
|
|
|
|
|
|
fractal_data["uuid"], |
|
|
|
|
|
"%d x %d pixels" % (fractal_data["width"], fractal_data["height"]), |
|
|
|
|
|
"%d bytes" % (fractal_data["size"] or 0), |
|
|
]) |
|
|
]) |
|
|
print(output) |
|
|
print(output) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_fractals(page=1): |
|
|
def get_fractals(page=1): |
|
|
result = requests.get("%s/v1/fractal?page=%d" % |
|
|
|
|
|
(CONF.endpoint_url, page)) |
|
|
|
|
|
|
|
|
headers = {'Content-Type': 'application/vnd.api+json', |
|
|
|
|
|
'Accept': 'application/vnd.api+json'} |
|
|
|
|
|
result = requests.get("%s/v1/fractal?page=%d&page[size]=10" % |
|
|
|
|
|
(CONF.endpoint_url, page), |
|
|
|
|
|
headers=headers) |
|
|
|
|
|
LOG.debug("result: %s" % result.text) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fractals = [] |
|
|
fractals = [] |
|
|
if result.status_code == 200: |
|
|
if result.status_code == 200: |
|
|
data = json.loads(result.text) |
|
|
data = json.loads(result.text) |
|
|
if page < data['total_pages']: |
|
|
|
|
|
fractals = data['objects'] + get_fractals(page + 1) |
|
|
|
|
|
|
|
|
if (page * 10) < data['meta']['total']: |
|
|
|
|
|
fractals = data['data'] + get_fractals(page + 1) |
|
|
else: |
|
|
else: |
|
|
return data['objects'] |
|
|
|
|
|
|
|
|
return data['data'] |
|
|
|
|
|
|
|
|
return fractals |
|
|
return fractals |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def do_delete_fractal(): |
|
|
def do_delete_fractal(): |
|
|
LOG.info("deleting fractal %s" % CONF.command.uuid) |
|
|
LOG.info("deleting fractal %s" % CONF.command.uuid) |
|
|
|
|
|
headers = {'Content-Type': 'application/vnd.api+json', |
|
|
|
|
|
'Accept': 'application/vnd.api+json'} |
|
|
result = requests.delete("%s/v1/fractal/%s" % |
|
|
result = requests.delete("%s/v1/fractal/%s" % |
|
|
(CONF.endpoint_url, CONF.command.uuid)) |
|
|
|
|
|
LOG.debug("result: %s" %result) |
|
|
|
|
|
|
|
|
(CONF.endpoint_url, CONF.command.uuid), |
|
|
|
|
|
headers=headers) |
|
|
|
|
|
LOG.debug("result: %s" % result.text) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def do_create_fractal(): |
|
|
def do_create_fractal(): |
|
@ -164,11 +184,11 @@ def do_create_fractal(): |
|
|
for i in range(0, number): |
|
|
for i in range(0, number): |
|
|
task = get_random_task() |
|
|
task = get_random_task() |
|
|
LOG.debug("created task %s" % task) |
|
|
LOG.debug("created task %s" % task) |
|
|
# NOTE(berendt): only necessary when using requests < 2.4.2 |
|
|
|
|
|
headers = {'Content-type': 'application/json', |
|
|
|
|
|
'Accept': 'text/plain'} |
|
|
|
|
|
requests.post("%s/v1/fractal" % CONF.endpoint_url, |
|
|
|
|
|
|
|
|
headers = {'Content-Type': 'application/vnd.api+json', |
|
|
|
|
|
'Accept': 'application/vnd.api+json'} |
|
|
|
|
|
resp = requests.post("%s/v1/fractal" % CONF.endpoint_url, |
|
|
json.dumps(task), headers=headers) |
|
|
json.dumps(task), headers=headers) |
|
|
|
|
|
LOG.debug("resp: %s" % resp.text) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_command_parsers(subparsers): |
|
|
def add_command_parsers(subparsers): |
|
|