Implement creating Bay using heat
Co-authored-by: Steven Dake <sdake@redhat.com> Implements-blueprint: backend-bay-heat-kube Change-Id: Ia544d8bd3bc03afa900247b8da09675c0c6aec71
This commit is contained in:
parent
f1fbce758d
commit
6ad1fb26a4
@ -21,7 +21,7 @@ import sys
|
|||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from magnum.common import rpc_service as service
|
from magnum.common import rpc_service as service
|
||||||
from magnum.conductor.handlers import bay_ironic as bay_ironic
|
from magnum.conductor.handlers import bay_k8s_heat
|
||||||
from magnum.conductor.handlers import docker_conductor
|
from magnum.conductor.handlers import docker_conductor
|
||||||
from magnum.conductor.handlers import kube as k8s_conductor
|
from magnum.conductor.handlers import kube as k8s_conductor
|
||||||
from magnum.openstack.common._i18n import _
|
from magnum.openstack.common._i18n import _
|
||||||
@ -43,7 +43,7 @@ def main():
|
|||||||
endpoints = [
|
endpoints = [
|
||||||
docker_conductor.Handler(),
|
docker_conductor.Handler(),
|
||||||
k8s_conductor.Handler(),
|
k8s_conductor.Handler(),
|
||||||
bay_ironic.Handler()
|
bay_k8s_heat.Handler()
|
||||||
]
|
]
|
||||||
server = service.Service(cfg.CONF.conductor.topic,
|
server = service.Service(cfg.CONF.conductor.topic,
|
||||||
cfg.CONF.conductor.host, endpoints)
|
cfg.CONF.conductor.host, endpoints)
|
||||||
|
@ -12,9 +12,10 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from heatclient.common import template_utils
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from magnum.common import heat
|
from magnum.common import clients
|
||||||
from magnum import objects
|
from magnum import objects
|
||||||
from magnum.openstack.common._i18n import _
|
from magnum.openstack.common._i18n import _
|
||||||
from magnum.openstack.common import log as logging
|
from magnum.openstack.common import log as logging
|
||||||
@ -22,7 +23,8 @@ from magnum.openstack.common import log as logging
|
|||||||
|
|
||||||
k8s_heat_opts = [
|
k8s_heat_opts = [
|
||||||
cfg.StrOpt('template_path',
|
cfg.StrOpt('template_path',
|
||||||
default='/etc/magnum/templates/kubecluster.yaml',
|
default=
|
||||||
|
'/etc/magnum/templates/heat-kubernetes/kubecluster.yaml',
|
||||||
help=_(
|
help=_(
|
||||||
'Location of template to build a k8s cluster. '))]
|
'Location of template to build a k8s cluster. '))]
|
||||||
|
|
||||||
@ -43,25 +45,30 @@ class Handler(object):
|
|||||||
# Bay Operations
|
# Bay Operations
|
||||||
|
|
||||||
def bay_create(self, ctxt, bay):
|
def bay_create(self, ctxt, bay):
|
||||||
if bay.type is not 'k8s_heat':
|
|
||||||
return
|
|
||||||
|
|
||||||
LOG.debug('k8s_heat bay_create')
|
LOG.debug('k8s_heat bay_create')
|
||||||
# 'definition' and 'properties' field are needed.
|
|
||||||
|
osc = clients.OpenStackClients(ctxt)
|
||||||
|
|
||||||
# stack_name is unique on each tenant.
|
# stack_name is unique on each tenant.
|
||||||
stack_name = bay.name
|
stack_name = bay.name
|
||||||
# bay_definition is used for heat parameter
|
bay_model = objects.BayModel.get_by_uuid(ctxt, bay.baymodel_id)
|
||||||
# larsks/heat-kubernetes requires
|
bay_definition = {
|
||||||
# 'ssh_key_name' and 'external_network_id'
|
'ssh_key_name': bay_model.keypair_id,
|
||||||
bay_definition = bay.definition
|
'external_network_id': bay_model.external_network_id,
|
||||||
|
'server_image': bay_model.image_id,
|
||||||
|
'server_flavor': bay_model.flavor_id
|
||||||
|
}
|
||||||
|
tpl_files, template = template_utils.get_template_contents(
|
||||||
|
cfg.CONF.k8s_heat.template_path)
|
||||||
|
|
||||||
heat_client = heat.get_client(ctxt)
|
fields = {
|
||||||
created_stack = heat_client.stacks.create(stack_name=stack_name,
|
'stack_name': stack_name,
|
||||||
template=cfg.CONF.k8s_heat.template_path,
|
'parameters': bay_definition,
|
||||||
parameters=bay_definition)
|
'template': template,
|
||||||
stack_id = created_stack['stack']['id']
|
'files': dict(list(tpl_files.items()))
|
||||||
bay.properties['stack_id'] = stack_id
|
}
|
||||||
|
created_stack = osc.heat().stacks.create(**fields)
|
||||||
|
bay.stack_id = created_stack['stack']['id']
|
||||||
|
|
||||||
bay.create()
|
bay.create()
|
||||||
|
|
||||||
@ -71,31 +78,14 @@ class Handler(object):
|
|||||||
return bay
|
return bay
|
||||||
|
|
||||||
def bay_delete(self, ctxt, uuid):
|
def bay_delete(self, ctxt, uuid):
|
||||||
# if bay.type is not 'k8s_heat':
|
|
||||||
# return
|
|
||||||
|
|
||||||
LOG.debug('k8s_heat bay_delete')
|
LOG.debug('k8s_heat bay_delete')
|
||||||
bay = objects.Bay.get_by_uuid(ctxt, uuid)
|
bay = objects.Bay.get_by_uuid(ctxt, uuid)
|
||||||
stack_id = bay.properties['stack_id']
|
|
||||||
heat.stacks.delete(stack_id)
|
|
||||||
bay.destroy()
|
bay.destroy()
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def bay_show(self, ctxt, uuid):
|
def bay_show(self, ctxt, uuid):
|
||||||
# if bay.type is not 'k8s_heat':
|
|
||||||
# return
|
|
||||||
|
|
||||||
LOG.debug('k8s_heat bay_show')
|
LOG.debug('k8s_heat bay_show')
|
||||||
bay = objects.Bay.get_by_uuid(ctxt, uuid)
|
bay = objects.Bay.get_by_uuid(ctxt, uuid)
|
||||||
stack_id = bay.properties['stack_id']
|
|
||||||
stack = heat.stacks.get(stack_id)
|
|
||||||
|
|
||||||
if stack.status == 'COMPLETE':
|
|
||||||
master_address = stack['outputs'][0]['output_value']
|
|
||||||
minion_addresses = stack['outputs'][2]['output_value']
|
|
||||||
bay.properties['master_address'] = master_address
|
|
||||||
bay.properties['minion_addresses'] = minion_addresses
|
|
||||||
bay.save()
|
|
||||||
|
|
||||||
return bay
|
return bay
|
||||||
|
@ -38,6 +38,9 @@ def upgrade():
|
|||||||
sa.Column('name', sa.String(length=255), nullable=True),
|
sa.Column('name', sa.String(length=255), nullable=True),
|
||||||
sa.Column('baymodel_id', sa.String(length=255), nullable=True),
|
sa.Column('baymodel_id', sa.String(length=255), nullable=True),
|
||||||
sa.Column('node_count', sa.Integer(), nullable=True),
|
sa.Column('node_count', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('master_address', sa.String(length=255), nullable=True),
|
||||||
|
sa.Column('minions_address', sa.Text(), nullable=True),
|
||||||
|
sa.Column('stack_id', sa.String(length=255), nullable=True),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
mysql_ENGINE='InnoDB',
|
mysql_ENGINE='InnoDB',
|
||||||
mysql_DEFAULT_CHARSET='UTF8'
|
mysql_DEFAULT_CHARSET='UTF8'
|
||||||
@ -49,10 +52,9 @@ def upgrade():
|
|||||||
sa.Column('id', sa.Integer(), nullable=False),
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
sa.Column('uuid', sa.String(length=36), nullable=True),
|
sa.Column('uuid', sa.String(length=36), nullable=True),
|
||||||
sa.Column('name', sa.String(length=255), nullable=True),
|
sa.Column('name', sa.String(length=255), nullable=True),
|
||||||
sa.Column('type', sa.String(length=20), nullable=True),
|
|
||||||
sa.Column('image_id', sa.String(length=255), nullable=True),
|
|
||||||
sa.Column('flavor_id', sa.String(length=255), nullable=True),
|
sa.Column('flavor_id', sa.String(length=255), nullable=True),
|
||||||
sa.Column('keypair_id', sa.String(length=255), nullable=True),
|
sa.Column('keypair_id', sa.String(length=255), nullable=True),
|
||||||
|
sa.Column('image_id', sa.String(length=255), nullable=True),
|
||||||
sa.Column('external_network_id', sa.String(length=255), nullable=True),
|
sa.Column('external_network_id', sa.String(length=255), nullable=True),
|
||||||
sa.Column('dns_nameserver', sa.String(length=255), nullable=True),
|
sa.Column('dns_nameserver', sa.String(length=255), nullable=True),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
@ -123,6 +123,9 @@ class Bay(Base):
|
|||||||
uuid = Column(String(36))
|
uuid = Column(String(36))
|
||||||
name = Column(String(255))
|
name = Column(String(255))
|
||||||
baymodel_id = Column(String(255))
|
baymodel_id = Column(String(255))
|
||||||
|
stack_id = Column(String(255))
|
||||||
|
master_address = Column(String(255))
|
||||||
|
minions_address = Column(JSONEncodedList)
|
||||||
node_count = Column(Integer())
|
node_count = Column(Integer())
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,6 +31,9 @@ class Bay(base.MagnumObject):
|
|||||||
'uuid': obj_utils.str_or_none,
|
'uuid': obj_utils.str_or_none,
|
||||||
'name': obj_utils.str_or_none,
|
'name': obj_utils.str_or_none,
|
||||||
'baymodel_id': obj_utils.str_or_none,
|
'baymodel_id': obj_utils.str_or_none,
|
||||||
|
'stack_id': obj_utils.str_or_none,
|
||||||
|
'master_address': obj_utils.str_or_none,
|
||||||
|
'minions_address': obj_utils.list_or_none,
|
||||||
'node_count': obj_utils.int_or_none
|
'node_count': obj_utils.int_or_none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user