App-FuguVM

 view release on metacpan or  search on metacpan

lib/App/FuguVM/State.pm  view on Meta::CPAN

sub vm_pidfile ($self)
{
	return $self->{vm_pid};
}

# $self->proxy_pidfile:
#	Return the PID file of the proxy child. App::FuguVM::Guest gives it to
#	the proxy supervisor.
sub proxy_pidfile ($self)
{
	return $self->{proxy_pid};
}

# VM PID management. QEMU writes the pid file itself, so the module
# only reads and clears it.
sub get_vm_pid ($self)
{
	return $self->{vm_pid}->read_pid;
}

sub clear_vm_pid ($self)
{
	$self->{vm_pid}->remove;
	return $self;
}

# $self->is_vm_running:
#	Report if the QEMU process is alive. A QEMU that became a
#	zombie is not running: the check reaps it and says so.
sub is_vm_running ($self)
{
	return $self->{vm_pid}->is_running ? 1 : 0;
}

# Disk state
sub disk_path ($self)
{
	return $self->{disk_path};
}

sub disk_exists ($self)
{
	return -f $self->{disk_path};
}

# Installation state
sub is_installed ($self)
{
	return $self->{store}->get('installed') ? 1 : 0;
}

sub mark_installed ($self)
{
	$self->{store}->data->{installed}    = 1;
	$self->{store}->data->{installed_at} = time;
	$self->{store}->save;

	return $self;
}

# Root password management. The state stores the password for the
# initial setup. The store writes at mode 0600.
sub set_root_password ( $self, $password )
{
	$self->{store}->set( root_password => $password );
	return $self;
}

sub get_root_password ($self)
{
	return $self->{store}->get('root_password');
}

# SSH key installation state
# The state tracks which SSH key is installed. Thus the system can
# detect when the configured SSH key changed. Then it automatically
# installs the new key.
sub mark_ssh_key_installed ( $self, $ssh_pubkey = undef )
{
	my $data = $self->{store}->data;
	$data->{ssh_key_installed}    = 1;
	$data->{ssh_key_installed_at} = time;
	$data->{installed_ssh_pubkey} = $ssh_pubkey if defined $ssh_pubkey;
	$self->{store}->save;

	return $self;
}

sub get_installed_ssh_pubkey ($self)
{
	return $self->{store}->get('installed_ssh_pubkey');
}

sub vm_state_dir ($self)
{
	return $self->{vm_state_dir};
}

sub vm_name ($self)
{
	return $self->{vm_name};
}

sub data ($self)
{
	return $self->{store}->data;
}

# Shutdown state tracking
# The state records whether the VM was shut down cleanly. This detects
# the risk of filesystem corruption.

sub mark_clean_shutdown ($self)
{
	my $data = $self->{store}->data;
	$data->{shutdown_clean} = 1;
	$data->{shutdown_at}    = time;
	delete $data->{running};
	$self->{store}->save;

	return $self;
}

sub mark_unclean_shutdown ($self)
{
	my $data = $self->{store}->data;
	$data->{shutdown_clean} = 0;
	$data->{shutdown_at}    = time;
	delete $data->{running};
	$self->{store}->save;



( run in 1.891 second using v1.01-cache-2.11-cpan-4ef0a570458 )