App-FuguVM

 view release on metacpan or  search on metacpan

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


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

# $self->mark_installed($arch):
#	Record the install mark and the architecture of the installed
#	disk. The argument is required, so no path can forget it.
sub mark_installed ( $self, $arch )
{
	my $data = $self->{store}->data;
	$data->{installed}      = 1;
	$data->{installed_at}   = time;
	$data->{installed_arch} = $arch;
	$self->{store}->save;

	return $self;
}

# $self->get_installed_arch:
#	Return the recorded architecture of the installed disk, or
#	undef.
sub get_installed_arch ($self)
{
	return $self->{store}->get('installed_arch');
}

# The runtime record: the facts of one run of one guest. The record
# holds the selected accelerator and the two resolved host ports.
# App::FuguVM::Guest writes it before it spawns QEMU, and the stop
# verbs clear it beside clear_vm_pid.

# $self->set_runtime(%facts):
#	Record accel, ssh_port and console_port, and save the store.
sub set_runtime ( $self, %facts )
{
	$self->{store}->set( runtime => \%facts );

	return $self;
}

# $self->get_runtime:
#	Return the recorded facts as a hash reference. Return an empty
#	hash reference when the guest never ran.
sub get_runtime ($self)
{
	return $self->{store}->get('runtime') // {};
}

# $self->clear_runtime:
#	Delete the record, and save the store.
sub clear_runtime ($self)
{
	$self->{store}->delete('runtime');

	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 0.862 second using v1.01-cache-2.11-cpan-f5f21f1076c )