How to use the nova.utils.execute function in nova

To help you get started, we’ve selected a few nova examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / neutron / quantum / plugins / linuxbridge / nova / linux_net_linux_bridge.py View on Github external
try:
                # First, try with 'ip'
                utils.execute('ip', 'tuntap', 'add', dev, 'mode', 'tap',
                          run_as_root=True)
            except exception.ProcessExecutionError:
                # Second option: tunctl
                utils.execute('tunctl', '-b', '-t', dev, run_as_root=True)
            utils.execute('ip', 'link', 'set', dev, "address", mac_address,
                          run_as_root=True)
            utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True)

        if not _device_exists(bridge):
            LOG.debug(_("Starting bridge %s "), bridge)
            utils.execute('brctl', 'addbr', bridge, run_as_root=True)
            utils.execute('brctl', 'setfd', bridge, str(0), run_as_root=True)
            utils.execute('brctl', 'stp', bridge, 'off', run_as_root=True)
            utils.execute('ip', 'link', 'set', bridge, "address", mac_address,
                          run_as_root=True)
            utils.execute('ip', 'link', 'set', bridge, 'up', run_as_root=True)
            LOG.debug(_("Done starting bridge %s"), bridge)

        full_ip = '%s/%s' % (network['dhcp_server'],
                             network['cidr'].rpartition('/')[2])
        utils.execute('ip', 'address', 'add', full_ip, 'dev', bridge,
                run_as_root=True)

        return dev
github openstack / nova / nova / volume / encryptors / luks.py View on Github external
def _open_volume(self, passphrase, **kwargs):
        """Opens the LUKS partition on the volume using the specified
        passphrase.

        :param passphrase: the passphrase used to access the volume
        """
        LOG.debug("opening encrypted volume %s", self.dev_path)
        utils.execute('cryptsetup', 'luksOpen', '--key-file=-',
                      self.dev_path, self.dev_name, process_input=passphrase,
                      run_as_root=True, check_exit_code=True)
github openstack / nova / nova / volume / encryptors / luks.py View on Github external
"""
        mangled_passphrase = self._get_mangled_passphrase(key)
        self._open_volume(mangled_passphrase, **kwargs)
        self._close_volume(**kwargs)
        LOG.debug("%s correctly opened with a mangled passphrase, replacing"
                  "this with the original passphrase", self.dev_path)

        # NOTE(lyarwood): Now that we are sure that the mangled passphrase is
        # used attempt to add the correct passphrase before removing the
        # mangled version from the volume.

        # luksAddKey currently prompts for the following input :
        # Enter any existing passphrase:
        # Enter new passphrase for key slot:
        # Verify passphrase:
        utils.execute('cryptsetup', 'luksAddKey', self.dev_path,
                      process_input=''.join([mangled_passphrase, '\n',
                                             passphrase, '\n', passphrase]),
                      run_as_root=True, check_exit_code=True)

        # Verify that we can open the volume with the current passphrase
        # before removing the mangled passphrase.
        self._open_volume(passphrase, **kwargs)
        self._close_volume(**kwargs)

        # luksRemoveKey only prompts for the key to remove.
        utils.execute('cryptsetup', 'luksRemoveKey', self.dev_path,
                      process_input=mangled_passphrase,
                      run_as_root=True, check_exit_code=True)
        LOG.debug("%s mangled passphrase successfully replaced", self.dev_path)
github nii-cloud / dodai-compute / nova / virt / dodai / connection.py View on Github external
image_type = "server"
        image_name = image_meta["name"] or image_meta["properties"]["image_location"]
        if image_name.find("dodai-deploy") == -1:
            image_type = "node"

        # begin to install os
        pxe_ip = bmm["pxe_ip"] or "None"
        pxe_mac = bmm["pxe_mac"] or "None"
        storage_ip = bmm["storage_ip"] or "None"
        storage_mac = bmm["storage_mac"] or "None"
        service_mac1 = bmm["service_mac1"] or "None"
        service_mac2 = bmm["service_mac2"] or "None"

        instance_path = self._get_cobbler_instance_path(instance) 
        if not os.path.exists(instance_path):
            utils.execute('mkdir', '-p', instance_path)

        self._cp_template("create.sh", 
                          self._get_cobbler_instance_path(instance, "create.sh"),
                          {"INSTANCE_ID": instance["id"], 
                           "IMAGE_ID": instance["image_ref"], 
                           "COBBLER": FLAGS.cobbler, 
                           "HOST_NAME": bmm["name"], 
                           "STORAGE_IP": storage_ip,
                           "STORAGE_MAC": storage_mac,
                           "PXE_IP": pxe_ip, 
                           "PXE_MAC": pxe_mac,
                           "SERVICE_MAC1": bmm["service_mac1"],
                           "SERVICE_MAC2": bmm["service_mac2"],
                           "IMAGE_TYPE": image_type,
                           "MONITOR_PORT": FLAGS.dodai_monitor_port,
                           "ROOT_SIZE": FLAGS.dodai_partition_root_gb,
github openstack / nova / nova / objectstore / image.py View on Github external
key, err = utils.execute(
                'openssl rsautl -decrypt -inkey %s' % cloud_private_key,
                process_input=encrypted_key,
                check_exit_code=False)
        if err:
            raise exception.Error(_("Failed to decrypt private key: %s")
                                  % err)
        iv, err = utils.execute(
                'openssl rsautl -decrypt -inkey %s' % cloud_private_key,
                process_input=encrypted_iv,
                check_exit_code=False)
        if err:
            raise exception.Error(_("Failed to decrypt initialization "
                                    "vector: %s") % err)

        _out, err = utils.execute(
                'openssl enc -d -aes-128-cbc -in %s -K %s -iv %s -out %s'
                 % (encrypted_filename, key, iv, decrypted_filename),
                 check_exit_code=False)
        if err:
            raise exception.Error(_("Failed to decrypt image file "
                                    "%(image_file)s: %(err)s") %
                                    {'image_file': encrypted_filename,
                                     'err': err})
github openstack / nova / nova / virt / libvirt / volume / scality.py View on Github external
def _mount_sofs(self):
        config = CONF.libvirt.scality_sofs_config
        mount_path = CONF.libvirt.scality_sofs_mount_point

        if not os.path.isdir(mount_path):
            utils.execute('mkdir', '-p', mount_path)
        if not self._sofs_is_mounted():
            utils.execute('mount', '-t', 'sofs', config, mount_path,
                          run_as_root=True)
            if not self._sofs_is_mounted():
                msg = _("Cannot mount Scality SOFS, check syslog for errors")
                LOG.warning(msg)
                raise exception.InternalError(msg)
github openstack / nova / nova / cmd / baremetal_deploy_helper.py View on Github external
def discovery(portal_address, portal_port):
    """Do iSCSI discovery on portal."""
    utils.execute('iscsiadm',
                  '-m', 'discovery',
                  '-t', 'st',
                  '-p', '%s:%s' % (portal_address, portal_port),
                  run_as_root=True,
                  check_exit_code=[0])
github openstack / nova / nova / virt / docker / driver.py View on Github external
if_remote_name = 'pvnetr{0}'.format(rand)
        bridge = network_info['bridge']
        ip = self._find_fixed_ip(network_info['subnets'])
        if not ip:
            raise RuntimeError(_('Cannot set fixed ip'))
        undo_mgr = utils.UndoManager()
        try:
            utils.execute(
                'ip', 'link', 'add', 'name', if_local_name, 'type',
                'veth', 'peer', 'name', if_remote_name,
                run_as_root=True)
            undo_mgr.undo_with(lambda: utils.execute(
                'ip', 'link', 'delete', if_local_name, run_as_root=True))
            # NOTE(samalba): Deleting the interface will delete all associated
            # resources (remove from the bridge, its pair, etc...)
            utils.execute(
                'brctl', 'addif', bridge, if_local_name,
                run_as_root=True)
            utils.execute(
                'ip', 'link', 'set', if_local_name, 'up',
                run_as_root=True)
            utils.execute(
                'ip', 'link', 'set', if_remote_name, 'netns', nspid,
                run_as_root=True)
            utils.execute(
                'ip', 'netns', 'exec', container_id, 'ifconfig',
                if_remote_name, ip,
                run_as_root=True)
        except Exception:
            msg = _('Failed to setup the network, rolling back')
            undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
github docker / openstack-docker / nova-driver / driver.py View on Github external
'veth', 'peer', 'name', if_remote_name,
                run_as_root=True)
            undo_mgr.undo_with(lambda: utils.execute(
                'ip', 'link', 'delete', if_local_name, run_as_root=True))
            # NOTE(samalba): Deleting the interface will delete all associated
            # resources (remove from the bridge, its pair, etc...)
            utils.execute(
                'brctl', 'addif', bridge, if_local_name,
                run_as_root=True)
            utils.execute(
                'ip', 'link', 'set', if_local_name, 'up',
                run_as_root=True)
            utils.execute(
                'ip', 'link', 'set', if_remote_name, 'netns', nspid,
                run_as_root=True)
            utils.execute(
                'ip', 'netns', 'exec', container_id, 'ifconfig',
                if_remote_name, ip,
                run_as_root=True)
        except Exception:
            msg = _('Failed to setup the network, rolling back')
            undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
github oracle / solaris-userland / components / openstack / nova / files / solariszones / driver.py View on Github external
def _has_vnc_console_service(self, instance):
        """Returns True if the instance has a zone VNC console SMF service"""
        name = instance['name']
        console_fmri = VNC_CONSOLE_BASE_FMRI + ':' + name
        # TODO(npower): investigate using RAD instead of CLI invocation
        try:
            utils.execute('/usr/bin/svcs', '-H', '-o', 'state',
                          console_fmri)
            return True
        except processutils.ProcessExecutionError as err:
            return False