Remove fping plugin from V3 API

The fping extension, was introduced in
I7d942270aa52bd6216eda0d7ae366ef0195d52a8.  But this doesn't seem like a
good for nova-api.  We have no other 'instance monitoring' support in
nova and doing it out of the nova-api doesn't seem like the right place.

Change-Id: I3e9bd9b1c04aa06b62f1d3d82b0966e69829a620
This commit is contained in:
Joe Gordon 2013-07-11 09:33:35 +01:00
parent 52b43c2f4c
commit beb5699381
6 changed files with 0 additions and 254 deletions

View File

@ -108,8 +108,6 @@
"compute_extension:floating_ips_bulk": "rule:admin_api",
"compute_extension:fping": "",
"compute_extension:fping:all_tenants": "rule:admin_api",
"compute_extension:v3:os-fping": "",
"compute_extension:v3:os-fping:all_tenants": "rule:admin_api",
"compute_extension:hide_server_addresses": "is_admin:False",
"compute_extension:v3:os-hide-server-addresses": "is_admin:False",
"compute_extension:hosts": "rule:admin_api",

View File

@ -1,156 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 Grid Dynamics
# Copyright 2011 OpenStack Foundation
# All Rights Reserved.
#
# 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.
import itertools
import os
from oslo.config import cfg
from webob import exc
from nova.api.openstack import common
from nova.api.openstack import extensions
from nova import compute
from nova import exception
from nova.openstack.common.gettextutils import _
from nova import utils
ALIAS = "os-fping"
authorize = extensions.extension_authorizer('compute', 'v3:' + ALIAS)
authorize_all_tenants = extensions.extension_authorizer(
'compute', 'v3:' + ALIAS + ':all_tenants')
CONF = cfg.CONF
CONF.import_opt('fping_path', 'nova.api.openstack.compute.contrib.fping')
class FpingController(object):
def __init__(self, network_api=None):
self.compute_api = compute.API()
self.last_call = {}
def check_fping(self):
if not os.access(CONF.fping_path, os.X_OK):
raise exc.HTTPServiceUnavailable(
explanation=_("fping utility is not found."))
@staticmethod
def fping(ips):
fping_ret = utils.execute(CONF.fping_path, *ips,
check_exit_code=False)
if not fping_ret:
return set()
alive_ips = set()
for line in fping_ret[0].split("\n"):
ip = line.split(" ", 1)[0]
if "alive" in line:
alive_ips.add(ip)
return alive_ips
@staticmethod
def _get_instance_ips(context, instance):
ret = []
for network in common.get_networks_for_instance(
context, instance).values():
all_ips = itertools.chain(network["ips"], network["floating_ips"])
ret += [ip["address"] for ip in all_ips]
return ret
def index(self, req):
context = req.environ["nova.context"]
search_opts = dict(deleted=False)
if "all_tenants" in req.GET:
authorize_all_tenants(context)
else:
authorize(context)
if context.project_id:
search_opts["project_id"] = context.project_id
else:
search_opts["user_id"] = context.user_id
self.check_fping()
include = req.GET.get("include", None)
if include:
include = set(include.split(","))
exclude = set()
else:
include = None
exclude = req.GET.get("exclude", None)
if exclude:
exclude = set(exclude.split(","))
else:
exclude = set()
instance_list = self.compute_api.get_all(
context, search_opts=search_opts)
ip_list = []
instance_ips = {}
instance_projects = {}
for instance in instance_list:
uuid = instance["uuid"]
if uuid in exclude or (include is not None and
uuid not in include):
continue
ips = [str(ip) for ip in self._get_instance_ips(context, instance)]
instance_ips[uuid] = ips
instance_projects[uuid] = instance["project_id"]
ip_list += ips
alive_ips = self.fping(ip_list)
res = []
for instance_uuid, ips in instance_ips.iteritems():
res.append({
"id": instance_uuid,
"project_id": instance_projects[instance_uuid],
"alive": bool(set(ips) & alive_ips),
})
return {"servers": res}
def show(self, req, id):
try:
context = req.environ["nova.context"]
authorize(context)
self.check_fping()
instance = self.compute_api.get(context, id)
ips = [str(ip) for ip in self._get_instance_ips(context, instance)]
alive_ips = self.fping(ips)
return {
"server": {
"id": instance["uuid"],
"project_id": instance["project_id"],
"alive": bool(set(ips) & alive_ips),
}
}
except exception.NotFound:
raise exc.HTTPNotFound()
class Fping(extensions.V3APIExtensionBase):
"""Fping Management Extension."""
name = "Fping"
alias = ALIAS
namespace = "http://docs.openstack.org/compute/ext/fping/api/v3"
version = 1
def get_resources(self):
resources = [
extensions.ResourceExtension(ALIAS, FpingController())]
return resources
def get_controller_extensions(self):
return []

View File

