Example #1
0
    def _execute(self):
        self.source_remote_executor = RemoteHostExecutor(self._source.remote_host)
        self._execute_on_every_device(self._sync_disk, self._sync_partition)
        self.source_remote_executor.close()
        self.source_remote_executor = None

        return Commander.Signal.SLEEP
Example #2
0
 def __init__(self, remote_host):
     """
     
     :param remote_host: the remote host to execute on
     :type remote_host: remote_host.public.RemoteHost
     """
     self.remote_executor = RemoteHostExecutor(remote_host)
Example #3
0
 def _execute(self):
     self.source_remote_executor = RemoteHostExecutor(
         self._source.remote_host)
     self._execute_on_every_device(self._replicate_partition_table,
                                   None,
                                   include_swap=True)
     self.source_remote_executor.close()
     self.source_remote_executor = None
Example #4
0
 def _execute(self):
     root_source_mountpoint = self._find_root_source_mountpoint()
     remote_executor = RemoteHostExecutor(self._target.remote_host)
     self._create_source_environment_mountpoints(remote_executor,
                                                 root_source_mountpoint)
     self._mount_source_environment(remote_executor, root_source_mountpoint)
     self._mount_source_mountpoints(remote_executor, root_source_mountpoint)
     self._reinstall_bootloader(remote_executor, root_source_mountpoint)
Example #5
0
 def _comment_out_listen_address(self):
     """
     comments out the ListenAddress line in the sshd_config file
     """
     RemoteFileEditor(RemoteHostExecutor(self._target.remote_host)).edit(
         SourceFileLocationResolver(self._source).resolve_path(self.SSHD_CONFIG_LOCATION),
         'ListenAddress',
         '# ListenAddress'
     )
Example #6
0
 def _write_network_config(self, network_config):
     """
     wirtes a given network config to the network config file
     
     :param network_config: the network config to persist
     :type network_config: str
     """
     RemoteFileEditor(RemoteHostExecutor(self._target.remote_host)).write(
         SourceFileLocationResolver(self._source).resolve_path(self.NETWORK_CONFIG_FILE_LOCATION),
         network_config
     )
Example #7
0
    def _execute_on_every_device(self,
                                 executable_for_disks,
                                 executable_for_partitions=None,
                                 include_swap=False):
        """
        execute the given executable with all devices.
        
        :param executable_for_disks: a function which takes the parameters: remote_executor, source_device, 
        target_device
        :type executable_for_disks: (self: Any, RemoteExecutor, (str, dict), (str, dict)) -> None
        :param executable: a function which takes the parameters: remote_executor, source_device, 
        target_device, source_partition_device, target_partition_device
        :type executable_for_partitions: (self: Any, RemoteExecutor, (str, dict), (str, dict), (str, dict), (str, dict)
        ) -> None
        :param include_swap: should a swap device also be iterated over
        :type include_swap: bool
        :return: the used remote_executor, for extended use
        :rtype: RemoteHostExecutor
        """
        remote_executor = RemoteHostExecutor(self._target.remote_host)

        for source_device_id, target_device in self._target.device_mapping.items(
        ):
            source_device = self._source.remote_host.system_info[
                'block_devices'][source_device_id]

            if executable_for_disks and (include_swap or not include_swap
                                         and source_device['fs'] != 'swap'):
                executable_for_disks(
                    remote_executor,
                    (source_device_id, source_device),
                    (target_device['id'], target_device),
                )

            if executable_for_partitions:
                for source_partition_id, target_partition in target_device[
                        'children'].items():
                    source_partition = source_device['children'][
                        source_partition_id]
                    if (include_swap or not include_swap
                            and source_partition['fs'] != 'swap'):
                        executable_for_partitions(
                            remote_executor,
                            (source_device_id, source_device),
                            (target_device['id'], target_device),
                            (source_partition_id, source_partition),
                            (target_partition['id'], target_partition),
                        )

        return remote_executor
 def _init_test_data(self, **kwargs):
     self.remote_executor = RemoteHostExecutor(
         RemoteHost.objects.create(address='ubuntu16'))
     TestAsset.REMOTE_HOST_MOCKS['ubuntu16'].add_command(
         'sudo cat /etc/testfile.txt', self.TEST_FILE_CONTENT)
 def _init_operator_class(self, operator_class):
     return operator_class(RemoteHostExecutor(self.remote_host))
Example #10
0
 def _execute(self):
     RemoteHostExecutor(self._target.remote_host).execute(
         'sudo shutdown -P now &', block_for_response=False)
     self._cloud_manager.stop_target(
         self._target.remote_host.cloud_metadata['id'])