Esempio n. 1
0
 def get_data(self):
     try:
         volume_id = self.kwargs['volume_id']
         volume = cinder.volume_get(self.request, volume_id)
         search_opts = self.get_search_opts(volume)
         snapshots = cinder.volume_snapshot_list(self.request,
                                                 search_opts=search_opts)
         if snapshots:
             setattr(volume, 'has_snapshot', True)
         for att in volume.attachments:
             att['instance'] = nova.server_get(self.request,
                                               att['server_id'])
     except Exception:
         redirect = self.get_redirect_url()
         exceptions.handle(self.request,
                           _('Unable to retrieve volume details.'),
                           redirect=redirect)
     try:
         volume.messages = cinder.message_list(
             self.request,
             {
                 'resource_type': 'volume',
                 'resource_uuid': volume.id
             },
         )
     except Exception:
         volume.messages = []
         exceptions.handle(
             self.request,
             _('Unable to retrieve volume messages.'),
             ignore=True,
         )
     return volume, snapshots
Esempio n. 2
0
def volume_get(request, volume_id):
    volume_data = cinderclient(request).volumes.get(volume_id)

    for attachment in volume_data.attachments:
        if "server_id" in attachment:
            try:
                instance = nova.server_get(request, attachment['server_id'])
                attachment['instance_name'] = instance.name
            except Exception:
                LOG.error("Invalid server:(%s) for volume:(%s)",
                          (attachment['server_id'], volume_id))
                attachment['instance_name'] = _("Unknown instance")
        else:
            # Nova volume can occasionally send back error'd attachments
            # the lack a server_id property; to work around that we'll
            # give the attached instance a generic name.
            attachment['instance_name'] = _("Unknown instance")

    volume_data.transfer = None
    if volume_data.status == 'awaiting-transfer':
        for transfer in transfer_list(request):
            if transfer.volume_id == volume_id:
                volume_data.transfer = transfer
                break

    return Volume(volume_data)
Esempio n. 3
0
 def get(cls, request, uuid):
     node = NodeClient(request).node_class.get(request, uuid)
     if node.instance_uuid is not None:
         server = nova.server_get(request, node.instance_uuid)
     else:
         server = None
     return cls(node, instance=server, request=request)
Esempio n. 4
0
    def get_by_instance_uuid(cls, request, instance_uuid):
        """Return the Node in Ironic associated with the instance ID

        :param request: request object
        :type  request: django.http.HttpRequest

        :param instance_uuid: ID of Instance that is deployed on the Node
                              to be retrieved
        :type  instance_uuid: str

        :return: matching Node
        :rtype:  tuskar_ui.api.Node

        :raises: ironicclient.exc.HTTPNotFound if there is no Node with the
                 matching instance UUID
        """
        # TODO(Tzu-Mainn Chen): remove test data when possible
        # node = ironicclient(request).nodes.get_by_instance_uuid(
        #    instance_uuid)

        server = nova.server_get(request, instance_uuid)
        nodes = baremetalclient(request).list()

        node = next((n for n in nodes if instance_uuid == n.instance_uuid),
                    None)

        return cls(node, instance=server, request=request)
Esempio n. 5
0
 def get_data(self):
     try:
         volume_id = self.kwargs['volume_id']
         volume = cinder.volume_get(self.request, volume_id)
         search_opts = self.get_search_opts(volume)
         snapshots = cinder.volume_snapshot_list(
             self.request, search_opts=search_opts)
         if snapshots:
             setattr(volume, 'has_snapshot', True)
         for att in volume.attachments:
             att['instance'] = nova.server_get(self.request,
                                               att['server_id'])
     except Exception:
         redirect = self.get_redirect_url()
         exceptions.handle(self.request,
                           _('Unable to retrieve volume details.'),
                           redirect=redirect)
     try:
         volume.messages = cinder.message_list(
             self.request,
             {'resource_type': 'volume', 'resource_uuid': volume.id},
         )
     except Exception:
         volume.messages = []
         exceptions.handle(
             self.request,
             _('Unable to retrieve volume messages.'),
             ignore=True,
         )
     return volume, snapshots
Esempio n. 6
0
def getStackResourcesThread(request, stack):
    # LOG.info('\n\n\nStack: %s - %s - Project: %s\n\n', stack.id, stack.stack_name, stack.project)
    #global fixed_heat_endpoint
    global stacks_obj
    temp_endpoint = fixed_heat_endpoint.replace('%(tenant_id)s', stack.project)

    keystone_temp = ksclient.Client(auth_url=ENV_OS_AUTH_URL,
                                    username=ENV_OS_USERNAME,
                                    password=ENV_OS_PASSWORD,
                                    tenant_id=stack.project)

    heat_temp = heat_client.Client(ENV_HEAT_OS_API_VERSION,
                                   endpoint=temp_endpoint,
                                   token=keystone_temp.auth_token)

    resources_obj = []
    for resource in heat_temp.resources.list(stack.id):
        if resource.resource_type == "OS::Nova::Server":
            server = nova.server_get(request, resource.physical_resource_id)
            resources_obj.append({
                "resource_id": resource.physical_resource_id,
                "resource_name": server.name
            })

    stacks_obj.append({
        "stack_id": stack.id,
        "stack_name": stack.stack_name,
        "resources": resources_obj
    })
Esempio n. 7
0
    def get(cls, request, uuid):
        node = NodeClient(request).node_class.get(request, uuid)

        if node.instance_uuid is not None:
            server = nova.server_get(request, node.instance_uuid)
            return cls(node, instance=server, request=request)

        return cls(node)
Esempio n. 8
0
def wait_instance_active(request, instance_id, interval):
    """Wait Instance Active"""
    while True:
        instance = nova.server_get(request, instance_id)
        LOG.debug("Instance Status : {}".format(instance.status))
        if instance.status == "ACTIVE":
            break
        sleep(interval)
    LOG.debug("Instance Create Complete")
    return instance
Esempio n. 9
0
 def get_context_data(self, request):
     volume_id = self.tab_group.kwargs["volume_id"]
     try:
         volume = cinder.volume_get(request, volume_id)
         for att in volume.attachments:
             att["instance"] = nova.server_get(request, att["server_id"])
     except:
         redirect = reverse("horizon:project:volumes:index")
         exceptions.handle(self.request, _("Unable to retrieve volume details."), redirect=redirect)
     return {"volume": volume}
Esempio n. 10
0
 def get_object(self):
     if not hasattr(self, "_object"):
         try:
             self._object = novaapi.server_get(self.request,
                                               self.kwargs["instance_id"])
         except:
             redirect = reverse('horizon:project:veta:index')
             exceptions.handle(self.request,
                               _("Unable to retrieve instance."),
                               redirect=redirect)
     return self._object
Esempio n. 11
0
 def get_context_data(self, request):
     volume_id = self.tab_group.kwargs['volume_id']
     try:
         volume = cinder.volume_get(request, volume_id)
         for att in volume.attachments:
             att['instance'] = nova.server_get(request, att['server_id'])
     except Exception:
         redirect = reverse('horizon:project:volumes:index')
         exceptions.handle(self.request,
                           _('Unable to retrieve volume details.'),
                           redirect=redirect)
     return {'volume': volume}
Esempio n. 12
0
 def get_context_data(self, request):
     volume_id = self.tab_group.kwargs['volume_id']
     try:
         volume = cinder.volume_get(request, volume_id)
         for att in volume.attachments:
             att['instance'] = nova.server_get(request, att['server_id'])
     except Exception:
         redirect = reverse('horizon:project:volumes:index')
         exceptions.handle(self.request,
                           _('Unable to retrieve volume details.'),
                           redirect=redirect)
     return {'volume': volume}
def volume_get(request, volume_id):
    volume_data = cinderclient(request).volumes.get(volume_id)
    for attachment in volume_data.attachments:
        if "server_id" in attachment:
            instance = nova.server_get(request, attachment['server_id'])
            attachment['instance_name'] = instance.name
        else:
            # Nova volume can occasionally send back error'd attachments
            # the lack a server_id property; to work around that we'll
            # give the attached instance a generic name.
            attachment['instance_name'] = _("Unknown instance")
    return volume_data
Esempio n. 14
0
def volume_get(request, volume_id):
    volume_data = cinderclient(request).volumes.get(volume_id)

    for attachment in volume_data.attachments:
        if "server_id" in attachment:
            instance = nova.server_get(request, attachment['server_id'])
            attachment['instance_name'] = instance.name
        else:
            # Nova volume can occasionally send back error'd attachments
            # the lack a server_id property; to work around that we'll
            # give the attached instance a generic name.
            attachment['instance_name'] = _("Unknown instance")
    return Volume(volume_data)
Esempio n. 15
0
 def get_context_data(self, request):
     server_group_id = self.tab_group.kwargs['server_group_id']
     try:
         server_group = stx_nova.server_group_get(request, server_group_id)
         server_group.members_display = []
         for member in server_group.members:
             server_group.members_display.append(
                 dict(id=member, instance=nova.server_get(request, member)))
     except Exception:
         redirect = reverse('horizon:project:server_groups:index')
         exceptions.handle(self.request,
                           _('Unable to retrieve server group details.'),
                           redirect=redirect)
     return {'server_group': server_group}
Esempio n. 16
0
    def instance(self):
        """Return the Nova Instance associated with this Node

        :return: Nova Instance associated with this Node; or
                 None if there is no Instance associated with this
                 Node, or no matching Instance is found
        :rtype:  tuskar_ui.api.Instance
        """
        if hasattr(self, '_instance'):
            return self._instance

        if self.instance_uuid:
            server = nova.server_get(self._request, self.instance_uuid)
            return server

        return None
Esempio n. 17
0
 def get_data(self):
     try:
         volume_id = self.kwargs['volume_id']
         volume = cinder.volume_get(self.request, volume_id)
         snapshots = cinder.volume_snapshot_list(
             self.request, search_opts={'volume_id': volume.id})
         if snapshots:
             setattr(volume, 'has_snapshot', True)
         for att in volume.attachments:
             att['instance'] = nova.server_get(self.request,
                                               att['server_id'])
     except Exception:
         redirect = self.get_redirect_url()
         exceptions.handle(self.request,
                           _('Unable to retrieve volume details.'),
                           redirect=redirect)
     return volume
Esempio n. 18
0
 def get_data(self):
     try:
         volume_id = self.kwargs['volume_id']
         volume = cinder.volume_get(self.request, volume_id)
         snapshots = cinder.volume_snapshot_list(
             self.request, search_opts={'volume_id': volume.id})
         if snapshots:
             setattr(volume, 'has_snapshot', True)
         for att in volume.attachments:
             att['instance'] = nova.server_get(self.request,
                                               att['server_id'])
     except Exception:
         redirect = self.get_redirect_url()
         exceptions.handle(self.request,
                           _('Unable to retrieve volume details.'),
                           redirect=redirect)
     return volume
Esempio n. 19
0
    def get(cls, request, uuid):
        """Return the Node that matches the ID

        :param request: request object
        :type  request: django.http.HttpRequest

        :param uuid: ID of Node to be retrieved
        :type  uuid: str

        :return: matching Node, or None if no IronicNode matches the ID
        :rtype:  tuskar_ui.api.node.Node
        """
        node = ironicclient(request).node.get(uuid)
        if node.instance_uuid is not None:
            server = nova.server_get(request, node.instance_uuid)
        else:
            server = None
        return cls(node, request, server)
Esempio n. 20
0
def get_cluster_nodes(request, cluster_id):
    token = request.user.token.id
    resp = requests.get(
        get_savanna_address(request) + "/clusters/" + cluster_id,
        headers={"x-auth-token": token})
    nodes = resp.json()["cluster"]["nodes"]
    nodes_with_id = []
    for node in nodes:
        vm = nova.server_get(request, node["vm_id"])
        addresses = []
        for network, address in vm.addresses.items():
            addresses.extend(address)

        nodes_with_id.append(ClusterNode(vm.id, "%s (%s)" % (vm.name, ", ".join(
            [elem['addr'].__str__() for elem in addresses])),
            node["node_template"]["name"],
            node["node_template"]["id"]))

    return nodes_with_id
Esempio n. 21
0
    def get_by_instance_uuid(cls, request, instance_uuid):
        """Return the Node associated with the instance ID

        :param request: request object
        :type  request: django.http.HttpRequest

        :param instance_uuid: ID of Instance that is deployed on the Node
                              to be retrieved
        :type  instance_uuid: str

        :return: matching Node
        :rtype:  tuskar_ui.api.node.Node

        :raises: ironicclient.exc.HTTPNotFound if there is no Node with
                 the matching instance UUID
        """
        node = ironicclient(request).node.get_by_instance_uuid(instance_uuid)
        server = nova.server_get(request, instance_uuid)
        return cls(node, request, server)
Esempio n. 22
0
def getStackResourcesThread(request, stack):
    # LOG.info('\n\n\nStack: %s - %s - Project: %s\n\n', stack.id, stack.stack_name, stack.project)
    # global fixed_heat_endpoint
    global stacks_obj
    temp_endpoint = fixed_heat_endpoint.replace("%(tenant_id)s", stack.project)

    keystone_temp = ksclient.Client(
        auth_url=ENV_OS_AUTH_URL, username=ENV_OS_USERNAME, password=ENV_OS_PASSWORD, tenant_id=stack.project
    )

    heat_temp = heat_client.Client(ENV_HEAT_OS_API_VERSION, endpoint=temp_endpoint, token=keystone_temp.auth_token)

    resources_obj = []
    for resource in heat_temp.resources.list(stack.id):
        if resource.resource_type == "OS::Nova::Server":
            server = nova.server_get(request, resource.physical_resource_id)
            resources_obj.append({"resource_id": resource.physical_resource_id, "resource_name": server.name})

    stacks_obj.append({"stack_id": stack.id, "stack_name": stack.stack_name, "resources": resources_obj})
Esempio n. 23
0
def get_cluster_nodes(request, cluster_id):
    token = request.user.token.id
    resp = requests.get(get_savanna_address(request) + "/clusters/" +
                        cluster_id,
                        headers={"x-auth-token": token})
    nodes = resp.json()["cluster"]["nodes"]
    nodes_with_id = []
    for node in nodes:
        vm = nova.server_get(request, node["vm_id"])
        addresses = []
        for network, address in vm.addresses.items():
            addresses.extend(address)

        nodes_with_id.append(
            ClusterNode(
                vm.id, "%s (%s)" % (vm.name, ", ".join(
                    [elem['addr'].__str__() for elem in addresses])),
                node["node_template"]["name"], node["node_template"]["id"]))

    return nodes_with_id
Esempio n. 24
0
def create_snapshot(request, instance_id, status_check_interval):
    """Create Snapshot"""
    instance = nova.server_get(request, instance_id)
    snapshot_id = nova.snapshot_create(request, instance.id, instance.name)
    LOG.debug("Target instance name : {} ({})".format(instance.name,
                                                      instance.id))
    LOG.debug("Snapshot id : {}".format(snapshot_id))
    image = glance.image_get(request, snapshot_id)
    LOG.debug("Snapshot Image : {}".format(image))
    # TODO : from oslo_service.loopingcall import FixedIntervalLoopingCall should be applied
    while True:
        image = glance.image_get(request, snapshot_id)
        if (image or image.status) is None:
            LOG.error("Instance Snapshot Fail")
            break
        LOG.debug("Instance Snapshot Status : {}".format(image.status))
        sleep(status_check_interval)
        if image.status == "active":
            LOG.debug("Instance Snapshot Complete : {}".format(image))
            break
    return image
Esempio n. 25
0
def volume_get(request, volume_id):
    volume_data = cinderclient(request).volumes.get(volume_id)

    for attachment in volume_data.attachments:
        if "server_id" in attachment:
            instance = nova.server_get(request, attachment['server_id'])
            attachment['instance_name'] = instance.name
        else:
            # Nova volume can occasionally send back error'd attachments
            # the lack a server_id property; to work around that we'll
            # give the attached instance a generic name.
            attachment['instance_name'] = _("Unknown instance")

    volume_data.transfer = None
    if volume_data.status == 'awaiting-transfer':
        for transfer in transfer_list(request):
            if transfer.volume_id == volume_id:
                volume_data.transfer = transfer
                break

    return Volume(volume_data)
Esempio n. 26
0
def volume_get(request, volume_id):
    client = _cinderclient_with_generic_groups(request)
    volume_data = client.volumes.get(volume_id)

    for attachment in volume_data.attachments:
        if "server_id" in attachment:
            instance = nova.server_get(request, attachment['server_id'])
            attachment['instance_name'] = instance.name
        else:
            # Nova volume can occasionally send back error'd attachments
            # the lack a server_id property; to work around that we'll
            # give the attached instance a generic name.
            attachment['instance_name'] = _("Unknown instance")

    volume_data.transfer = None
    if volume_data.status == 'awaiting-transfer':
        for transfer in transfer_list(request):
            if transfer.volume_id == volume_id:
                volume_data.transfer = transfer
                break

    return Volume(volume_data)
Esempio n. 27
0
    def get(cls, request, uuid):
        """Return the Node in Ironic that matches the ID

        :param request: request object
        :type  request: django.http.HttpRequest

        :param uuid: ID of Node to be retrieved
        :type  uuid: str

        :return: matching Node, or None if no Node matches the ID
        :rtype:  tuskar_ui.api.Node
        """
        # TODO(Tzu-Mainn Chen): remove test data when possible
        # node = ironicclient(request).nodes.get(uuid)

        node = baremetalclient(request).get(uuid)

        if node.instance_uuid is not None:
            server = nova.server_get(request, node.instance_uuid)
            return cls(node, instance=server, request=request)

        return cls(node)
def getVmsAppNameThread(request, stack, stacks_obj):
    # LOG.info('\n\n\nStack: %s - %s - Project: %s\n\n', stack.id, stack.stack_name, stack.project)
    global fixed_heat_endpoint
    temp_endpoint = fixed_heat_endpoint.replace('%(tenant_id)s', stack.project)

    keystone_temp = ksclient.Client(auth_url=ENV_OS_AUTH_URL,
                                    username=ENV_OS_USERNAME,
                                    password=ENV_OS_PASSWORD,
                                    tenant_id=stack.project)

    heat_temp = heat_client.Client(ENV_HEAT_OS_API_VERSION,
                                   endpoint=temp_endpoint,
                                   token=keystone_temp.auth_token)

    resources_obj = []
    for resource in heat_temp.resources.list(stack.id):
        if resource.resource_type == "OS::Nova::Server":
            server = nova.server_get(request, resource.physical_resource_id)
            resources_obj.append({
                "resource_id": resource.physical_resource_id,
                "resource_name": server.name
            })

    template = heat_temp.stacks.template(stack.id)
    template_params = template.get("parameters")

    application_name = "--"
    if ("application_name" in json.dumps(template_params)):
        application_name = template_params["application_name"]["default"]

    LOG.debug('Appending stack resources: %s', stack.stack_name)
    stacks_obj.append({
        "stack_id": stack.id,
        "stack_name": stack.stack_name,
        "application_name": application_name,
        "resources": resources_obj
    })
Esempio n. 29
0
 def get_by_instance_uuid(cls, request, instance_uuid):
     node = NodeClient(request).node_class.get_by_instance_uuid(
         request, instance_uuid)
     server = nova.server_get(request, instance_uuid)
     return cls(node, instance=server, request=request)
Esempio n. 30
0
 def display_instance(self):
     try:
         instance = nova.server_get(self.request, self.port['device_id'])
         return instance.name
     except:
         return '--'
Esempio n. 31
0
 def get_by_instance_uuid(cls, request, instance_uuid):
     node = NodeClient(request).node_class.get_by_instance_uuid(
         request, instance_uuid)
     server = nova.server_get(request, instance_uuid)
     return cls(node, instance=server, request=request)
 def display_instance(self):
     try:
         instance = nova.server_get(self.request, self.port['device_id'])
         return instance.name
     except:
         return '--'