def get_stack_topology(request):
    assign = get_tenant_stack_assignment(request.user.tenant_id)
    if not assign:
        return {"network_entities": "{}",
                "network_connections": "{}"}
    hc = heat.heatclient(request)
    # we only want the one that matches the network template
    stacks = [s for s in hc.stacks.list(tenant_id=request.user.tenant_id)
              if s.id == assign.stack_id]
    if not stacks:
        # leftover association
        with bsn_api.Session.begin(subtransactions=True):
            bsn_api.Session.delete(assign)
        return {"network_entities": "",
                "network_connections": ""}
    resources = hc.resources.list(assign.stack_id)
    entities = {}
    connections = []
    for res in resources:
        if res.resource_type in ('OS::Neutron::Router', 'OS::Neutron::Subnet'):
            entities[res.physical_resource_id] = {
                'properties': {'name': res.physical_resource_id}
            }
        if res.resource_type == 'OS::Neutron::RouterInterface':
            connections.append({
                'source': res.physical_resource_id.split(':subnet_id=')[0],
                'destination': res.physical_resource_id.split('subnet_id=')[-1],
                'expected_connection': 'forward'
            })
    resp = {'assign': assign,
            'network_entities': json.dumps(entities),
            'network_connections': json.dumps(connections),
            'stack_resources': resources,
            'stack': stacks[0]}
    return resp
Exemple #2
0
 def handle(self, request, data):
     try:
         template_id = request.path_info.split('/')[-1]
         try:
             template_db = neutron.networktemplate_get(request, template_id)
         except Exception:
             raise Exception(_("Could not find a template with that ID."))
         # validate the body
         extract_fields_from_body(request, template_db.body)
         templateassignment_dict = {
             'tenant_id': request.user.tenant_id,
             'template_id': template_db.id,
             'stack_id': 'PENDING'}
         neutron.networktemplateassignment_create(
             request, **templateassignment_dict)
         args = {
             'stack_name': "auto-%s" % template_db.name,
             'parameters': data,
             'template': template_db.body
         }
         hc = heat.heatclient(request)
         try:
             req = hc.stacks.create(**args)
         except Exception as e:
             raise e
         neutron.networktemplateassignment_update(
             request, request.user.tenant_id,
             **{'stack_id': req['stack']['id']})
     except Exception as e:
         msg = _("Error loading template: %s") % e
         exceptions.handle(self.request, msg, redirect=self.failure_url)
     return True
def delete_associated_stack(request):
    assign = get_tenant_stack_assignment(request.user.tenant_id)
    if not assign:
        return
    hc = heat.heatclient(request)
    # we only want the one that matches the network template
    stacks = [s for s in hc.stacks.list(tenant_id=request.user.tenant_id)
              if s.id == assign.stack_id]
    if stacks:
        hc.stacks.delete(assign.stack_id)
Exemple #4
0
def delete_associated_stack(request):
    assign = get_tenant_stack_assignment(request.user.tenant_id)
    if not assign:
        return
    hc = heat.heatclient(request)
    # we only want the one that matches the network template
    stacks = [
        s for s in hc.stacks.list(tenant_id=request.user.tenant_id)
        if s.id == assign.stack_id
    ]
    if stacks:
        hc.stacks.delete(assign.stack_id)
Exemple #5
0
def get_stack_topology(request):
    try:
        assign = neutron.networktemplateassignment_get(request,
                                                       request.user.tenant_id)
        networktemplate = neutron.networktemplate_get(request,
                                                      assign.template_id)
    except Exception:
        return {"network_entities": "{}", "network_connections": "{}"}

    hc = heat.heatclient(request)
    # we only want the one that matches the network template
    stacks = [
        s for s in hc.stacks.list(tenant_id=request.user.tenant_id)
        if s.id == assign.stack_id
    ]
    if not stacks:
        # leftover association, delete the assignment
        neutron.networktemplateassignment_delete(request,
                                                 request.user.tenant_id)
        return {"network_entities": "", "network_connections": ""}
    resources = hc.resources.list(assign.stack_id)
    entities = {}
    connections = []
    for res in resources:
        if res.resource_type in ('OS::Neutron::Router', 'OS::Neutron::Subnet'):
            entities[res.physical_resource_id] = {
                'properties': {
                    'name': res.physical_resource_id
                }
            }
        if res.resource_type == 'OS::Neutron::RouterInterface':
            connections.append({
                'source':
                res.physical_resource_id.split(':subnet_id=')[0],
                'destination':
                res.physical_resource_id.split('subnet_id=')[-1],
                'expected_connection':
                'forward'
            })
    resp = {
        'template': networktemplate,
        'assign': assign,
        'network_entities': json.dumps(entities),
        'network_connections': json.dumps(connections),
        'stack_resources': resources,
        'stack': stacks[0]
    }
    return resp
def deploy_instance(request, tid , params):
    template = get_template_by_id(tid)
    with bsn_api.Session.begin(subtransactions=True):
        body = template.body
        db_obj = network_template_db.NetworkTemplateAssignment(
            template_id=tid, tenant_id=request.user.tenant_id,
            stack_id="PENDING")
        bsn_api.Session.add(db_obj)
    args = {
        'stack_name': "auto-%s" % template.template_name,
        'parameters': params,
        'template': body
    }
    hc = heat.heatclient(request)
    req = hc.stacks.create(**args)
    update_assignment_by_tenant_id(
        request.user.tenant_id, {'stack_id': req['stack']['id']})
Exemple #7
0
def deploy_instance(request, tid, params):
    template = get_template_by_id(tid)
    with bsn_api.Session.begin(subtransactions=True):
        body = template.body
        db_obj = network_template_db.NetworkTemplateAssignment(
            template_id=tid,
            tenant_id=request.user.tenant_id,
            stack_id="PENDING")
        bsn_api.Session.add(db_obj)
    args = {
        'stack_name': "auto-%s" % template.template_name,
        'parameters': params,
        'template': body
    }
    hc = heat.heatclient(request)
    req = hc.stacks.create(**args)
    update_assignment_by_tenant_id(request.user.tenant_id,
                                   {'stack_id': req['stack']['id']})
Exemple #8
0
def is_heat_available(request):
    try:
        heat.heatclient(request)
        return True
    except Exception:
        return False
Exemple #9
0
def extract_fields_from_body(request, body):
    hc = heat.heatclient(request)
    res = hc.stacks.validate(template=body)
    return res
Exemple #10
0
def resource_type_show(request, resource_type):
    client = heat.heatclient(request)
    return client.resource_types.get(resource_type)
Exemple #11
0
def resource_type_list(request):
    client = heat.heatclient(request)
    kwargs = {}
    return client.resource_types.list(**kwargs)
def is_heat_available(request):
    try:
        heat.heatclient(request)
        return True
    except:
        return False
def extract_fields_from_body(request, body):
    hc = heat.heatclient(request)
    res = hc.stacks.validate(template=body)
    return res