Exemplo n.º 1
0
    def tearDown(self):
        try:
            vb_stop_vm(BOOTABLE_BASE_BOX_NAME)
        except Exception:
            pass

        if vb_machine_exists(INSTANCE_NAME):
            try:
                vb_stop_vm(INSTANCE_NAME)
                vb_destroy_machine(INSTANCE_NAME)
            except Exception as e:
                log.warning("Possibly dirty state after exception", exc_info=True)
Exemplo n.º 2
0
    def tearDown(self):
        try:
            vb_stop_vm(BOOTABLE_BASE_BOX_NAME)
        except Exception:
            pass

        if vb_machine_exists(INSTANCE_NAME):
            try:
                vb_stop_vm(INSTANCE_NAME)
                vb_destroy_machine(INSTANCE_NAME)
            except Exception as e:
                log.warning("Possibly dirty state after exception", exc_info=True)
def stop(name, call=None):
    """
    Stop a running machine.
    @param name: Machine to stop
    @type name: str
    @param call: Must be "action"
    @type call: str
    """
    if call != 'action':
        raise SaltCloudSystemExit(
            'The instance action must be called with -a or --action.')

    log.info("Stopping machine: %s", name)
    vb_stop_vm(name)
Exemplo n.º 4
0
    def test_start_stop(self):
        for i in range(2):
            machine = vb_start_vm(BOOTABLE_BASE_BOX_NAME, 20000)
            self.assertEqual(machine_get_machinestate_str(machine), "Running")

            machine = vb_stop_vm(BOOTABLE_BASE_BOX_NAME)
            self.assertEqual(machine_get_machinestate_str(machine), "PoweredOff")
Exemplo n.º 5
0
    def test_start_stop(self):
        for i in range(2):
            machine = vb_start_vm(BOOTABLE_BASE_BOX_NAME, 20000)
            self.assertEqual(machine_get_machinestate_str(machine), "Running")

            machine = vb_stop_vm(BOOTABLE_BASE_BOX_NAME)
            self.assertEqual(machine_get_machinestate_str(machine), "PoweredOff")
Exemplo n.º 6
0
def stop(name, call=None):
    """
    Stop a running machine.
    @param name: Machine to stop
    @type name: str
    @param call: Must be "action"
    @type call: str
    """
    if call != "action":
        raise SaltCloudSystemExit(
            "The instance action must be called with -a or --action.")

    log.info("Stopping machine: %s", name)
    vb_stop_vm(name)
    machine = vb_get_machine(name)
    del machine["name"]
    return treat_machine_dict(machine)
Exemplo n.º 7
0
def stop(name, call=None):
    """
    Stop a running machine.
    @param name: Machine to stop
    @type name: str
    @param call: Must be "action"
    @type call: str
    """
    if call != 'action':
        raise SaltCloudSystemExit(
            'The instance action must be called with -a or --action.'
        )

    log.info("Stopping machine: %s", name)
    vb_stop_vm(name)
    machine = vb_get_machine(name)
    del machine["name"]
    return treat_machine_dict(machine)
Exemplo n.º 8
0
def destroy(name, call=None):
    """
    This function irreversibly destroys a virtual machine on the cloud provider.
    Before doing so, it should fire an event on the Salt event bus.
    The tag for this event is `salt/cloud/<vm name>/destroying`.
    Once the virtual machine has been destroyed, another event is fired.
    The tag for that event is `salt/cloud/<vm name>/destroyed`.
    Dependencies:
        list_nodes
    @param name:
    @type name: str
    @param call:
    @type call:
    @return: True if all went well, otherwise an error message
    @rtype: bool|str
    """
    log.info("Attempting to delete instance %s", name)

    vb_stop_vm(name)
    vb_destroy_vm(name)
def create(vm_info):
    """
    Creates a virtual machine from the given VM information.
    This is what is used to request a virtual machine to be created by the
    cloud provider, wait for it to become available,
    and then (optionally) log in and install Salt on it.

    Fires:
        "starting create" : This event is tagged salt/cloud/<vm name>/creating.
        The payload contains the names of the VM, profile and provider.

    @param vm_info
            {
                name: <str>
                profile: <dict>
                driver: <provider>:<profile>
                clonefrom: <vm_name>
            }
    @type vm_info dict
    @return dict of resulting vm. !!!Passwords can and should be included!!!
    """

    try:
        # Check for required profile parameters before sending any API calls.
        if vm_info['profile'] and config.is_profile_configured(
                __opts__, __active_provider_name__ or 'virtualbox',
                vm_info['profile']) is False:
            return False
    except AttributeError:
        pass

    vm_name = vm_info["name"]
    deploy = config.get_cloud_config_value('deploy',
                                           vm_info,
                                           __opts__,
                                           search_global=False,
                                           default=True)
    wait_for_ip_timeout = config.get_cloud_config_value('wait_for_ip_timeout',
                                                        vm_info,
                                                        __opts__,
                                                        default=60)
    boot_timeout = config.get_cloud_config_value('boot_timeout',
                                                 vm_info,
                                                 __opts__,
                                                 default=60 * 1000)
    power = config.get_cloud_config_value('power_on',
                                          vm_info,
                                          __opts__,
                                          default=False)
    key_filename = config.get_cloud_config_value('private_key',
                                                 vm_info,
                                                 __opts__,
                                                 search_global=False,
                                                 default=None)

    log.debug("Going to fire event: starting create")

    # to create the virtual machine.
    request_kwargs = {
        'name': vm_info['name'],
        'clone_from': vm_info['clonefrom']
    }
    vb_stop_vm(vm_info['clonefrom'])
    vb_clone_vm(vm_info['name'], vm_info['clonefrom'])

    # Booting and deploying if needed
    if power:
        vb_start_vm(vm_info['name'])
        ip = wait_for(vb_get_vm_address,
                      timeout=60,
                      step=1,
                      default=[],
                      func_kwargs={'name': vm_info['name']})

        log.info("[ {0} ] IPv4 is: {1}".format(vm_info['name'], ip))
        # ssh or smb using ip and install salt only if deploy is True
        if deploy:
            vm_info['ssh_host'] = ip
            ret = __utils__['cloud.bootstrap'](vm_info, __opts__)

    return ret
Exemplo n.º 10
0
    Start a machine.
    @param name: Machine to start
    @type name: str
    @param call: Must be "action"
    @type call: str
    """
    if call != 'action':
        raise SaltCloudSystemExit(
            'The instance action must be called with -a or --action.')

    log.info("Starting machine: %s", name)
    vb_start_vm(name)


def stop(name, call=None):
    """
    Stop a running machine.
    @param name: Machine to stop
    @type name: str
    @param call: Must be "action"
    @type call: str
    """
    if call != 'action':
        raise SaltCloudSystemExit(
            'The instance action must be called with -a or --action.')

    log.info("Stopping machine: %s", name)


vb_stop_vm(name)