@ -214,7 +214,6 @@ DEFAULT_LIMITS = [
Limit("GET", "*changes-since*", ".*changes-since.*", 3,
utils.TIME_UNITS['MINUTE']),
Limit("DELETE", "*", ".*", 100, utils.TIME_UNITS['MINUTE']),
Limit("GET", "*/os-fping", "^/os-fping", 12, utils.TIME_UNITS['HOUR']),
]

View File

@ -1,92 +0,0 @@
# Copyright 2011 Grid Dynamics
# Copyright 2011 OpenStack Foundation
# All Rights Reserved.
#
# 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 nova.api.openstack.compute.plugins.v3 import fping
from nova.api.openstack import extensions
from nova import exception
from nova import test
from nova.tests.api.openstack import fakes
import nova.utils
FAKE_UUID = fakes.FAKE_UUID
def execute(*cmd, **args):
return "".join(["%s is alive" % ip for ip in cmd[1:]])
class FpingTest(test.TestCase):
def setUp(self):
super(FpingTest, self).setUp()
self.flags(verbose=True, use_ipv6=False)
return_server = fakes.fake_instance_get()
return_servers = fakes.fake_instance_get_all_by_filters()
self.stubs.Set(nova.db, "instance_get_all_by_filters",
return_servers)
self.stubs.Set(nova.db, "instance_get_by_uuid",
return_server)
self.stubs.Set(nova.utils, "execute",
execute)
self.stubs.Set(fping.FpingController, "check_fping",
lambda self: None)
self.ext_mgr = extensions.ExtensionManager()
self.ext_mgr.extensions = {}
self.controller = fping.FpingController(self.ext_mgr)
def test_fping_index(self):
req = fakes.HTTPRequestV3.blank("/os-fping")
res_dict = self.controller.index(req)
self.assertTrue("servers" in res_dict)
for srv in res_dict["servers"]:
for key in "project_id", "id", "alive":
self.assertTrue(key in srv)
def test_fping_index_policy(self):
req = fakes.HTTPRequestV3.blank("/os-fping?all_tenants=1")
self.assertRaises(exception.NotAuthorized, self.controller.index, req)
req = fakes.HTTPRequestV3.blank("/v2/1234/os-fping?all_tenants=1")
req.environ["nova.context"].is_admin = True
res_dict = self.controller.index(req)
self.assertTrue("servers" in res_dict)
def test_fping_index_include(self):
req = fakes.HTTPRequestV3.blank("/os-fping")
res_dict = self.controller.index(req)
ids = [srv["id"] for srv in res_dict["servers"]]
req = fakes.HTTPRequestV3.blank("/os-fping?include=%s" % ids[0])
res_dict = self.controller.index(req)
self.assertEqual(len(res_dict["servers"]), 1)
self.assertEqual(res_dict["servers"][0]["id"], ids[0])
def test_fping_index_exclude(self):
req = fakes.HTTPRequestV3.blank("/os-fping")
res_dict = self.controller.index(req)
ids = [srv["id"] for srv in res_dict["servers"]]
req = fakes.HTTPRequestV3.blank("/os-fping?exclude=%s" %
",".join(ids[1:]))
res_dict = self.controller.index(req)
self.assertEqual(len(res_dict["servers"]), 1)
self.assertEqual(res_dict["servers"][0]["id"], ids[0])
def test_fping_show(self):
req = fakes.HTTPRequestV3.blank("/os-fping/%s" % FAKE_UUID)
res_dict = self.controller.show(req, FAKE_UUID)
self.assertTrue("server" in res_dict)
srv = res_dict["server"]
for key in "project_id", "id", "alive":
self.assertTrue(key in srv)

View File

@ -185,8 +185,6 @@ policy_data = """
"compute_extension:floating_ips_bulk": "",
"compute_extension:fping": "",
"compute_extension:fping:all_tenants": "is_admin:True",
"compute_extension:v3:os-fping": "",
"compute_extension:v3:os-fping:all_tenants": "is_admin:True",
"compute_extension:hide_server_addresses": "",
"compute_extension:v3:os-hide-server-addresses": "",
"compute_extension:hosts": "",

View File

@ -78,7 +78,6 @@ nova.api.v3.extensions =
flavor_access = nova.api.openstack.compute.plugins.v3.flavor_access:FlavorAccess
flavor_disabled = nova.api.openstack.compute.plugins.v3.flavor_disabled:FlavorDisabled
flavor_rxtx = nova.api.openstack.compute.plugins.v3.flavor_rxtx:FlavorRxtx
fping = nova.api.openstack.compute.plugins.v3.fping:Fping
hide_server_addresses = nova.api.openstack.compute.plugins.v3.hide_server_addresses:HideServerAddresses
hosts = nova.api.openstack.compute.plugins.v3.hosts:Hosts
hypervisors = nova.api.openstack.compute.plugins.v3.hypervisors:Hypervisors