-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright 2015 Spanish National Research Council | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
|
||
from ooi.api import base | ||
from ooi.api import network as network_api | ||
from ooi.occi.core import collection | ||
from ooi.occi.infrastructure import compute | ||
from ooi.occi.infrastructure import network | ||
# from ooi.occi.infrastructure import network_link | ||
from ooi.openstack import network as os_network | ||
|
||
|
||
class Controller(base.Controller): | ||
def index(self, req): | ||
tenant_id = req.environ["keystone.token_auth"].user.project_id | ||
req = self._get_req(req, path="/%s/os-floating-ips" % tenant_id) | ||
response = req.get_response(self.app) | ||
floating_ips = self.get_from_response(response, "floating_ips", []) | ||
occi_link_resources = [] | ||
for ip in floating_ips: | ||
if ip["instance_id"]: | ||
net_id = "%s/%s" % (network_api.FLOATING_PREFIX, ip["pool"]) | ||
n = network.NetworkResource(title="network", id=net_id) | ||
c = compute.ComputeResource(title="Compute", | ||
id=ip["instance_id"]) | ||
# TODO(enolfc): get the MAC? | ||
iface = os_network.OSNetworkInterface(c, n, "mac", ip["ip"]) | ||
occi_link_resources.append(iface) | ||
|
||
return collection.Collection(resources=occi_link_resources) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters