def dispatch_service_vm_real(
        self,
        context,
        instance_name,
        vm_image,
        vm_flavor,
        hosting_device_drv,
        credentials_info,
        connectivity_info,
        ports=None,
    ):
        mgmt_port = connectivity_info["mgmt_port"]
        nics = [{"port-id": mgmt_port["id"]}]
        for port in ports or {}:
            nics.append({"port-id": port["id"]})

        try:
            image = n_utils.find_resource(self._nclient.images, vm_image)
            flavor = n_utils.find_resource(self._nclient.flavors, vm_flavor)
        except (nova_exc.CommandError, Exception) as e:
            LOG.error(_LE("Failure finding needed Nova resource: %s"), e)
            return

        try:
            # Assumption for now is that this does not need to be
            # plugin dependent, only hosting device type dependent.
            files = hosting_device_drv.create_config(context, credentials_info, connectivity_info)
        except IOError:
            return

        try:
            server = self._nclient.servers.create(
                instance_name, image.id, flavor.id, nics=nics, files=files, config_drive=(files != {})
            )
        # There are several individual Nova client exceptions but they have
        # no other common base than Exception, therefore the long list.
        except (
            nova_exc.UnsupportedVersion,
            nova_exc.CommandError,
            nova_exc.AuthorizationFailure,
            nova_exc.NoUniqueMatch,
            nova_exc.AuthSystemNotFound,
            nova_exc.NoTokenLookupException,
            nova_exc.EndpointNotFound,
            nova_exc.AmbiguousEndpoints,
            nova_exc.ConnectionRefused,
            nova_exc.ClientException,
            Exception,
        ) as e:
            LOG.error(_LE("Failed to create service VM instance: %s"), e)
            return
        return {"id": server.id}
Пример #2
0
 def server_get_by_name_or_id(self, context, instance_name_or_id):
     try:
         server = utils.find_resource(
             novaclient(context).servers, instance_name_or_id)
     except nova_exception.CommandError:
         # we did not find the server in the current tenant,
         # and proceed searching in all tenants
         try:
             server = utils.find_resource(
                 novaclient(context).servers, instance_name_or_id,
                 all_tenants=True)
         except nova_exception.CommandError as e:
             msg = _("Failed to get Nova VM. %s") % e
             raise exception.ManilaException(msg)
     return _untranslate_server_summary_view(server)
def do_instance_action_list(cs, args):
    """List actions on a server."""
    server = utils.find_resource(cs.servers, args.server)
    actions = cs.instance_action.list(server)
    utils.print_list(actions,
                     ['Action', 'Request_ID', 'Message', 'Start_Time'],
                     sortby_index=3)
Пример #4
0
def deassociate(cs, vmname):
    """Removes a floating IP address from the specified VM."""
    m = "deassociate"

    # Note changed behavior:  Do nothing. Let OpenStack clean up the Floating IPs.
    sop(m, "Entry/exit. Doing nothing. Returning success.")
    return None

    sop(m, "Entry. vmname=" + vmname)

    server = utils.find_resource(cs.servers, vmname)
    if None == server:
        sop(m, "ERROR: Server not found: " + vmname)
        sys.exit(RC_SERVER_NOT_FOUND)

    floating_ip = getAssociatedFloatingIP(cs, server, 1)
    if None == floating_ip:
        sop(m,
            "ERROR: A floating IP was not associated with server: " + vmname)
        sys.exit(RC_IP_NOT_ASSOCIATED)

    sop(
        m, "Removing floating_ip %s from server %s" %
        (repr(floating_ip.ip), repr(server)))
    server.remove_floating_ip(floating_ip.ip)

    sop(m, "Deallocating all available floating_IPs.")
    deallocateAllAvailableFloatingIPs(cs)

    sop(m, "Exit. Success.")
Пример #5
0
def isactive(cs, vmname):
    """Indicates whether the specified VM is active. Returns rc=0 when active."""
    m = "isactive"
    sop(m, "Entry. vmname=" + vmname)

    try:
        server = utils.find_resource(cs.servers, vmname)
        if None == server:
            sop(
                m, "ERROR: Server not found: " + vmname +
                " Returning RC_SERVER_NOT_FOUND")
            sys.exit(RC_SERVER_NOT_FOUND)
        status = server.status.lower()
        if "error" == status:
            sop(
                m, "Exit. status=" + status + " vmname=" + vmname +
                " Returning RC_SERVER_ERROR")
            sys.exit(RC_SERVER_ERROR)
        if "active" != status:
            sop(
                m, "Exit. status=" + status + " vmname=" + vmname +
                " Returning RC_SERVER_NOT_ACTIVE")
            sys.exit(RC_SERVER_NOT_ACTIVE)
        sop(m,
            "Exit. status=" + status + " vmname=" + vmname + " Returning rc=0")
        sys.exit(0)
    except Exception as e:
        sop(
            m, "ERROR: Caught exception from python-novaclient for server " +
            vmname + ":")
        sop(m, e)
        sop(m, "Returning RC_SERVER_NOT_FOUND")
        sys.exit(RC_SERVER_NOT_FOUND)
Пример #6
0
def do_instance_action_list(cs, args):
    """List actions on a server."""
    server = utils.find_resource(cs.servers, args.server)
    actions = cs.instance_action.list(server)
    utils.print_list(actions,
                     ['Action', 'Request_ID', 'Message', 'Start_Time'],
                     sortby_index=3)
Пример #7
0
 def server_get_by_name_or_id(self, context, instance_name_or_id):
     try:
         server = utils.find_resource(novaclient(context).servers, instance_name_or_id)
     except nova_exception.CommandError as e:
         msg = _("Failed to get Nova VM. %s") % e
         raise exception.ManilaException(msg)
     return _untranslate_server_summary_view(server)
Пример #8
0
    def dispatch_service_vm_real(self,
                                 context,
                                 instance_name,
                                 vm_image,
                                 vm_flavor,
                                 hosting_device_drv,
                                 credentials_info,
                                 connectivity_info,
                                 ports=None):
        mgmt_port = connectivity_info['mgmt_port']
        nics = [{'port-id': mgmt_port['id']}]
        for port in ports or {}:
            nics.append({'port-id': port['id']})

        try:
            image = n_utils.find_resource(self._nclient.images, vm_image)
            flavor = n_utils.find_resource(self._nclient.flavors, vm_flavor)
        except (nova_exc.CommandError, Exception) as e:
            LOG.error(_LE('Failure finding needed Nova resource: %s'), e)
            return

        try:
            # Assumption for now is that this does not need to be
            # plugin dependent, only hosting device type dependent.
            files = hosting_device_drv.create_config(context, credentials_info,
                                                     connectivity_info)
        except IOError:
            return

        try:
            server = self._nclient.servers.create(instance_name,
                                                  image.id,
                                                  flavor.id,
                                                  nics=nics,
                                                  files=files,
                                                  config_drive=(files != {}))
        # There are several individual Nova client exceptions but they have
        # no other common base than Exception, therefore the long list.
        except (nova_exc.UnsupportedVersion, nova_exc.CommandError,
                nova_exc.AuthorizationFailure, nova_exc.NoUniqueMatch,
                nova_exc.AuthSystemNotFound, nova_exc.NoTokenLookupException,
                nova_exc.EndpointNotFound, nova_exc.AmbiguousEndpoints,
                nova_exc.ConnectionRefused, nova_exc.ClientException,
                Exception) as e:
            LOG.error(_LE('Failed to create service VM instance: %s'), e)
            return
        return {'id': server.id}
Пример #9
0
 def server_get_by_name_or_id(self, context, instance_name_or_id):
     try:
         server = utils.find_resource(
             novaclient(context).servers, instance_name_or_id)
     except nova_exception.CommandError as e:
         msg = _("Failed to get Nova VM. %s") % e
         raise exception.ManilaException(msg)
     return _untranslate_server_summary_view(server)
def do_instance_action(cs, args):
    """Show an action."""
    server = utils.find_resource(cs.servers, args.server)
    action_resource = cs.instance_action.get(server, args.request_id)
    action = action_resource._info
    if 'events' in action:
        action['events'] = pprint.pformat(action['events'])
    utils.print_dict(action)
Пример #11
0
def do_instance_action(cs, args):
    """Show an action."""
    server = utils.find_resource(cs.servers, args.server)
    action_resource = cs.instance_action.get(server, args.request_id)
    action = action_resource._info
    if 'events' in action:
        action['events'] = pprint.pformat(action['events'])
    utils.print_dict(action)
def _find_server(cs, args):
    try:
        return utils.find_resource(cs.servers, args.server,
                                   wrap_exception=False)
    except exceptions.NoUniqueMatch as e:
        raise exceptions.CommandError(six.text_type(e))
    except exceptions.NotFound:
        # The server can be deleted
        return args.server
def _find_server(cs, args):
    try:
        return utils.find_resource(cs.servers,
                                   args.server,
                                   wrap_exception=False)
    except exceptions.NoUniqueMatch as e:
        raise exceptions.CommandError(six.text_type(e))
    except exceptions.NotFound:
        # The server can be deleted
        return args.server
Пример #14
0
    def dispatch_service_vm_real(self,
                                 context,
                                 instance_name,
                                 vm_image,
                                 vm_flavor,
                                 hosting_device_drv,
                                 credentials_info,
                                 connectivity_info,
                                 ports=None):
        mgmt_port = connectivity_info['mgmt_port']
        nics = [{'port-id': mgmt_port['id']}]
        for port in ports or {}:
            nics.append({'port-id': port['id']})

        try:
            image = n_utils.find_resource(
                bc.get_novaclient_images(self._nclient), vm_image)
            flavor = n_utils.find_resource(self._nclient.flavors, vm_flavor)
        except (nova_exc.CommandError, Exception) as e:
            LOG.error('Failure finding needed Nova resource: %s', e)
            return

        try:
            # Assumption for now is that this does not need to be
            # plugin dependent, only hosting device type dependent.
            files = hosting_device_drv.create_config(context, credentials_info,
                                                     connectivity_info)
        except IOError:
            return

        try:
            server = self._nclient.servers.create(instance_name,
                                                  image.id,
                                                  flavor.id,
                                                  nics=nics,
                                                  files=files,
                                                  config_drive=(files != {}))
        # There are several individual Nova client exceptions but they have
        # no other common base than Exception, therefore the long list.
        except Exception as e:
            LOG.error('Failed to create service VM instance: %s', e)
            return
        return {'id': server.id}
Пример #15
0
    def unset_extra_specs(self, rsrc, action, action_dict, subcloud_rsrc):
        flavor = novaclient_utils.find_resource(
            self.sc_nova_client.flavors,
            subcloud_rsrc.subcloud_resource_id,
            is_public=None)

        es_metadata = action_dict[action]
        metadata = {}
        # extra_spec keys passed in could be of format "key1"
        # or "key1;key2;key3"
        for metadatum in es_metadata.split(';'):
            if metadatum:
                metadata[metadatum] = None

        try:
            flavor.unset_keys(metadata.keys())
        except novaclient_exceptions.NotFound:
            LOG.info("Extra-spec {} not found {}:{}".format(
                metadata.keys(), rsrc, action_dict),
                     extra=self.log_extra)
Пример #16
0
def displayassociated(cs, vmname):
    """Displays floating IP address associated with specified VM.
       Returns the IP in a string in the form of a json object."""
    m = "displayassociated"
    sop(m, "Entry. vmname=" + vmname)

    server = utils.find_resource(cs.servers, vmname)
    if None == server:
        sop(m, "ERROR: Server not found: " + vmname)
        sys.exit(RC_SERVER_NOT_FOUND)

    floating_ip = getAssociatedFloatingIP(cs, server, 1)
    if None == floating_ip:
        sop(m,
            "ERROR: A floating IP was not associated with server: " + vmname)
        sys.exit(RC_IP_NOT_ASSOCIATED)

    sop(m, "Exit. Success. Returning floating_ip: " + floating_ip.ip)

    print(
        '{ "rc": 0, "ip": "%s", "msg": "OPSTX7832I: Found floating IP %s for VM %s" }'
        % (floating_ip.ip, floating_ip.ip, vmname))
def do_backup_schedule(cs, args):
    """
    Show or edit the backup schedule for a server.

    With no flags, the backup schedule will be shown. If flags are given,
    the backup schedule will be modified accordingly.
    """
    server = utils.find_resource(cs.servers, args.server)
    backup_schedule = cs.rax_backup_schedule_python_novaclient_ext.get(server)
    # If we have some flags, update the backup
    backup = {}
    if args.daily:
        backup['daily'] = args.daily.upper()
    if args.weekly:
        backup['weekly'] = args.weekly.upper()
    if args.enabled is not None:
        backup['enabled'] = args.enabled
    if args.rotation is not None:
        backup['rotation'] = args.rotation
    if backup:
        backup_schedule.update(**backup)
    else:
        utils.print_dict(backup_schedule._info)
Пример #18
0
def waitForServerActive(cs, vmname):
    """Waits until timeout for the specified server to be in 'active' state.
      Returns immediately on status 'active' or 'error'.
      Returns the server object upon exit."""
    m = "waitForServerActive"
    sop(m, "Entry. vmname=" + vmname)
    server = None

    # Try for 100 attempts, 3 seconds each, yields 5 minutes.
    # (Andy witnessed one launch take 4 mins to go from state booting to active.)
    numRetries = 100
    while numRetries > 0:
        numRetries = numRetries - 1
        try:
            # important: get a fresh view of server status on every retry.
            server = utils.find_resource(cs.servers, vmname)
            if None == server:
                sop(m, "ERROR: Server not found: " + vmname)
                sys.exit(RC_SERVER_NOT_FOUND)
            status = server.status.lower()
            if "active" == status or "error" == status:
                sop(m, "Exit. server=" + vmname + " status=" + status)
                return server
        except Exception as e:
            sop(
                m,
                "ERROR: Caught exception from python-novaclient for server=" +
                vmname + ":")
            sop(m, e)
        sop(
            m, "Sleeping briefly. server=" + vmname + " status=" + status +
            " numRetries=%i" % (numRetries))
        time.sleep(3)

    sop(m, "Exit. Timeout expired. server=" + vmname + " status=" + status)
    return server
Пример #19
0
 def test_find_by_str_lower_name_mixed(self):
     output = utils.find_resource(self.manager, 'mixed')
     self.assertEqual(output, self.manager.get('12345678'))
Пример #20
0
def _find_server(cs, server):
    """ Returns a sever by name or ID. """
    return utils.find_resource(cs.gridcentric, server)
Пример #21
0
 def test_find_by_str_upper_name(self):
     output = utils.find_resource(self.manager, 'UPPER')
     self.assertEqual(output, self.manager.get('12345'))
Пример #22
0
def _find_volume(cs, volume):
    """Get a volume by ID."""
    return utils.find_resource(cs.volumes, volume)
Пример #23
0
def _find_volume_snapshot(cs, snapshot):
    """Get a volume snapshot by ID."""
    return utils.find_resource(cs.volume_snapshots, snapshot)
Пример #24
0
def _find_flavor(cs, flavor):
    """Get a flavor by name, ID, or RAM size."""
    try:
        return utils.find_resource(cs.flavors, flavor)
    except exceptions.NotFound:
        return cs.flavors.find(ram=flavor)
Пример #25
0
def _find_image(cs, image):
    """Get an image by name or ID."""
    return utils.find_resource(cs.images, image)
Пример #26
0
def _find_volume_snapshot(cs, snapshot):
    """Get a volume snapshot by ID."""
    return utils.find_resource(cs.volume_snapshots, snapshot)
Пример #27
0
def _find_ipgroup(cs, group):
    """Get an IP group by name or ID."""
    return utils.find_resource(cs.ipgroups, group)
Пример #28
0
def _find_server(cs, server):
    """ Returns a sever by name or ID. """
    return utils.find_resource(cs.gridcentric, server)
def _find_server(cs, args):
    return utils.find_resource(cs.servers, args.server)
Пример #30
0
 def test_find_by_str_upper_name(self):
     output = utils.find_resource(self.manager, 'UPPER')
     self.assertEqual(output, self.manager.get('12345'))
def do_restore(cs, args):
    """Restore a soft-deleted server."""
    utils.find_resource(cs.servers, args.server).restore()
def do_force_delete(cs, args):
    """Force delete a server."""
    utils.find_resource(cs.servers, args.server).force_delete()
Пример #33
0
def do_instance_action_list(cs, args):
    """List actions on a server."""
    server = utils.find_resource(cs.servers, args.server)
    actions = cs.instance_action.list(server)
    utils.print_list(actions, ["Action", "Request_ID", "Message", "Start_Time"], sortby_index=3)
Пример #34
0
 def test_find_by_str_lower_name_mixed(self):
     output = utils.find_resource(self.manager, 'mixed')
     self.assertEqual(output, self.manager.get('12345678'))
Пример #35
0
def _find_baremetal_node(cs, node):
    """Get a node by ID."""
    return utils.find_resource(cs.baremetal, node)
def do_restore(cs, args):
    """Restore a deferred deleted server."""
    server = utils.find_resource(cs.servers, args.server)
    server.restore()
Пример #37
0
def _find_server(cs, server):
    """Get a server by name or ID."""
    return utils.find_resource(cs.servers, server)
Пример #38
0
 def test_find_by_str_name(self):
     output = utils.find_resource(self.manager, "entity_one")
     self.assertEqual(output, self.manager.get("1234"))
Пример #39
0
def _find_image(cs, image):
    """Get an image by name or ID."""
    return utils.find_resource(cs.images, image)
Пример #40
0
 def test_find_by_integer_id(self):
     output = utils.find_resource(self.manager, 1234)
     self.assertEqual(output, self.manager.get('1234'))
Пример #41
0
def _find_server(cs, server):
    """Get a server by name or ID."""
    return utils.find_resource(cs.servers, server)
Пример #42
0
 def test_find_by_str_name(self):
     output = utils.find_resource(self.manager, 'entity_one')
     self.assertEqual(output, self.manager.get('1234'))
Пример #43
0
def _find_flavor(cs, flavor):
    """Get a flavor by name, ID, or RAM size."""
    try:
        return utils.find_resource(cs.flavors, flavor)
    except exceptions.NotFound:
        return cs.flavors.find(ram=flavor)
Пример #44
0
 def test_find_in_alphanum_allowd_manager_by_str_id_(self):
     alphanum_manager = FakeManager(True)
     output = utils.find_resource(alphanum_manager, '01234')
     self.assertEqual(output, alphanum_manager.get('01234'))
Пример #45
0
 def test_find_by_str_displayname(self):
     output = utils.find_resource(self.manager, 'entity_three')
     self.assertEqual(output, self.manager.get('4242'))
Пример #46
0
def _find_volume(cs, volume):
    """Get a volume by ID."""
    return utils.find_resource(cs.volumes, volume)
Пример #47
0
def _find_baremetal_node(cs, node):
    """Get a node by ID."""
    return utils.find_resource(cs.baremetal, node)
Пример #48
0
def _find_server(cs, server):
    """ Returns a sever by name or ID. """
    return utils.find_resource(cs.veta, server)
Пример #49
0
 def test_find_by_uuid(self):
     output = utils.find_resource(self.manager, UUID)
     self.assertEqual(output, self.manager.get(UUID))
Пример #50
0
def do_force_delete(cs, args):
    """Force delete a server."""
    utils.find_resource(cs.servers, args.server).force_delete()
Пример #51
0
 def test_find_by_str_displayname(self):
     display_manager = FakeDisplayManager(None)
     output = utils.find_resource(display_manager, 'entity_three')
     self.assertEqual(output, display_manager.get('4242'))
Пример #52
0
def do_restore(cs, args):
    """Restore a soft-deleted server."""
    utils.find_resource(cs.servers, args.server, deleted=True).restore()
def do_force_delete(cs, args):
    """Force delete a deferred deleted server."""
    server = utils.find_resource(cs.servers, args.server)
    server.force_delete()
Пример #54
0
def _find_pci(cs, info):
    """Get a hypervisor by name or ID."""
    return utils.find_resource(cs.pci, info)