def load_balancer_example(lb_info, lb_id, status): """ Create load balancer response example """ lb_example = {"name": lb_info["name"], "id": lb_id, "protocol": lb_info["protocol"], "port": lb_info.get("port", 80), "algorithm": lb_info.get("algorithm") or "RANDOM", "status": status, "cluster": {"name": "test-cluster"}, "timeout": lb_info.get("tiemout", 30), "created": {"time": current_time_in_utc()}, "virtualIps": [{"address": "127.0.0.1", "id": 1111, "type": "PUBLIC", "ipVersion": "IPV4"}, {"address": "0000:0000:0000:0000:1111:111b:0000:0000", "id": 1111, "type": "PUBLIC", "ipVersion": "IPV6"}], "sourceAddresses": {"ipv6Public": "0000:0001:0002::00/00", "ipv4Servicenet": "127.0.0.1", "ipv4Public": "127.0.0.1"}, "httpsRedirect": lb_info.get("httpsRedirect", False), "updated": {"time": current_time_in_utc()}, "halfClosed": lb_info.get("halfClosed", False), "connectionLogging": lb_info.get("connectionLogging", {"enabled": False}), "contentCaching": {"enabled": False}} if lb_info.get("nodes"): lb_example.update({"nodes": _format_nodes_on_lb(lb_info["nodes"])}) if lb_info.get("metadata"): lb_example.update({"metadata": _format_meta(lb_info["metadata"])}) return lb_example
def load_balancer_example(lb_info, lb_id, status): """ Create load balancer response example """ lb_example = { "name": lb_info["name"], "id": lb_id, "protocol": lb_info["protocol"], "port": lb_info.get("port", 80), "algorithm": lb_info.get("algorithm") or "RANDOM", "status": status, "cluster": { "name": "test-cluster" }, "timeout": lb_info.get("tiemout", 30), "created": { "time": current_time_in_utc() }, "virtualIps": [{ "address": "127.0.0.1", "id": 1111, "type": "PUBLIC", "ipVersion": "IPV4" }, { "address": "0000:0000:0000:0000:1111:111b:0000:0000", "id": 1111, "type": "PUBLIC", "ipVersion": "IPV6" }], "sourceAddresses": { "ipv6Public": "0000:0001:0002::00/00", "ipv4Servicenet": "127.0.0.1", "ipv4Public": "127.0.0.1" }, "httpsRedirect": lb_info.get("httpsRedirect", False), "updated": { "time": current_time_in_utc() }, "halfClosed": lb_info.get("halfClosed", False), "connectionLogging": lb_info.get("connectionLogging", {"enabled": False}), "contentCaching": { "enabled": False } } if lb_info.get("nodes"): lb_example.update({"nodes": _format_nodes_on_lb(lb_info["nodes"])}) if lb_info.get("metadata"): lb_example.update({"metadata": _format_meta(lb_info["metadata"])}) return lb_example
def server_template(tenant_id, server_info, server_id, status): """ Template used to create server cache. """ server_template = { "OS-DCF:diskConfig": "AUTO", "OS-EXT-STS:power_state": 1, "OS-EXT-STS:task_state": None, "OS-EXT-STS:vm_state": "active", "accessIPv4": "198.101.241.238", "accessIPv6": "2001:4800:780e:0510:d87b:9cbc:ff04:513a", "key_name": None, "addresses": { "private": [ { "addr": "10.180.{0}.{1}".format(randrange(255), randrange(255)), "version": 4 } ], "public": [ { "addr": "198.101.241.{0}".format(randrange(255)), "version": 4 }, { "addr": "2001:4800:780e:0510:d87b:9cbc:ff04:513a", "version": 6 } ] }, "created": current_time_in_utc(), "flavor": { "id": server_info['flavorRef'], "links": [ { "href": "http://localhost:8902/{0}/flavors/{1}".format(tenant_id, server_info[ 'flavorRef']), "rel": "bookmark" } ] }, "hostId": "33ccb6c82f3625748b6f2338f54d8e9df07cc583251e001355569056", "id": server_id, "image": { "id": server_info['imageRef'], "links": [ { "href": "http://localhost:8902/{0}/images/{1}".format(tenant_id, server_info[ 'imageRef']), "rel": "bookmark" } ] }, "links": [ { "href": "http://localhost:8902/v2/{0}/servers/{1}".format(tenant_id, server_id), "rel": "self" }, { "href": "http://localhost:8902/{0}/servers/{1}".format(tenant_id, server_id), "rel": "bookmark" } ], "metadata": server_info.get('metadata'), "name": server_info['name'], "progress": 100, "status": status, "tenant_id": tenant_id, "updated": current_time_in_utc(), "user_id": "170454" } return server_template
def server_template(tenant_id, server_info, server_id, status, current_time=None, ipsegment=lambda: randrange(255), compute_uri_prefix="http://localhost:8902/"): """ Template used to create server cache. """ if current_time is None: current_time = current_time_in_utc() def url(suffix): return str(URLPath.fromString(compute_uri_prefix).child(suffix)) server_template = { "OS-DCF:diskConfig": "AUTO", "OS-EXT-STS:power_state": 1, "OS-EXT-STS:task_state": None, "OS-EXT-STS:vm_state": "active", "accessIPv4": "198.101.241.238", "accessIPv6": "2001:4800:780e:0510:d87b:9cbc:ff04:513a", "key_name": None, "addresses": { "private": [ { "addr": "10.180.{0}.{1}".format(ipsegment(), ipsegment()), "version": 4 } ], "public": [ { "addr": "198.101.241.{0}".format(ipsegment()), "version": 4 }, { "addr": "2001:4800:780e:0510:d87b:9cbc:ff04:513a", "version": 6 } ] }, "created": current_time, "flavor": { "id": server_info['flavorRef'], "links": [ { "href": compute_uri_prefix + "{0}/flavors/{1}".format( tenant_id, server_info['flavorRef'] ), "rel": "bookmark" } ] }, "hostId": "33ccb6c82f3625748b6f2338f54d8e9df07cc583251e001355569056", "id": server_id, "image": { "id": server_info['imageRef'], "links": [ { "href": url("{0}/images/{1}".format( tenant_id, server_info['imageRef'] )), "rel": "bookmark" } ] }, "links": [ { "href": url("v2/{0}/servers/{1}".format( tenant_id, server_id )), "rel": "self" }, { "href": url("{0}/servers/{1}".format(tenant_id, server_id)), "rel": "bookmark" } ], "metadata": server_info.get('metadata') or {}, "name": server_info['name'], "progress": 100, "status": status, "tenant_id": tenant_id, "updated": current_time, "user_id": "170454" } return server_template
def server_template(tenant_id, server_info, server_id, status, current_time=None, ipsegment=lambda: randrange(255), compute_uri_prefix="http://localhost:8902/"): """ Template used to create server cache. """ if current_time is None: current_time = current_time_in_utc() def url(suffix): return str(URLPath.fromString(compute_uri_prefix).child(suffix)) server_template = { "OS-DCF:diskConfig": "AUTO", "OS-EXT-STS:power_state": 1, "OS-EXT-STS:task_state": None, "OS-EXT-STS:vm_state": "active", "accessIPv4": "198.101.241.238", "accessIPv6": "2001:4800:780e:0510:d87b:9cbc:ff04:513a", "key_name": None, "addresses": { "private": [{ "addr": "10.180.{0}.{1}".format(ipsegment(), ipsegment()), "version": 4 }], "public": [{ "addr": "198.101.241.{0}".format(ipsegment()), "version": 4 }, { "addr": "2001:4800:780e:0510:d87b:9cbc:ff04:513a", "version": 6 }] }, "created": current_time, "flavor": { "id": server_info['flavorRef'], "links": [{ "href": compute_uri_prefix + "{0}/flavors/{1}".format(tenant_id, server_info['flavorRef']), "rel": "bookmark" }] }, "hostId": "33ccb6c82f3625748b6f2338f54d8e9df07cc583251e001355569056", "id": server_id, "image": { "id": server_info['imageRef'], "links": [{ "href": url("{0}/images/{1}".format(tenant_id, server_info['imageRef'])), "rel": "bookmark" }] }, "links": [{ "href": url("v2/{0}/servers/{1}".format(tenant_id, server_id)), "rel": "self" }, { "href": url("{0}/servers/{1}".format(tenant_id, server_id)), "rel": "bookmark" }], "metadata": server_info.get('metadata') or {}, "name": server_info['name'], "progress": 100, "status": status, "tenant_id": tenant_id, "updated": current_time, "user_id": "170454" } return server_template