Merge "Split instance code into seperate file"
This commit is contained in:
commit
7dcf6123db
@ -24,8 +24,6 @@ from heat.engine import constraints
|
||||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
from heat.engine import scheduler
|
||||
from heat.engine import signal_responder
|
||||
from heat.engine import support
|
||||
from heat.engine import volume_tasks as vol_task
|
||||
from heat.openstack.common import log as logging
|
||||
|
||||
@ -34,89 +32,6 @@ cfg.CONF.import_opt('instance_user', 'heat.common.config')
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Restarter(signal_responder.SignalResponder):
|
||||
|
||||
support_status = support.SupportStatus(
|
||||
support.DEPRECATED,
|
||||
_('The HARestarter resource type is unsupported and will be removed '
|
||||
'in a future release of Heat, once it has support for auto-healing '
|
||||
'any type of resource. Note that HARestarter does *not* actually '
|
||||
'restart servers - it deletes and then recreates them. It also does '
|
||||
'the same to all dependent resources, and may therefore exhibit '
|
||||
'unexpected and undesirable behaviour. Avoid.')
|
||||
)
|
||||
|
||||
PROPERTIES = (
|
||||
INSTANCE_ID,
|
||||
) = (
|
||||
'InstanceId',
|
||||
)
|
||||
|
||||
ATTRIBUTES = (
|
||||
ALARM_URL,
|
||||
) = (
|
||||
'AlarmUrl',
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
INSTANCE_ID: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Instance ID to be restarted.'),
|
||||
required=True,
|
||||
constraints=[
|
||||
constraints.CustomConstraint('nova.server')
|
||||
]
|
||||
),
|
||||
}
|
||||
|
||||
attributes_schema = {
|
||||
ALARM_URL: attributes.Schema(
|
||||
_("A signed url to handle the alarm (Heat extension).")
|
||||
),
|
||||
}
|
||||
|
||||
def handle_create(self):
|
||||
super(Restarter, self).handle_create()
|
||||
self.resource_id_set(self._get_user_id())
|
||||
|
||||
def handle_signal(self, details=None):
|
||||
if self.action in (self.SUSPEND, self.DELETE):
|
||||
msg = _('Cannot signal resource during %s') % self.action
|
||||
raise Exception(msg)
|
||||
|
||||
if details is None:
|
||||
alarm_state = 'alarm'
|
||||
else:
|
||||
alarm_state = details.get('state', 'alarm').lower()
|
||||
|
||||
LOG.info(_LI('%(name)s Alarm, new state %(state)s'),
|
||||
{'name': self.name, 'state': alarm_state})
|
||||
|
||||
if alarm_state != 'alarm':
|
||||
return
|
||||
|
||||
target_id = self.properties[self.INSTANCE_ID]
|
||||
victim = self.stack.resource_by_refid(target_id)
|
||||
if victim is None:
|
||||
LOG.info(_LI('%(name)s Alarm, can not find instance '
|
||||
'%(instance)s'),
|
||||
{'name': self.name,
|
||||
'instance': target_id})
|
||||
return
|
||||
|
||||
LOG.info(_LI('%(name)s Alarm, restarting resource: %(victim)s'),
|
||||
{'name': self.name, 'victim': victim.name})
|
||||
self.stack.restart_resource(victim.name)
|
||||
|
||||
def _resolve_attribute(self, name):
|
||||
'''
|
||||
heat extension: "AlarmUrl" returns the url to post to the policy
|
||||
when there is an alarm.
|
||||
'''
|
||||
if name == self.ALARM_URL and self.resource_id is not None:
|
||||
return six.text_type(self._get_signed_url())
|
||||
|
||||
|
||||
class Instance(resource.Resource):
|
||||
|
||||
PROPERTIES = (
|
||||
@ -980,5 +895,4 @@ class Instance(resource.Resource):
|
||||
def resource_mapping():
|
||||
return {
|
||||
'AWS::EC2::Instance': Instance,
|
||||
'OS::Heat::HARestarter': Restarter,
|
||||
}
|
114
heat/engine/resources/openstack/ha_restarter.py
Normal file
114
heat/engine/resources/openstack/ha_restarter.py
Normal file
@ -0,0 +1,114 @@
|
||||
#
|
||||
# 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 six
|
||||
|
||||
from heat.common.i18n import _
|
||||
from heat.common.i18n import _LI
|
||||
from heat.engine import attributes
|
||||
from heat.engine import constraints
|
||||
from heat.engine import properties
|
||||
from heat.engine import signal_responder
|
||||
from heat.engine import support
|
||||
from heat.openstack.common import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Restarter(signal_responder.SignalResponder):
|
||||
|
||||
support_status = support.SupportStatus(
|
||||
support.DEPRECATED,
|
||||
_('The HARestarter resource type is unsupported and will be removed '
|
||||
'in a future release of Heat, once it has support for auto-healing '
|
||||
'any type of resource. Note that HARestarter does *not* actually '
|
||||
'restart servers - it deletes and then recreates them. It also does '
|
||||
'the same to all dependent resources, and may therefore exhibit '
|
||||
'unexpected and undesirable behaviour. Avoid.')
|
||||
)
|
||||
|
||||
PROPERTIES = (
|
||||
INSTANCE_ID,
|
||||
) = (
|
||||
'InstanceId',
|
||||
)
|
||||
|
||||
ATTRIBUTES = (
|
||||
ALARM_URL,
|
||||
) = (
|
||||
'AlarmUrl',
|
||||
)
|
||||
|
||||
properties_schema = {
|
||||
INSTANCE_ID: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Instance ID to be restarted.'),
|
||||
required=True,
|
||||
constraints=[
|
||||
constraints.CustomConstraint('nova.server')
|
||||
]
|
||||
),
|
||||
}
|
||||
|
||||
attributes_schema = {
|
||||
ALARM_URL: attributes.Schema(
|
||||
_("A signed url to handle the alarm (Heat extension).")
|
||||
),
|
||||
}
|
||||
|
||||
def handle_create(self):
|
||||
super(Restarter, self).handle_create()
|
||||
self.resource_id_set(self._get_user_id())
|
||||
|
||||
def handle_signal(self, details=None):
|
||||
if self.action in (self.SUSPEND, self.DELETE):
|
||||
msg = _('Cannot signal resource during %s') % self.action
|
||||
raise Exception(msg)
|
||||
|
||||
if details is None:
|
||||
alarm_state = 'alarm'
|
||||
else:
|
||||
alarm_state = details.get('state', 'alarm').lower()
|
||||
|
||||
LOG.info(_LI('%(name)s Alarm, new state %(state)s'),
|
||||
{'name': self.name, 'state': alarm_state})
|
||||
|
||||
if alarm_state != 'alarm':
|
||||
return
|
||||
|
||||
target_id = self.properties[self.INSTANCE_ID]
|
||||
victim = self.stack.resource_by_refid(target_id)
|
||||
if victim is None:
|
||||
LOG.info(_LI('%(name)s Alarm, can not find instance '
|
||||
'%(instance)s'),
|
||||
{'name': self.name,
|
||||
'instance': target_id})
|
||||
return
|
||||
|
||||
LOG.info(_LI('%(name)s Alarm, restarting resource: %(victim)s'),
|
||||
{'name': self.name, 'victim': victim.name})
|
||||
self.stack.restart_resource(victim.name)
|
||||
|
||||
def _resolve_attribute(self, name):
|
||||
'''
|
||||
heat extension: "AlarmUrl" returns the url to post to the policy
|
||||
when there is an alarm.
|
||||
'''
|
||||
if name == self.ALARM_URL and self.resource_id is not None:
|
||||
return six.text_type(self._get_signed_url())
|
||||
|
||||
|
||||
def resource_mapping():
|
||||
return {
|
||||
'OS::Heat::HARestarter': Restarter,
|
||||
}
|
@ -23,8 +23,8 @@ from heat.common import exception
|
||||
from heat.common import template_format
|
||||
from heat.engine.clients.os import cinder
|
||||
from heat.engine.clients.os import nova
|
||||
from heat.engine.resources.aws import instance
|
||||
from heat.engine.resources.aws import volume as aws_vol
|
||||
from heat.engine.resources import instance
|
||||
from heat.engine import rsrc_defn
|
||||
from heat.engine import scheduler
|
||||
from heat.tests import test_volume_utils as vt_base
|
||||
|
@ -27,7 +27,7 @@ from heat.engine.notification import autoscaling as notification
|
||||
from heat.engine import parser
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources.aws import autoscaling_group as asg
|
||||
from heat.engine.resources import instance
|
||||
from heat.engine.resources.aws import instance
|
||||
from heat.engine.resources import loadbalancer
|
||||
from heat.engine.resources.neutron import loadbalancer as neutron_lb
|
||||
from heat.engine import rsrc_defn
|
||||
|
@ -38,7 +38,7 @@ from heat.engine import dependencies
|
||||
from heat.engine import environment
|
||||
from heat.engine import properties
|
||||
from heat.engine import resource as res
|
||||
from heat.engine.resources import instance as instances
|
||||
from heat.engine.resources.aws import instance as instances
|
||||
from heat.engine import service
|
||||
from heat.engine import service_stack_watch
|
||||
from heat.engine import stack as parser
|
||||
|
@ -22,6 +22,7 @@ import six
|
||||
from heat.common import environment_format
|
||||
from heat.engine import environment
|
||||
from heat.engine import resources
|
||||
from heat.engine.resources.aws import instance
|
||||
from heat.tests import common
|
||||
from heat.tests import generic_resource
|
||||
|
||||
@ -382,7 +383,7 @@ class GlobalEnvLoadingTest(common.HeatTestCase):
|
||||
self.assertIsNone(g_env.get_resource_info('OS::Nova::Server'))
|
||||
|
||||
# 4. make sure we haven't removed something we shouldn't have
|
||||
self.assertEqual(resources.instance.Instance,
|
||||
self.assertEqual(instance.Instance,
|
||||
g_env.get_resource_info('AWS::EC2::Instance').value)
|
||||
|
||||
def test_env_multi_resources_disable(self):
|
||||
@ -423,7 +424,7 @@ class GlobalEnvLoadingTest(common.HeatTestCase):
|
||||
|
||||
# 2. assert global resources are NOT gone.
|
||||
self.assertEqual(
|
||||
resources.instance.Instance,
|
||||
instance.Instance,
|
||||
u_env.get_resource_info('AWS::EC2::Instance').value)
|
||||
|
||||
def test_env_ignore_files_starting_dot(self):
|
||||
|
@ -29,7 +29,7 @@ from heat.engine.clients.os import nova
|
||||
from heat.engine import environment
|
||||
from heat.engine import parser
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources import instance as instances
|
||||
from heat.engine.resources.aws import instance as instances
|
||||
from heat.engine import scheduler
|
||||
from heat.tests import common
|
||||
from heat.tests import utils
|
||||
|
@ -20,7 +20,7 @@ from heat.engine.clients.os import neutron
|
||||
from heat.engine.clients.os import nova
|
||||
from heat.engine import environment
|
||||
from heat.engine import parser
|
||||
from heat.engine.resources import instance as instances
|
||||
from heat.engine.resources.aws import instance as instances
|
||||
from heat.engine.resources import network_interface as network_interfaces
|
||||
from heat.engine import scheduler
|
||||
from heat.tests import common
|
||||
|
@ -19,8 +19,8 @@ from heat.common import identifier
|
||||
from heat.common import template_format
|
||||
from heat.engine import environment
|
||||
from heat.engine import parser
|
||||
from heat.engine.resources.aws import instance
|
||||
from heat.engine.resources.aws import wait_condition_handle as aws_wch
|
||||
from heat.engine.resources import instance
|
||||
from heat.engine.resources import server
|
||||
from heat.engine import scheduler
|
||||
from heat.engine import service
|
||||
|
@ -14,7 +14,7 @@
|
||||
from heat.common import template_format
|
||||
from heat.engine.clients.os import glance
|
||||
from heat.engine.clients.os import nova
|
||||
from heat.engine.resources import instance as instances
|
||||
from heat.engine.resources.aws import instance as instances
|
||||
from heat.engine import scheduler
|
||||
from heat.tests import common
|
||||
from heat.tests import utils
|
||||
|
@ -15,7 +15,8 @@ import mock
|
||||
|
||||
from heat.common import template_format
|
||||
from heat.engine.clients.os import nova
|
||||
from heat.engine.resources import instance
|
||||
from heat.engine.resources.aws import instance
|
||||
from heat.engine.resources.openstack import ha_restarter
|
||||
from heat.engine import scheduler
|
||||
from heat.tests import common
|
||||
from heat.tests import utils
|
||||
@ -46,7 +47,7 @@ class RestarterTest(common.HeatTestCase):
|
||||
snippet = template_format.parse(restarter_template)
|
||||
stack = utils.parse_stack(snippet)
|
||||
resource_defns = stack.t.resource_definitions(stack)
|
||||
restarter = instance.Restarter(
|
||||
restarter = ha_restarter.Restarter(
|
||||
'restarter', resource_defns['restarter'], stack)
|
||||
nova.NovaClientPlugin.get_server = mock.Mock(
|
||||
return_value=mock.MagicMock())
|
||||
|
@ -19,7 +19,7 @@ from heat.engine.clients.os import glance
|
||||
from heat.engine.clients.os import nova
|
||||
from heat.engine import environment
|
||||
from heat.engine import parser
|
||||
from heat.engine.resources import instance as instances
|
||||
from heat.engine.resources.aws import instance as instances
|
||||
from heat.engine import scheduler
|
||||
from heat.tests import common
|
||||
from heat.tests import utils
|
||||
|
@ -29,7 +29,7 @@ from heat.engine.clients.os import nova
|
||||
from heat.engine import environment
|
||||
from heat.engine import parser
|
||||
from heat.engine import resource as rsrc
|
||||
from heat.engine.resources import instance as instances
|
||||
from heat.engine.resources.aws import instance as instances
|
||||
from heat.engine import scheduler
|
||||
from heat.tests import common
|
||||
from heat.tests import utils
|
||||
|
Loading…
Reference in New Issue
Block a user