Commit 227ccc21 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Create server in public net with FIP

Remove 'floating_ips' extension attribute to POST /servers API call.
Instead use the 'fixed_ip' attribute of 'networks' attribute to specify
the IPv4 address of a floating IP. So in order to create a server
connected to a private network and a public network, the 'networks'
attribute will be:
[{"uuid": "<private-network-uuid>"},
 {"uuid": "<floating-ip-network-uuid>",
  "fixed_ip": "<floating-ip-address>"}]
parent 395f0023
......@@ -380,8 +380,6 @@ def create_server(request):
assert isinstance(personality, list)
networks = server.get("networks", [])
assert isinstance(networks, list)
floating_ips = server.get("floating_ips", [])
assert isinstance(floating_ips, list)
except (KeyError, AssertionError):
raise faults.BadRequest("Malformed request")
......@@ -396,8 +394,7 @@ def create_server(request):
vm = servers.create(user_id, name, password, flavor, image,
metadata=metadata, personality=personality,
networks=networks,
floating_ips=floating_ips)
networks=networks)
server = vm_to_dict(vm, detail=True)
server['status'] = 'BUILD'
......
......@@ -498,7 +498,7 @@ class ServerCreateAPITest(ComputeAPITest):
DEFAULT_INSTANCE_NETWORKS=["SNF:ANY_PUBLIC"]):
response = self.mypost('servers', 'test_user',
json.dumps(request), 'json')
self.assertFault(response, 403, "forbidden")
self.assertBadRequest(response)
# test wrong user
request = deepcopy(self.request)
......@@ -512,7 +512,6 @@ class ServerCreateAPITest(ComputeAPITest):
# Test floating IPs
request = deepcopy(self.request)
request["server"]["networks"] = [{"uuid": bnet1.network.id}]
fp1 = mfactory.FloatingIPFactory(address="10.0.0.2",
userid="test_user",
network=self.network,
......@@ -521,7 +520,11 @@ class ServerCreateAPITest(ComputeAPITest):
userid="test_user",
network=self.network,
nic=None)
request["server"]["floating_ips"] = [fp1.id, fp2.id]
request["server"]["networks"] = [{"uuid": bnet1.network.id},
{"uuid": fp1.network.id,
"fixed_ip": fp1.address},
{"uuid": fp2.network.id,
"fixed_ip": fp2.address}]
with override_settings(settings,
DEFAULT_INSTANCE_NETWORKS=[bnet3.network.id]):
with mocked_quotaholder():
......@@ -538,12 +541,12 @@ class ServerCreateAPITest(ComputeAPITest):
self.assertEqual(len(kwargs["nics"]), 4)
self.assertEqual(kwargs["nics"][0]["network"],
bnet3.network.backend_id)
self.assertEqual(kwargs["nics"][1]["network"], fp1.network.backend_id)
self.assertEqual(kwargs["nics"][1]["ip"], fp1.address)
self.assertEqual(kwargs["nics"][2]["network"], fp2.network.backend_id)
self.assertEqual(kwargs["nics"][2]["ip"], fp2.address)
self.assertEqual(kwargs["nics"][3]["network"],
self.assertEqual(kwargs["nics"][1]["network"],
bnet1.network.backend_id)
self.assertEqual(kwargs["nics"][2]["network"], fp1.network.backend_id)
self.assertEqual(kwargs["nics"][2]["ip"], fp1.address)
self.assertEqual(kwargs["nics"][3]["network"], fp2.network.backend_id)
self.assertEqual(kwargs["nics"][3]["ip"], fp2.address)
def test_create_server_no_flavor(self, mrapi):
request = deepcopy(self.request)
......
......@@ -274,14 +274,24 @@ def create_instance_nics(vm, userid, networks=[], floating_ips=[]):
port = util.get_port(port_id, userid, for_update=True)
ports.append(port)
elif net_id is not None:
address = net.get("fixed_ip")
network = util.get_network(net_id, userid, non_deleted=True)
if network.public:
raise faults.Forbidden("Can not connect to public network")
address = net.get("fixed_ip")
port = _create_port(userid, network, address=address)
if address is None:
msg = ("Can not connect to public network %s. Specify"
" 'fixed_ip'" " attribute to connect to a public"
" network")
raise faults.BadRequest(msg % network.id)
floating_ip = util.get_floating_ip_by_address(userid,
address,
for_update=True)
port = _create_port(userid, network, use_ipaddress=floating_ip)
else:
port = _create_port(userid, network, address=address)
ports.append(port)
else:
raise faults.BadRequest("")
raise faults.BadRequest("Network 'uuid' or 'port' attribute"
" is required.")
for index, port in enumerate(ports):
associate_port_with_machine(port, vm)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment