App-FuguVM

 view release on metacpan or  search on metacpan

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

}

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

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

# $self->store:
#	Return the state store. App::FuguVM::Guest gives it to the proxy, which
#	keeps its port there.
sub store ($self)
{
	return $self->{store};
}

# $self->state_dir:
#	Return the directory that holds every VM's state, not this
#	VM's own. App::FuguVM::Disk keys its paths by VM name under it.
sub state_dir ($self)
{
	return $self->{state_dir};
}

# $self->vm_pidfile:
#	Return the PID file of the QEMU process. QEMU writes it itself,
#	through its -pidfile option.
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;
}



( run in 0.910 second using v1.01-cache-2.11-cpan-14f38c9f855 )