1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 2001 by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 package com.sun.dhcpmgr.cli.pntadm; 27 28 import com.sun.dhcpmgr.data.DhcpClientRecord; 29 import com.sun.dhcpmgr.data.Network; 30 import com.sun.dhcpmgr.bridge.BridgeException; 31 import com.sun.dhcpmgr.bridge.NoEntryException; 32 33 import java.lang.IllegalArgumentException; 34 35 /** 36 * The main class for the "delete client" functionality of pntadm. 37 */ 38 public class DeleteClientEntry extends PntAdmFunction { 39 40 /** 41 * The valid options associated with deleting a client entry. 42 */ 43 static final int supportedOptions[] = { 44 PntAdm.RESOURCE, 45 PntAdm.RESOURCE_CONFIG, 46 PntAdm.PATH 47 }; 48 49 /** 50 * The client entry to delete. 51 */ 52 String clientIP; 53 54 /** 55 * Constructs a DeleteClientEntry object for the client, clientIP. 56 * @param clientIP the client name or IP address. 57 */ 58 public DeleteClientEntry(String clientIP) { 59 60 this.clientIP = clientIP; 61 validOptions = supportedOptions; 62 63 } // constructor 64 65 /** 66 * Returns the option flag for this function. 67 * @returns the option flag for this function. 68 */ 69 public int getFunctionFlag() { 70 return (PntAdm.DELETE_CLIENT_ENTRY); 71 } 72 73 /** 74 * Executes the "delete client" functionality. 75 * @return PntAdm.SUCCESS, PntAdm.ENOENT, PntAdm.WARNING, or 76 * PntAdm.CRITICAL 77 */ 78 public int execute() 79 throws IllegalArgumentException { 80 81 int returnCode = PntAdm.SUCCESS; 82 83 // Build up a DhcpClientRecord from the user specified options. 84 // 85 try { 86 DhcpClientRecord dhcpClientRecord = new DhcpClientRecord(clientIP); 87 88 // Create a Network object. 89 // 90 Network network = getNetMgr().getNetwork(networkName); 91 if (networkName == null) { 92 printErrMessage(getString("network_name_error")); 93 return (PntAdm.WARNING); 94 } 95 96 // Delete the client and remove host from the hosts table 97 // if requested. 98 // 99 getNetMgr().deleteClient(dhcpClientRecord, network.toString(), 100 getDhcpDatastore()); 101 102 } catch (NoEntryException e) { 103 printErrMessage(getMessage(e)); 104 returnCode = PntAdm.ENOENT; 105 } catch (Throwable e) { 106 printErrMessage(getMessage(e)); 107 returnCode = PntAdm.WARNING; 108 } 109 110 return (returnCode); 111 112 } // execute 113 114 } // DeleteClientEntry