<commit_before>import { VmActions } from '../vm-actions/vm-action';
import {
  VirtualMachine,
  VmState
} from './vm.model';

const isIpAvailable = (vm) => {
  return vm.nic.length && !!vm.nic[0].ipAddress;
};

const VmStartAction = {
  name: 'VM_PAGE.COMMANDS.START',
  command: VmActions.START,
  icon: 'play_arrow',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_START',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Stopped
};

const VmStopAction = {
  name: 'VM_PAGE.COMMANDS.STOP',
  command: VmActions.STOP,
  icon: 'stop',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_STOP',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Running
};

const VmRebootAction = {
  name: 'VM_PAGE.COMMANDS.REBOOT',
  command: VmActions.REBOOT,
  icon: 'replay',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_REBOOT',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Running
};

const VmRestoreAction = {
  name: 'VM_PAGE.COMMANDS.RESTORE',
  command: VmActions.RESTORE,
  icon: 'settings_backup_restore',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_RESTORE',
  canActivate: (vm: VirtualMachine) => !!vm && [
    VmState.Running,
    VmState.Stopped
  ].includes(vm.state)
};

const VmDestroyAction = {
  name: 'VM_PAGE.COMMANDS.DESTROY',
  command: VmActions.DESTROY,
  icon: 'delete',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_DESTROY',
  canActivate: (vm: VirtualMachine) => !!vm && [
    VmState.Running, VmState.Stopped,
    VmState.Error
  ].includes(vm.state)
};

const VmResetPasswordAction = {
  name: 'VM_PAGE.COMMANDS.RESET_PASSWORD',
  command: VmActions.RESET_PASSWORD,
  icon: 'vpn_key',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_RESET_PASSWORD',
  canActivate: (vm: VirtualMachine) => !!vm
    && [VmState.Running, VmState.Stopped].includes(vm.state)
    && vm.passwordEnabled
    && isIpAvailable(vm)
};

const VmExpungeAction = {
  name: 'VM_PAGE.COMMANDS.EXPUNGE',
  command: VmActions.EXPUNGE,
  icon: 'delete_forever',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_EXPUNGE',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Destroyed
};

const VmRecoverAction = {
  name: 'VM_PAGE.COMMANDS.RECOVER',
  command: VmActions.RECOVER,
  icon: 'restore',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_RECOVER',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Destroyed
};

export const VmAccessAction = {
  name: 'VM_PAGE.COMMANDS.VM_ACCESS',
  command: VmActions.ACCESS,
  icon: 'computer',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Running
};

export const VmPulseAction = {

  name: 'PULSE.PULSE',
  command: VmActions.PULSE,
  icon: 'timeline',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Running
};

export class VmActionsService {
  public actions = [
    VmStartAction,
    VmStopAction,
    VmRebootAction,
    VmRestoreAction,
    VmDestroyAction,
    VmResetPasswordAction,
    VmAccessAction,
    VmPulseAction
  ];
  public destroyedActions = [
    VmExpungeAction,
    VmRecoverAction
  ];
}
<commit_msg>fix(access-vm): fix IP value (closes #851) (#855)<commit_after>import { VmActions } from '../vm-actions/vm-action';
import {
  VirtualMachine,
  VmState
} from './vm.model';

const isIpAvailable = (vm) => {
  return vm.nic.length && !!vm.nic[0].ipaddress;
};

const VmStartAction = {
  name: 'VM_PAGE.COMMANDS.START',
  command: VmActions.START,
  icon: 'play_arrow',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_START',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Stopped
};

const VmStopAction = {
  name: 'VM_PAGE.COMMANDS.STOP',
  command: VmActions.STOP,
  icon: 'stop',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_STOP',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Running
};

const VmRebootAction = {
  name: 'VM_PAGE.COMMANDS.REBOOT',
  command: VmActions.REBOOT,
  icon: 'replay',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_REBOOT',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Running
};

const VmRestoreAction = {
  name: 'VM_PAGE.COMMANDS.RESTORE',
  command: VmActions.RESTORE,
  icon: 'settings_backup_restore',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_RESTORE',
  canActivate: (vm: VirtualMachine) => !!vm && [
    VmState.Running,
    VmState.Stopped
  ].includes(vm.state)
};

const VmDestroyAction = {
  name: 'VM_PAGE.COMMANDS.DESTROY',
  command: VmActions.DESTROY,
  icon: 'delete',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_DESTROY',
  canActivate: (vm: VirtualMachine) => !!vm && [
    VmState.Running, VmState.Stopped,
    VmState.Error
  ].includes(vm.state)
};

const VmResetPasswordAction = {
  name: 'VM_PAGE.COMMANDS.RESET_PASSWORD',
  command: VmActions.RESET_PASSWORD,
  icon: 'vpn_key',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_RESET_PASSWORD',
  canActivate: (vm: VirtualMachine) => !!vm
    && [VmState.Running, VmState.Stopped].includes(vm.state)
    && vm.passwordEnabled
    && isIpAvailable(vm)
};

const VmExpungeAction = {
  name: 'VM_PAGE.COMMANDS.EXPUNGE',
  command: VmActions.EXPUNGE,
  icon: 'delete_forever',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_EXPUNGE',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Destroyed
};

const VmRecoverAction = {
  name: 'VM_PAGE.COMMANDS.RECOVER',
  command: VmActions.RECOVER,
  icon: 'restore',
  confirmMessage: 'DIALOG_MESSAGES.VM.CONFIRM_RECOVER',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Destroyed
};

export const VmAccessAction = {
  name: 'VM_PAGE.COMMANDS.VM_ACCESS',
  command: VmActions.ACCESS,
  icon: 'computer',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Running
};

export const VmPulseAction = {

  name: 'PULSE.PULSE',
  command: VmActions.PULSE,
  icon: 'timeline',
  canActivate: (vm: VirtualMachine) => !!vm && vm.state === VmState.Running
};

export class VmActionsService {
  public actions = [
    VmStartAction,
    VmStopAction,
    VmRebootAction,
    VmRestoreAction,
    VmDestroyAction,
    VmResetPasswordAction,
    VmAccessAction,
    VmPulseAction
  ];
  public destroyedActions = [
    VmExpungeAction,
    VmRecoverAction
  ];
}

{'fraction_non_alphanumeric': 0.1462705844365515, 'fraction_numerical': 0.0012915724895059735, 'mean_word_length': 4.551075268817204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5311278', 'n_tokens_mistral': 2363, 'n_tokens_neox': 2336, 'n_words': 396}