Esempio n. 1
0
    def handle(self, request, data):
        try:
            assign = neutron.networktemplateassignment_get(
                request, request.user.tenant_id)
            # we only want the one that matches the network template
            stack = heat.stack_get(request, assign.stack_id)
            if not stack:
                msg = _('Stack instance %(stack_id)s could not be found. '
                        'Deleting the network template association '
                        '%(assign_id)s.') % {'stack_id': assign.stack_id,
                                             'assign_id': assign.id}
                LOG.error(msg)
                messages.error(request, msg)
            else:
                # stack found, delete it
                heat.stack_delete(request, assign.stack_id)
                stack = heat.stack_get(request, assign.stack_id)
                if stack.stack_status not in \
                        ['DELETE_IN_PROGRESS', 'DELETE_COMPLETED']:
                    msg = _('Stack instance %(stack_name)s could not be '
                            'deleted. Reason: %(status_reason)s. Skipping '
                            'network template removal.') % \
                        {'stack_name': stack.stack_name,
                         'status_reason': stack.stack_status_reason}
                    LOG.error(msg)
                    messages.error(request, msg)
                    return False

                msg = _('Stack %s delete in progress..') % assign.stack_id
                LOG.info(msg)
                messages.warning(request, msg)
            return True
        except Exception as e:
            messages.error(request, e)
            return False
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
 def __init__(self, *args, **kwargs):
     super(ApplyTemplateForm, self).__init__(*args, **kwargs)
     try:
         template_id = self.request.path_info.split('/')[-1]
         try:
             template_db = neutron.networktemplate_get(
                 self.request, template_id)
         except Exception:
             raise Exception(_("Could not find a template with that ID."))
         try:
             assign = neutron.networktemplateassignment_get(
                 self.request, self.request.user.tenant_id)
             if assign:
                 raise Exception(
                     _("This tenant has already deployed "
                       "a network template."))
         except Exception:
             pass
         template = extract_fields_from_body(self.request, template_db.body)
         # Sorts the parameters in the template.
         parameters = list(template['Parameters'].keys())
         parameters.sort()
         parameters.reverse()
         # Populates the form dynamically with information from the template
         for parameter in parameters:
             self.fields[parameter] = forms.CharField(
                 max_length="255",
                 label=template['Parameters'][parameter]['Label'],
                 initial=findDefault(template['Parameters'][parameter],
                                     'Default'),
                 help_text=template['Parameters'][parameter]['Description'],
                 required=True)
     except Exception as e:
         msg = _("Failed preparing template. You may not have "
                 "permissions to use Heat templates. %s") % e
         exceptions.handle(self.request,
                           msg,
                           redirect=reverse(self.failure_url))