mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
remove zfs related staff, which is not used
This commit is contained in:
parent
f62d9ae9c9
commit
4d053964b6
@ -1,224 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.agent.resource.storage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.resource.DiskPreparer;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.Volume.VolumeType;
|
||||
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
public class IscsiMountPreparer implements DiskPreparer {
|
||||
private static final Logger s_logger = Logger.getLogger(IscsiMountPreparer.class);
|
||||
|
||||
private String _name;
|
||||
|
||||
private String _mountvmPath;
|
||||
private String _mountRootdiskPath;
|
||||
private String _mountDatadiskPath;
|
||||
protected String _mountParent;
|
||||
protected int _mountTimeout;
|
||||
|
||||
@Override
|
||||
public String mount(String vmName, VolumeVO vol, BootloaderType type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unmount(String path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static VolumeVO findVolume(final List<VolumeVO> volumes, final Volume.VolumeType vType) {
|
||||
if (volumes == null) return null;
|
||||
|
||||
for (final VolumeVO v: volumes) {
|
||||
if (v.getVolumeType() == vType)
|
||||
return v;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static List<VolumeVO> findVolumes(final List<VolumeVO> volumes, final Volume.VolumeType vType) {
|
||||
if (volumes == null) return null;
|
||||
final List<VolumeVO> result = new ArrayList<VolumeVO>();
|
||||
for (final VolumeVO v: volumes) {
|
||||
if (v.getVolumeType() == vType)
|
||||
result.add(v);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected static VolumeVO findVolume(final List<VolumeVO> volumes, final Volume.VolumeType vType, final String storageHost) {
|
||||
if (volumes == null) return null;
|
||||
for (final VolumeVO v: volumes) {
|
||||
if ((v.getVolumeType() == vType) && (v.getHostIp().equalsIgnoreCase(storageHost)))
|
||||
return v;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static boolean mirroredVolumes(final List<VolumeVO> vols, final Volume.VolumeType vType) {
|
||||
final List<VolumeVO> volumes = findVolumes(vols, vType);
|
||||
return volumes.size() > 1;
|
||||
}
|
||||
|
||||
public synchronized String mountImage(final String host, final String dest, final String vmName, final List<VolumeVO> volumes, final BootloaderType bootloader) {
|
||||
final Script command = new Script(_mountvmPath, _mountTimeout, s_logger);
|
||||
command.add("-h", host);
|
||||
command.add("-l", dest);
|
||||
command.add("-n", vmName);
|
||||
command.add("-b", bootloader.toString());
|
||||
|
||||
command.add("-t");
|
||||
|
||||
|
||||
final VolumeVO root = findVolume(volumes, Volume.VolumeType.ROOT);
|
||||
if (root == null) {
|
||||
return null;
|
||||
}
|
||||
command.add(root.getIscsiName());
|
||||
command.add("-r", root.getFolder());
|
||||
|
||||
final VolumeVO swap = findVolume(volumes, Volume.VolumeType.SWAP);
|
||||
if (swap !=null && swap.getIscsiName() != null) {
|
||||
command.add("-w", swap.getIscsiName());
|
||||
}
|
||||
|
||||
final VolumeVO datadsk = findVolume(volumes, Volume.VolumeType.DATADISK);
|
||||
if (datadsk !=null && datadsk.getIscsiName() != null) {
|
||||
command.add("-1", datadsk.getIscsiName());
|
||||
}
|
||||
|
||||
return command.execute();
|
||||
}
|
||||
|
||||
public synchronized String mountImage(final String storageHosts[], final String dest, final String vmName, final List<VolumeVO> volumes, final boolean mirroredVols, final BootloaderType booter) {
|
||||
if (!mirroredVols) {
|
||||
return mountImage(storageHosts[0], dest, vmName, volumes, booter);
|
||||
} else {
|
||||
return mountMirroredImage(storageHosts, dest, vmName, volumes, booter);
|
||||
}
|
||||
}
|
||||
|
||||
protected String mountMirroredImage(final String hosts[], final String dest, final String vmName, final List<VolumeVO> volumes, final BootloaderType booter) {
|
||||
final List<VolumeVO> rootDisks = findVolumes(volumes, VolumeType.ROOT);
|
||||
final String storIp0 = hosts[0];
|
||||
final String storIp1 = hosts[1];
|
||||
//mountrootdisk.sh -m -h $STORAGE0 -t $iqn0 -l $src -n $vmname -r $dest -M -H $STORAGE1 -T $iqn1
|
||||
final Script command = new Script(_mountRootdiskPath, _mountTimeout, s_logger);
|
||||
command.add("-m");
|
||||
command.add("-M");
|
||||
command.add("-h", storIp0);
|
||||
command.add("-H", storIp1);
|
||||
command.add("-l", dest);
|
||||
command.add("-r", rootDisks.get(0).getFolder());
|
||||
command.add("-n", vmName);
|
||||
command.add("-t", rootDisks.get(0).getIscsiName());
|
||||
command.add("-T", rootDisks.get(1).getIscsiName());
|
||||
command.add("-b", booter.toString());
|
||||
|
||||
final List<VolumeVO> swapDisks = findVolumes(volumes, VolumeType.SWAP);
|
||||
if (swapDisks.size() == 2) {
|
||||
command.add("-w", swapDisks.get(0).getIscsiName());
|
||||
command.add("-W", swapDisks.get(1).getIscsiName());
|
||||
}
|
||||
|
||||
final String result = command.execute();
|
||||
if (result == null){
|
||||
final List<VolumeVO> dataDisks = findVolumes(volumes, VolumeType.DATADISK);
|
||||
if (dataDisks.size() == 2) {
|
||||
final Script mountdata = new Script(_mountDatadiskPath, _mountTimeout, s_logger);
|
||||
mountdata.add("-m");
|
||||
mountdata.add("-M");
|
||||
mountdata.add("-h", storIp0);
|
||||
mountdata.add("-H", storIp1);
|
||||
mountdata.add("-n", vmName);
|
||||
mountdata.add("-c", "1");
|
||||
mountdata.add("-d", dataDisks.get(0).getIscsiName());
|
||||
mountdata.add("-D", dataDisks.get(1).getIscsiName());
|
||||
return mountdata.execute();
|
||||
|
||||
} else if (dataDisks.size() == 0){
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
_name = name;
|
||||
|
||||
String scriptsDir = (String)params.get("mount.scripts.dir");
|
||||
if (scriptsDir == null) {
|
||||
scriptsDir = "scripts/vm/storage/iscsi/comstar/filebacked";
|
||||
}
|
||||
|
||||
_mountDatadiskPath = Script.findScript(scriptsDir, "mountdatadisk.sh");
|
||||
if (_mountDatadiskPath == null) {
|
||||
throw new ConfigurationException("Unable to find mountdatadisk.sh");
|
||||
}
|
||||
s_logger.info("mountdatadisk.sh found in " + _mountDatadiskPath);
|
||||
|
||||
String value = (String)params.get("mount.script.timeout");
|
||||
_mountTimeout = NumbersUtil.parseInt(value, 240) * 1000;
|
||||
|
||||
_mountvmPath = Script.findScript(scriptsDir, "mountvm.sh");
|
||||
if (_mountvmPath == null) {
|
||||
throw new ConfigurationException("Unable to find mountvm.sh");
|
||||
}
|
||||
s_logger.info("mountvm.sh found in " + _mountvmPath);
|
||||
|
||||
_mountRootdiskPath = Script.findScript(scriptsDir, "mountrootdisk.sh");
|
||||
if (_mountRootdiskPath == null) {
|
||||
throw new ConfigurationException("Unable to find mountrootdisk.sh");
|
||||
}
|
||||
s_logger.info("mountrootdisk.sh found in " + _mountRootdiskPath);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1,583 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.storage;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.ModifyStoragePoolAnswer;
|
||||
import com.cloud.agent.api.ModifyStoragePoolCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupStorageCommand;
|
||||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
|
||||
import com.cloud.agent.api.storage.CreatePrivateTemplateCommand;
|
||||
import com.cloud.agent.api.storage.DestroyCommand;
|
||||
import com.cloud.agent.api.storage.UpgradeDiskAnswer;
|
||||
import com.cloud.agent.api.storage.UpgradeDiskCommand;
|
||||
import com.cloud.agent.api.to.VolumeTO;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.storage.Storage.StorageResourceType;
|
||||
import com.cloud.storage.template.TemplateInfo;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NfsUtils;
|
||||
import com.cloud.utils.script.OutputInterpreter;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
public abstract class FileSystemStorageResource extends StorageResource {
|
||||
protected static final Logger s_logger = Logger.getLogger(FileSystemStorageResource.class);
|
||||
protected String _templateRootDir;
|
||||
protected String _poolName;
|
||||
protected String _poolUuid;
|
||||
protected String _localStoragePath;
|
||||
|
||||
@Override
|
||||
public boolean existPath(String path) {
|
||||
if (path == null) {
|
||||
return false;
|
||||
}
|
||||
final Script cmd = new Script("ls", _timeout, s_logger);
|
||||
cmd.add(File.separator + path);
|
||||
|
||||
final String result = cmd.execute();
|
||||
if (result == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (result == Script.ERR_TIMEOUT) {
|
||||
throw new CloudRuntimeException("Script timed out");
|
||||
}
|
||||
|
||||
return !result.contains("No such file or directory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createPath(final String createPath) {
|
||||
final Script cmd = new Script("mkdir", _timeout, s_logger);
|
||||
cmd.add("-p", File.separator + createPath);
|
||||
|
||||
return cmd.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillNetworkInformation(StartupCommand cmd) {
|
||||
super.fillNetworkInformation(cmd);
|
||||
cmd.setIqn(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected long getUsedSize() {
|
||||
return getUsedSize(_rootDir);
|
||||
}
|
||||
|
||||
|
||||
protected long getUsedSize(String poolPath) {
|
||||
poolPath = getPoolPath(poolPath);
|
||||
if (poolPath == null) {
|
||||
return 0;
|
||||
}
|
||||
Script command = new Script("/bin/bash", _timeout, s_logger);
|
||||
command.add("-c");
|
||||
command.add("df -Ph " + poolPath + " | grep -v Used | awk '{print $3}' ");
|
||||
|
||||
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
|
||||
if (command.execute(parser) != null) {
|
||||
return -1;
|
||||
}
|
||||
return convertFilesystemSize(parser.getLine());
|
||||
}
|
||||
|
||||
private String getPoolPath(String poolPath) {
|
||||
if (!existPath(poolPath)) {
|
||||
poolPath = File.separator + poolPath;
|
||||
if (!existPath(poolPath))
|
||||
return null;
|
||||
}
|
||||
return poolPath;
|
||||
}
|
||||
|
||||
protected long getTotalSize(String poolPath) {
|
||||
poolPath = getPoolPath(poolPath);
|
||||
if (poolPath == null) {
|
||||
return 0;
|
||||
}
|
||||
Script command = new Script("/bin/bash", _timeout, s_logger);
|
||||
command.add("-c");
|
||||
command.add("df -Ph " + poolPath + " | grep -v Size | awk '{print $2}' ");
|
||||
|
||||
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
|
||||
if (command.execute(parser) != null) {
|
||||
return -1;
|
||||
}
|
||||
return convertFilesystemSize(parser.getLine());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long getTotalSize() {
|
||||
return getTotalSize(_rootDir);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createTrashDir(String imagePath, StringBuilder path) {
|
||||
final int index = imagePath.lastIndexOf(File.separator) + File.separator.length();
|
||||
path.append(_trashcanDir);
|
||||
path.append(imagePath.substring(_parent.length(), index));
|
||||
path.append(Long.toHexString(System.currentTimeMillis()));
|
||||
|
||||
final Script cmd = new Script("mkdir", _timeout, s_logger);
|
||||
cmd.add("-p", path.toString());
|
||||
|
||||
final String result = cmd.execute();
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
path.append(File.separator).append(imagePath.substring(index));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String destroy(String imagePath) {
|
||||
final StringBuilder trashPath = new StringBuilder();
|
||||
String result = createTrashDir(imagePath, trashPath);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
final Script cmd = new Script("mv", _timeout, s_logger);
|
||||
cmd.add(imagePath);
|
||||
cmd.add(trashPath.toString());
|
||||
result = cmd.execute();
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
s_logger.warn("Path " + imagePath + " has been moved to " + trashPath.toString());
|
||||
|
||||
cleanUpEmptyParents(imagePath);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanUpEmptyParents(String imagePath) {
|
||||
imagePath = imagePath.substring(0, imagePath.lastIndexOf(File.separator));
|
||||
String destroyPath = null;
|
||||
while (imagePath.length() > _parent.length() && !hasChildren(imagePath)) {
|
||||
destroyPath = imagePath;
|
||||
imagePath = imagePath.substring(0, imagePath.lastIndexOf(File.separator));
|
||||
}
|
||||
|
||||
if (destroyPath != null) {
|
||||
final Script cmd = new Script("rm", _timeout, s_logger);
|
||||
cmd.add("-rf", destroyPath);
|
||||
cmd.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Answer execute(DestroyCommand cmd) {
|
||||
VolumeTO volume = cmd.getVolume();
|
||||
String result = null;
|
||||
|
||||
result = delete(volume.getPath());
|
||||
return new Answer(cmd, result == null, result);
|
||||
}
|
||||
|
||||
private String delete(String image) {
|
||||
final Script cmd = new Script(_delvmPath, _timeout, s_logger);
|
||||
cmd.add("-i", image);
|
||||
|
||||
|
||||
final String result = cmd.execute();
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//cleanUpEmptyParents(image);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String delete(String imagePath, String extra) {
|
||||
return delete (imagePath);
|
||||
}
|
||||
|
||||
protected boolean isSharedNetworkFileSystem(String path) {
|
||||
if (path.endsWith("/")) {
|
||||
path = path.substring(0, path.length()-1);
|
||||
}
|
||||
Script command = new Script("/bin/bash", _timeout, s_logger);
|
||||
command.add("-c");
|
||||
command.add("mount -t nfs | grep nfs | awk '{print $3}' | grep -x " + path);
|
||||
|
||||
OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
|
||||
if (command.execute(parser) != null || parser.getLine() == null) { //not NFS client
|
||||
command = new Script("/bin/bash", _timeout, s_logger);
|
||||
command.add("-c");
|
||||
command.add("grep " + _rootDir + " /etc/exports");
|
||||
parser = new OutputInterpreter.OneLineParser();
|
||||
if (command.execute(parser) == null && parser.getLine() != null) {
|
||||
return true;
|
||||
}
|
||||
} else if (parser.getLine() != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private List<String[]> getNfsMounts(String path) {
|
||||
if (path != null && path.endsWith("/")) {
|
||||
path = path.substring(0, path.length()-1);
|
||||
}
|
||||
Script command = new Script("/bin/bash", _timeout, s_logger);
|
||||
command.add("-c");
|
||||
if (path != null) {
|
||||
command.add("cat /proc/mounts | grep nfs | grep " + path );
|
||||
} else {
|
||||
command.add("cat /proc/mounts | grep nfs | grep -v rpc_pipefs ");
|
||||
}
|
||||
|
||||
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
|
||||
if (command.execute(parser) != null || parser.getLines() == null) { //not NFS client
|
||||
return null;
|
||||
} else {
|
||||
List<String[]> result = new ArrayList<String[]>();
|
||||
String[] lines = parser.getLines().split("\\n");
|
||||
|
||||
for (String line: lines){
|
||||
String [] toks = line.split(" ");
|
||||
if ( toks.length < 4) {
|
||||
continue;
|
||||
}
|
||||
String [] hostpart = toks[0].split(":");
|
||||
if (hostpart.length != 2) {
|
||||
continue;
|
||||
}
|
||||
String localPath = toks[1];
|
||||
result.add(new String [] {hostpart[0], hostpart[1], localPath});
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String[]> getNetworkFileSystemServer(String path) {
|
||||
return getNfsMounts(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String create( String templatePath, final String rootdiskFolder, final String userPath, final String datadiskFolder, final String datadiskName, final int datadiskSize, String localPath) {
|
||||
|
||||
s_logger.debug("Creating volumes by cloning " + templatePath);
|
||||
final Script command = new Script(_createvmPath, _timeout, s_logger);
|
||||
|
||||
command.add("-t", templatePath);
|
||||
command.add("-i", rootdiskFolder);
|
||||
command.add("-u", userPath);
|
||||
if (datadiskSize != 0) {
|
||||
command.add("-f", datadiskFolder);
|
||||
command.add("-s", Integer.toString(datadiskSize));
|
||||
command.add("-n", datadiskName);
|
||||
}
|
||||
|
||||
return command.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UpgradeDiskAnswer execute(UpgradeDiskCommand cmd) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand []initialize() {
|
||||
StartupCommand [] cmds = super.initialize();
|
||||
StartupStorageCommand cmd = (StartupStorageCommand)cmds[0];
|
||||
|
||||
initLocalStorage(cmd);
|
||||
cmd.setTemplateInfo(new HashMap<String, TemplateInfo>()); //empty template info
|
||||
|
||||
return new StartupCommand[] {cmd};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Storage.StorageResourceType getStorageResourceType() {
|
||||
return Storage.StorageResourceType.STORAGE_POOL;
|
||||
}
|
||||
|
||||
protected String mountNfs(String hostAddress, String hostPath, String localPath) {
|
||||
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
|
||||
Script command = new Script("/bin/bash", _timeout, s_logger);
|
||||
command.add("-c");
|
||||
command.add("mount -t nfs -o acdirmax=0,acdirmin=0 " + hostAddress + ":" + hostPath + " " + localPath);
|
||||
String result = command.execute(parser);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected String umountNfs(String localPath) {
|
||||
Script command = new Script("/bin/bash", _timeout, s_logger);
|
||||
command.add("-c");
|
||||
command.add("umount " + localPath);
|
||||
String result = command.execute();
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void initLocalStorage(StartupStorageCommand cmd) {
|
||||
if (!existPath(_localStoragePath)) {
|
||||
createPath(_localStoragePath);
|
||||
}
|
||||
//setPoolPath(_localStoragePath);
|
||||
long capacity = getTotalSize(_localStoragePath);
|
||||
long used = getUsedSize(_localStoragePath);
|
||||
StoragePoolInfo poolInfo = new StoragePoolInfo( "Local Storage", "file://" + cmd.getPrivateIpAddress() + "/" + _localStoragePath, "localhost", _localStoragePath, _localStoragePath, StoragePoolType.Filesystem, capacity, capacity - used);
|
||||
cmd.setPoolInfo(poolInfo);
|
||||
}
|
||||
|
||||
|
||||
private Answer setFSStoragePool(ModifyStoragePoolCommand cmd) {
|
||||
StoragePoolVO pool = cmd.getPool();
|
||||
String localPath = pool.getPath();
|
||||
File localStorage = new File(localPath);
|
||||
if (!localStorage.exists()) {
|
||||
localStorage.mkdir();
|
||||
}
|
||||
/*String result = setPoolPath(localPath);
|
||||
if (result != null) {
|
||||
return new Answer(cmd, false, " Failed to create folders");
|
||||
}*/
|
||||
if (_instance != null) {
|
||||
localPath = localPath + File.separator + _instance;
|
||||
}
|
||||
_poolName = pool.getName();
|
||||
long capacity = getTotalSize(localPath);
|
||||
long used = getUsedSize(localPath);
|
||||
long available = capacity - used;
|
||||
Map<String, TemplateInfo> tInfo = new HashMap<String, TemplateInfo>();
|
||||
ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo);
|
||||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Answer execute(ModifyStoragePoolCommand cmd) {
|
||||
StoragePoolVO pool = cmd.getPool();
|
||||
if (pool.getPoolType() == StoragePoolType.Filesystem) {
|
||||
return setFSStoragePool(cmd);
|
||||
}
|
||||
if (cmd.getAdd()) {
|
||||
String result;
|
||||
String hostPath = pool.getPath();
|
||||
String hostPath2 = pool.getPath();
|
||||
if (hostPath.endsWith("/")) {
|
||||
hostPath2 = hostPath.substring(0, hostPath.length()-1);
|
||||
}
|
||||
String localPath = cmd.getLocalPath();
|
||||
boolean alreadyMounted = false;
|
||||
|
||||
List<String[]> shareInfo = getNfsMounts(null);
|
||||
if (shareInfo != null) {
|
||||
for (String [] share: shareInfo){
|
||||
String host = share[0];
|
||||
String path = share[1];
|
||||
String path2 = path;
|
||||
if (path.endsWith("/")) {
|
||||
path2 = path.substring(0, path.length()-1);
|
||||
}
|
||||
if (!path.equals(hostPath) && !path2.equals(hostPath2)){
|
||||
continue;
|
||||
}
|
||||
if (host.equalsIgnoreCase(pool.getHostAddress())){
|
||||
alreadyMounted = true;
|
||||
localPath = share[2];
|
||||
result = null;
|
||||
break;
|
||||
} else {
|
||||
try {
|
||||
InetAddress currAddr = InetAddress.getByName(host);
|
||||
InetAddress hostAddr = InetAddress.getByName(pool.getHostAddress());
|
||||
if (currAddr.equals(hostAddr)){
|
||||
alreadyMounted = true;
|
||||
result = null;
|
||||
localPath = share[2];
|
||||
break;
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String localPath2 = localPath;
|
||||
if (localPath.endsWith("/")){
|
||||
localPath2 = localPath.substring(0,localPath.length()-1);
|
||||
}
|
||||
|
||||
if (!alreadyMounted){
|
||||
Script mkdir = new Script("/bin/bash", _timeout, s_logger);
|
||||
mkdir.add("-c");
|
||||
mkdir.add("mkdir -p " + localPath);
|
||||
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
|
||||
result = mkdir.execute(parser);
|
||||
|
||||
if (result != null) {
|
||||
return new Answer(cmd, false, "Failed to create local path: " + result);
|
||||
}
|
||||
result = mountNfs(pool.getHostAddress(), pool.getPath(), localPath);
|
||||
if (result != null) {
|
||||
return new Answer(cmd, false, " Failed to mount: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
/*result = setPoolPath(localPath);
|
||||
if (result != null) {
|
||||
return new Answer(cmd, false, " Failed to create folders");
|
||||
}*/
|
||||
|
||||
|
||||
if (_instance != null) {
|
||||
localPath = localPath + File.separator + _instance;
|
||||
}
|
||||
_poolName =pool.getName();
|
||||
_poolUuid = pool.getUuid();
|
||||
long capacity = getTotalSize(localPath);
|
||||
long used = getUsedSize(localPath);
|
||||
long available = capacity - used;
|
||||
Map<String, TemplateInfo> tInfo = new HashMap<String, TemplateInfo>();
|
||||
ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo);
|
||||
return answer;
|
||||
} else {
|
||||
Script command = new Script("/bin/bash", _timeout, s_logger);
|
||||
command.add("-c");
|
||||
command.add("umount " + cmd.getLocalPath());
|
||||
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
|
||||
String result = command.execute(parser);
|
||||
if (result != null) {
|
||||
return new Answer(cmd, false, " Failed to unmount: " + result);
|
||||
}
|
||||
return new Answer(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String create(String templateFolder, String rootdiskFolder, String userPath, String dataPath, String localPath) {
|
||||
|
||||
s_logger.debug("Creating volumes");
|
||||
final Script command = new Script(_createvmPath, _timeout, s_logger);
|
||||
|
||||
command.add("-t", templateFolder);
|
||||
command.add("-i", rootdiskFolder);
|
||||
command.add("-u", userPath);
|
||||
|
||||
|
||||
return command.execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected String mountSecondaryStorage(String tmplMpt, String templatePath, String hostMpt) {
|
||||
String mountStr = null;
|
||||
try {
|
||||
mountStr = NfsUtils.url2Mount(tmplMpt);
|
||||
} catch (URISyntaxException e) {
|
||||
s_logger.debug("Is not a valid url" + tmplMpt);
|
||||
return null;
|
||||
}
|
||||
String []tok = mountStr.split(":");
|
||||
/*Mount already?*/
|
||||
if (!isNfsMounted(tok[0], tok[1], hostMpt)) {
|
||||
mountNfs(tok[0], tok[1], hostMpt);
|
||||
}
|
||||
if (!templatePath.startsWith("/"))
|
||||
templatePath = hostMpt + "/" + templatePath;
|
||||
else
|
||||
templatePath = hostMpt + templatePath;
|
||||
|
||||
return templatePath;
|
||||
}
|
||||
|
||||
protected boolean isNfsMounted(final String remoteHost, final String remotePath, final String mountPath) {
|
||||
boolean alreadyMounted = false;
|
||||
List<String[]> shareInfo = getNfsMounts(null);
|
||||
if (shareInfo != null) {
|
||||
for (String [] share: shareInfo){
|
||||
String host = share[0];
|
||||
String path = share[1];
|
||||
String path2 = path;
|
||||
String localPath = share[2];
|
||||
String localPath2 = localPath;
|
||||
|
||||
if (path.endsWith("/")) {
|
||||
path2 = path.substring(0, path.length()-1);
|
||||
}
|
||||
if (localPath.endsWith("/")) {
|
||||
localPath2 = localPath.substring(0, localPath.length() -1);
|
||||
}
|
||||
if ((!path.equals(remotePath) && !path2.equals(remotePath)) || (!localPath.equals(mountPath) && !localPath2.equals(mountPath)) ){
|
||||
continue;
|
||||
}
|
||||
|
||||
if (host.equalsIgnoreCase(remoteHost)){
|
||||
alreadyMounted = true;
|
||||
break;
|
||||
} else {
|
||||
try {
|
||||
InetAddress currAddr = InetAddress.getByName(host);
|
||||
InetAddress hostAddr = InetAddress.getByName(remoteHost);
|
||||
if (currAddr.equals(hostAddr)){
|
||||
alreadyMounted = true;
|
||||
break;
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return alreadyMounted;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultScriptsDir() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CreatePrivateTemplateAnswer execute(CreatePrivateTemplateCommand cmd) {
|
||||
CreatePrivateTemplateAnswer answer = super.execute(cmd);
|
||||
answer.setPath(answer.getPath().replaceFirst(_rootDir, ""));
|
||||
answer.setPath(answer.getPath().replaceFirst("^/*", "/"));
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,600 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.storage;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.BackupSnapshotAnswer;
|
||||
import com.cloud.agent.api.BackupSnapshotCommand;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.GetFileStatsAnswer;
|
||||
import com.cloud.agent.api.GetFileStatsCommand;
|
||||
import com.cloud.agent.api.GetStorageStatsAnswer;
|
||||
import com.cloud.agent.api.GetStorageStatsCommand;
|
||||
import com.cloud.agent.api.ManageSnapshotAnswer;
|
||||
import com.cloud.agent.api.ManageSnapshotCommand;
|
||||
import com.cloud.agent.api.ModifyStoragePoolCommand;
|
||||
import com.cloud.agent.api.PingCommand;
|
||||
import com.cloud.agent.api.PingStorageCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupStorageCommand;
|
||||
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
|
||||
import com.cloud.agent.api.storage.CreatePrivateTemplateCommand;
|
||||
import com.cloud.agent.api.storage.DestroyCommand;
|
||||
import com.cloud.agent.api.storage.DownloadCommand;
|
||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
|
||||
import com.cloud.agent.api.storage.ShareAnswer;
|
||||
import com.cloud.agent.api.storage.ShareCommand;
|
||||
import com.cloud.agent.api.storage.UpgradeDiskAnswer;
|
||||
import com.cloud.agent.api.storage.UpgradeDiskCommand;
|
||||
import com.cloud.agent.api.storage.UploadCommand;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.resource.ServerResourceBase;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.storage.template.DownloadManager;
|
||||
import com.cloud.storage.template.TemplateInfo;
|
||||
import com.cloud.storage.template.UploadManager;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.OutputInterpreter;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
/**
|
||||
* StorageResource represents the storage server. It executes commands
|
||||
* against the storage server.
|
||||
*
|
||||
* @config
|
||||
* {@table
|
||||
* || Param Name | Description | Values | Default ||
|
||||
* || pool | name of the pool to use | String | tank ||
|
||||
* || parent | parent path to all of the templates and the trashcan | Path | [pool]/vmops ||
|
||||
* || scripts.dir | directory to the scripts | Path | ./scripts ||
|
||||
* || scripts.timeout | timeout value to use when executing scripts | seconds | 120s ||
|
||||
* || public.templates.root.dir | directory where public templates reside | Path | [pool]/volumes/demo/template/public/os ||
|
||||
* || private.templates.root.dir | directory where private templates reside | Path | [pool]/volumes/template/demo/private ||
|
||||
* || templates.download.dir | directory where templates are downloaded prior to being installed | Path | [pool]/volumes/demo/template/download ||
|
||||
* || install.timeout.pergig | timeout for the template creation script per downloaded gigabyte | seconds | 900s ||
|
||||
* || install.numthreads | number of concurrent install threads | number | 3 ||
|
||||
* }
|
||||
*/
|
||||
public abstract class StorageResource extends ServerResourceBase implements ServerResource {
|
||||
protected static final Logger s_logger = Logger.getLogger(StorageResource.class);
|
||||
protected String _createvmPath;
|
||||
protected String _listvmdiskPath;
|
||||
protected String _listvmdisksizePath;
|
||||
protected String _delvmPath;
|
||||
protected String _manageSnapshotPath;
|
||||
protected String _manageVolumePath;
|
||||
protected String _createPrivateTemplatePath;
|
||||
protected String _guid;
|
||||
protected String _rootDir;
|
||||
protected String _rootFolder = "vmops";
|
||||
protected String _parent;
|
||||
protected String _trashcanDir;
|
||||
protected String _vmFolder;
|
||||
protected String _trashcanFolder;
|
||||
protected String _datadisksFolder;
|
||||
protected String _datadisksDir;
|
||||
protected String _sharePath;
|
||||
protected String _infoPath;
|
||||
protected int _timeout;
|
||||
|
||||
protected String _iqnPath;
|
||||
|
||||
protected String _checkchildrenPath;
|
||||
protected String _userPrivateTemplateRootDir;
|
||||
|
||||
protected String _zfsScriptsDir;
|
||||
|
||||
protected DownloadManager _downloadManager;
|
||||
protected UploadManager _uploadManager;
|
||||
|
||||
protected Map<Long, VolumeSnapshotRequest> _volumeHourlySnapshotRequests = new HashMap<Long, VolumeSnapshotRequest>();
|
||||
protected Map<Long, VolumeSnapshotRequest> _volumeDailySnapshotRequests = new HashMap<Long, VolumeSnapshotRequest>();
|
||||
protected String _instance;
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(final Command cmd) {
|
||||
if (cmd instanceof DestroyCommand) {
|
||||
return execute((DestroyCommand)cmd);
|
||||
} else if (cmd instanceof GetFileStatsCommand) {
|
||||
return execute((GetFileStatsCommand)cmd);
|
||||
} else if (cmd instanceof PrimaryStorageDownloadCommand) {
|
||||
return execute((PrimaryStorageDownloadCommand)cmd);
|
||||
} else if (cmd instanceof DownloadCommand) {
|
||||
return execute((DownloadCommand)cmd);
|
||||
}else if (cmd instanceof UploadCommand) {
|
||||
return execute((UploadCommand)cmd);
|
||||
} else if (cmd instanceof GetStorageStatsCommand) {
|
||||
return execute((GetStorageStatsCommand)cmd);
|
||||
} else if (cmd instanceof UpgradeDiskCommand) {
|
||||
return execute((UpgradeDiskCommand) cmd);
|
||||
} else if (cmd instanceof ShareCommand) {
|
||||
return execute((ShareCommand)cmd);
|
||||
} else if (cmd instanceof ManageSnapshotCommand) {
|
||||
return execute((ManageSnapshotCommand)cmd);
|
||||
} else if (cmd instanceof BackupSnapshotCommand) {
|
||||
return execute((BackupSnapshotCommand)cmd);
|
||||
} else if (cmd instanceof CreatePrivateTemplateCommand) {
|
||||
return execute((CreatePrivateTemplateCommand)cmd);
|
||||
} else if (cmd instanceof ModifyStoragePoolCommand ){
|
||||
return execute ((ModifyStoragePoolCommand) cmd);
|
||||
} else {
|
||||
s_logger.warn("StorageResource: Unsupported command");
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(ModifyStoragePoolCommand cmd) {
|
||||
s_logger.warn("Unsupported: network file system mount attempted");
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
|
||||
protected ShareAnswer execute(final ShareCommand cmd) {
|
||||
return new ShareAnswer(cmd, new HashMap<String, Integer>());
|
||||
}
|
||||
|
||||
protected Answer execute(final PrimaryStorageDownloadCommand cmd) {
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
|
||||
private Answer execute(UploadCommand cmd) {
|
||||
return _uploadManager.handleUploadCommand(cmd);
|
||||
}
|
||||
|
||||
protected Answer execute(final DownloadCommand cmd) {
|
||||
return _downloadManager.handleDownloadCommand(cmd);
|
||||
}
|
||||
|
||||
public String getSecondaryStorageMountPoint(String uri) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getUserPath(final String image) {
|
||||
return image.substring(0, image.indexOf(File.separator, _parent.length() + 2)).intern();
|
||||
}
|
||||
|
||||
|
||||
protected Answer execute(final GetFileStatsCommand cmd) {
|
||||
final String image = cmd.getPaths();
|
||||
final Script command = new Script(_listvmdisksizePath, _timeout, s_logger);
|
||||
command.add("-d", image);
|
||||
command.add("-a");
|
||||
|
||||
final SizeParser parser = new SizeParser();
|
||||
final String result = command.execute(parser);
|
||||
if (result != null) {
|
||||
return new Answer(cmd, false, result);
|
||||
}
|
||||
|
||||
return new GetFileStatsAnswer(cmd, parser.size);
|
||||
}
|
||||
|
||||
protected List<VolumeVO> getVolumes(final String rootdiskFolder, final String datadiskFolder, final String datadiskName) {
|
||||
final ArrayList<VolumeVO> vols = new ArrayList<VolumeVO>();
|
||||
|
||||
// Get the rootdisk volume
|
||||
String path = rootdiskFolder + File.separator + "rootdisk";
|
||||
long totalSize = getVolumeSize(path);
|
||||
|
||||
VolumeVO vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), rootdiskFolder, path, totalSize, Volume.VolumeType.ROOT);
|
||||
vols.add(vol);
|
||||
|
||||
// Get the datadisk volume
|
||||
if (datadiskFolder != null && datadiskName != null) {
|
||||
path = datadiskFolder + File.separator + datadiskName;
|
||||
totalSize = getVolumeSize(path);
|
||||
|
||||
vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), datadiskFolder, path, totalSize, Volume.VolumeType.DATADISK);
|
||||
vols.add(vol);
|
||||
}
|
||||
|
||||
return vols;
|
||||
}
|
||||
|
||||
protected List<VolumeVO> getVolumes(final String imagePath) {
|
||||
final ArrayList<VolumeVO> vols = new ArrayList<VolumeVO>();
|
||||
|
||||
String path = getVolumeName(imagePath, null);
|
||||
long totalSize = getVolumeSize(path);
|
||||
|
||||
VolumeVO vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.ROOT);
|
||||
|
||||
vols.add(vol);
|
||||
|
||||
path = getVolumeName(imagePath, (long)1);
|
||||
if (path != null) {
|
||||
totalSize = getVolumeSize(path);
|
||||
|
||||
|
||||
vol = new VolumeVO(null, -1, -1, -1, -1, new Long(-1), null, path, totalSize, Volume.VolumeType.DATADISK);
|
||||
vols.add(vol);
|
||||
}
|
||||
|
||||
return vols;
|
||||
}
|
||||
|
||||
protected long getVolumeSize(final String volume) {
|
||||
final Script command = new Script(_listvmdisksizePath, _timeout, s_logger);
|
||||
|
||||
command.add("-d", volume);
|
||||
command.add("-t");
|
||||
|
||||
final SizeParser parser = new SizeParser();
|
||||
final String result = command.execute(parser);
|
||||
if (result != null) {
|
||||
throw new CloudRuntimeException(result);
|
||||
}
|
||||
return parser.size;
|
||||
}
|
||||
|
||||
protected String getVolumeName(final String imagePath, final Long diskNum) {
|
||||
|
||||
final Script command = new Script(_listvmdiskPath, _timeout, s_logger);
|
||||
command.add("-i", imagePath);
|
||||
if (diskNum == null) {
|
||||
command.add("-r");
|
||||
} else {
|
||||
command.add("-d", diskNum.toString());
|
||||
}
|
||||
|
||||
final PathParser parser = new PathParser();
|
||||
final String result = command.execute(parser);
|
||||
if (result != null) {
|
||||
throw new CloudRuntimeException("Can't get volume name due to " + result);
|
||||
}
|
||||
|
||||
return parser.path;
|
||||
}
|
||||
|
||||
|
||||
protected long convertFilesystemSize(final String size) {
|
||||
if (size == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
long multiplier = 1;
|
||||
if (size.endsWith("T")) {
|
||||
multiplier = 1024l * 1024l * 1024l * 1024l;
|
||||
} else if (size.endsWith("G")) {
|
||||
multiplier = 1024l * 1024l * 1024l;
|
||||
} else if (size.endsWith("M")) {
|
||||
multiplier = 1024l * 1024l;
|
||||
} else if (size.endsWith("K")){
|
||||
multiplier = 1024l;
|
||||
} else {
|
||||
long num;
|
||||
try {
|
||||
num = Long.parseLong(size);
|
||||
} catch (NumberFormatException e) {
|
||||
s_logger.debug("Unknow size:" + size);
|
||||
return 0;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
return (long)(Double.parseDouble(size.substring(0, size.length() - 1)) * multiplier);
|
||||
}
|
||||
|
||||
protected abstract void cleanUpEmptyParents(String imagePath);
|
||||
protected abstract long getUsedSize() ;
|
||||
protected abstract long getTotalSize();
|
||||
protected abstract String destroy(final String imagePath) ;
|
||||
protected abstract String createTrashDir(final String imagePath, final StringBuilder path) ;
|
||||
public abstract boolean existPath(final String path);
|
||||
public abstract String createPath(final String createPath) ;
|
||||
protected abstract Answer execute(DestroyCommand cmd) ;
|
||||
protected abstract UpgradeDiskAnswer execute(final UpgradeDiskCommand cmd);
|
||||
protected abstract String delete(String imagePath, String extra);
|
||||
protected abstract Storage.StorageResourceType getStorageResourceType();
|
||||
protected abstract void configureFolders(String name, Map<String, Object> params) throws ConfigurationException ;
|
||||
|
||||
|
||||
|
||||
protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) {
|
||||
final long size = getUsedSize();
|
||||
return size != -1 ? new GetStorageStatsAnswer(cmd, 0, size) : new GetStorageStatsAnswer(cmd, "Unable to get storage stats");
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected ManageSnapshotAnswer execute(final ManageSnapshotCommand cmd) {
|
||||
final Script command = new Script(_manageSnapshotPath, _timeout, s_logger);
|
||||
String path = null;
|
||||
if (cmd.getCommandSwitch().equalsIgnoreCase(ManageSnapshotCommand.DESTROY_SNAPSHOT)) {
|
||||
path = cmd.getSnapshotPath();
|
||||
} else if (cmd.getCommandSwitch().equalsIgnoreCase(ManageSnapshotCommand.CREATE_SNAPSHOT)) {
|
||||
path = cmd.getVolumePath();
|
||||
}
|
||||
command.add(cmd.getCommandSwitch(), path);
|
||||
command.add("-n", cmd.getSnapshotName());
|
||||
|
||||
final String result = command.execute();
|
||||
return new ManageSnapshotAnswer(cmd, cmd.getSnapshotId(),cmd.getVolumePath(), (result == null), result);
|
||||
}
|
||||
|
||||
protected BackupSnapshotAnswer execute(final BackupSnapshotCommand cmd) {
|
||||
// This is implemented only for XenServerResource
|
||||
Answer answer = Answer.createUnsupportedCommandAnswer(cmd);
|
||||
return new BackupSnapshotAnswer(cmd, false, answer.getDetails(), null);
|
||||
}
|
||||
|
||||
protected CreatePrivateTemplateAnswer execute(final CreatePrivateTemplateCommand cmd) {
|
||||
final Script command = new Script(_createPrivateTemplatePath, _timeout, s_logger);
|
||||
|
||||
String installDir = _userPrivateTemplateRootDir;
|
||||
if (installDir.startsWith("/")) {
|
||||
installDir = installDir.substring(1);
|
||||
}
|
||||
|
||||
command.add("-p", cmd.getSnapshotPath());
|
||||
command.add("-s", cmd.getTemplateName());
|
||||
command.add("-d", installDir);
|
||||
command.add("-u", cmd.getUserFolder());
|
||||
String templateName = cmd.getTemplateName().replaceAll(" ", "_"); //hard to pass spaces to shell scripts
|
||||
if (templateName.length() > 32) {
|
||||
templateName = templateName.substring(0,31); //truncate
|
||||
}
|
||||
command.add("-n", templateName);
|
||||
|
||||
final String result = command.execute();
|
||||
CreatePrivateTemplateAnswer answer = new CreatePrivateTemplateAnswer(cmd, (result == null), result, null, 0, null, null);
|
||||
|
||||
if (result == null) {
|
||||
answer.setPath("/" + installDir + "/" + cmd.getUserFolder() + "/" + templateName);
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
protected String create(final String rootdiskFolder, final int rootDiskSizeGB) {
|
||||
|
||||
final Script command = new Script(_createvmPath, _timeout, s_logger);
|
||||
command.add("-i", rootdiskFolder);
|
||||
command.add("-S", Integer.toString(rootDiskSizeGB));
|
||||
|
||||
return command.execute();
|
||||
}
|
||||
|
||||
protected String create(final String templateFolder, final String rootdiskFolder, final String userPath, final String dataPath, String localPath) {
|
||||
|
||||
final Script command = new Script(_createvmPath, _timeout, s_logger);
|
||||
command.add("-t", templateFolder);
|
||||
command.add("-i", rootdiskFolder);
|
||||
command.add("-u", userPath);
|
||||
if (dataPath != null) {
|
||||
command.add("-d", dataPath);
|
||||
}
|
||||
|
||||
return command.execute();
|
||||
}
|
||||
|
||||
protected String create(final String templateFolder, final String rootdiskFolder, final String userPath, final String datadiskFolder, final String datadiskName, final int datadiskSize, String localPath) {
|
||||
|
||||
final Script command = new Script(_createvmPath, _timeout, s_logger);
|
||||
|
||||
// for private templates, the script needs the snapshot name being used to create the VM
|
||||
command.add("-t", templateFolder);
|
||||
command.add("-i", rootdiskFolder);
|
||||
command.add("-u", userPath);
|
||||
if (datadiskSize != 0) {
|
||||
command.add("-f", datadiskFolder);
|
||||
command.add("-s", Integer.toString(datadiskSize));
|
||||
command.add("-n", datadiskName);
|
||||
}
|
||||
|
||||
return command.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(final long id) {
|
||||
return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
final StartupStorageCommand cmd = new StartupStorageCommand(_parent, StoragePoolType.NetworkFilesystem, getTotalSize(), new HashMap<String, TemplateInfo>());
|
||||
cmd.setResourceType(getStorageResourceType());
|
||||
cmd.setIqn(getIQN());
|
||||
fillNetworkInformation(cmd);
|
||||
return new StartupCommand [] {cmd};
|
||||
}
|
||||
|
||||
protected String getIQN() {
|
||||
final Script command = new Script(_iqnPath, 500, s_logger);
|
||||
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
|
||||
final String result = command.execute(parser);
|
||||
if (result != null) {
|
||||
throw new CloudRuntimeException("Unable to get iqn: " + result);
|
||||
}
|
||||
|
||||
return parser.getLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String findScript(String script) {
|
||||
return Script.findScript(_zfsScriptsDir, script);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected abstract String getDefaultScriptsDir();
|
||||
|
||||
@Override
|
||||
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
|
||||
if (!super.configure(name, params)) {
|
||||
s_logger.warn("Base class was unable to configure");
|
||||
return false;
|
||||
}
|
||||
|
||||
_zfsScriptsDir = (String)params.get("zfs.scripts.dir");
|
||||
if (_zfsScriptsDir == null) {
|
||||
_zfsScriptsDir = getDefaultScriptsDir();
|
||||
}
|
||||
|
||||
String value = (String)params.get("scripts.timeout");
|
||||
_timeout = NumbersUtil.parseInt(value, 1440) * 1000;
|
||||
|
||||
_createvmPath = findScript("createvm.sh");
|
||||
if (_createvmPath == null) {
|
||||
throw new ConfigurationException("Unable to find the createvm.sh");
|
||||
}
|
||||
s_logger.info("createvm.sh found in " + _createvmPath);
|
||||
|
||||
_delvmPath = findScript("delvm.sh");
|
||||
if (_delvmPath == null) {
|
||||
throw new ConfigurationException("Unable to find the delvm.sh");
|
||||
}
|
||||
s_logger.info("delvm.sh found in " + _delvmPath);
|
||||
|
||||
_listvmdiskPath = findScript("listvmdisk.sh");
|
||||
if (_listvmdiskPath == null) {
|
||||
throw new ConfigurationException("Unable to find the listvmdisk.sh");
|
||||
}
|
||||
s_logger.info("listvmdisk.sh found in " + _listvmdiskPath);
|
||||
|
||||
_listvmdisksizePath = findScript("listvmdisksize.sh");
|
||||
if (_listvmdisksizePath == null) {
|
||||
throw new ConfigurationException("Unable to find the listvmdisksize.sh");
|
||||
}
|
||||
s_logger.info("listvmdisksize.sh found in " + _listvmdisksizePath);
|
||||
|
||||
_iqnPath = findScript("get_iqn.sh");
|
||||
if (_iqnPath == null) {
|
||||
throw new ConfigurationException("Unable to find get_iqn.sh");
|
||||
}
|
||||
s_logger.info("get_iqn.sh found in " + _iqnPath);
|
||||
|
||||
_manageSnapshotPath = findScript("managesnapshot.sh");
|
||||
if (_manageSnapshotPath == null) {
|
||||
throw new ConfigurationException("Unable to find the managesnapshot.sh");
|
||||
}
|
||||
s_logger.info("managesnapshot.sh found in " + _manageSnapshotPath);
|
||||
|
||||
_manageVolumePath = findScript("managevolume.sh");
|
||||
if (_manageVolumePath == null) {
|
||||
throw new ConfigurationException("Unable to find managevolume.sh");
|
||||
}
|
||||
s_logger.info("managevolume.sh found in " + _manageVolumePath);
|
||||
|
||||
_createPrivateTemplatePath = findScript("create_private_template.sh");
|
||||
if (_createPrivateTemplatePath == null) {
|
||||
throw new ConfigurationException("Unable to find the create_private_template.sh");
|
||||
}
|
||||
s_logger.info("create_private_template.sh found in " + _createPrivateTemplatePath);
|
||||
|
||||
_checkchildrenPath = findScript("checkchildren.sh");
|
||||
if (_checkchildrenPath == null) {
|
||||
throw new ConfigurationException("Unable to find the checkchildren.sh");
|
||||
}
|
||||
|
||||
value = (String)params.get("developer");
|
||||
boolean isDeveloper = Boolean.parseBoolean(value);
|
||||
|
||||
_instance = (String)params.get("instance");
|
||||
/*
|
||||
String guid = (String)params.get("guid");
|
||||
if (!isDeveloper && guid == null) {
|
||||
throw new ConfigurationException("Unable to find the guid");
|
||||
}
|
||||
_guid = guid;*/
|
||||
/*
|
||||
params.put("template.parent", _parent);
|
||||
_downloadManager = new DownloadManagerImpl();
|
||||
_downloadManager.configure("DownloadManager", params);*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Host.Type getType() {
|
||||
return Host.Type.Storage;
|
||||
}
|
||||
|
||||
protected boolean hasChildren(final String path) {
|
||||
final Script script = new Script(_checkchildrenPath, _timeout, s_logger);
|
||||
script.add(path);
|
||||
|
||||
return script.execute() != null; // not null means there's children.
|
||||
}
|
||||
|
||||
|
||||
public static class SizeParser extends OutputInterpreter {
|
||||
long size = 0;
|
||||
@Override
|
||||
public String interpret(final BufferedReader reader) throws IOException {
|
||||
String line = null;
|
||||
final StringBuilder buff = new StringBuilder();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
buff.append(line);
|
||||
}
|
||||
|
||||
size = Long.parseLong(buff.toString());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PathParser extends OutputInterpreter {
|
||||
String path;
|
||||
@Override
|
||||
public String interpret(final BufferedReader reader) throws IOException {
|
||||
String line = null;
|
||||
final StringBuilder buff = new StringBuilder();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
buff.append(line);
|
||||
}
|
||||
|
||||
path = buff.toString();
|
||||
if (path != null && path.length() == 0) {
|
||||
path = null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected class VolumeSnapshotRequest {
|
||||
private final long _volumeId;
|
||||
private final String _snapshotPath;
|
||||
|
||||
public VolumeSnapshotRequest(long volumeId, String snapshotPath) {
|
||||
_volumeId = volumeId;
|
||||
_snapshotPath = snapshotPath;
|
||||
}
|
||||
|
||||
public long getVolumeId() {
|
||||
return _volumeId;
|
||||
}
|
||||
|
||||
public String getSnapshotPath() {
|
||||
return _snapshotPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -22,7 +22,6 @@ import java.util.Map;
|
||||
|
||||
import com.cloud.agent.api.storage.DownloadAnswer;
|
||||
import com.cloud.agent.api.storage.DownloadCommand;
|
||||
import com.cloud.storage.StorageResource;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.utils.component.Manager;
|
||||
@ -104,9 +103,7 @@ public interface DownloadManager extends Manager {
|
||||
* @return list of template info for installed templates
|
||||
*/
|
||||
public Map<String, TemplateInfo> gatherTemplateInfo();
|
||||
|
||||
public String setRootDir(String rootDir, StorageResource storage);
|
||||
|
||||
|
||||
public String getPublicTemplateRepo();
|
||||
|
||||
}
|
||||
@ -46,7 +46,6 @@ import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.StorageLayer;
|
||||
import com.cloud.storage.StorageResource;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.template.Processor.FormatInfo;
|
||||
import com.cloud.storage.template.TemplateDownloader.DownloadCompleteCallback;
|
||||
@ -208,19 +207,6 @@ public class DownloadManagerImpl implements DownloadManager {
|
||||
private int installTimeoutPerGig = 180 * 60 * 1000;
|
||||
private boolean _sslCopy;
|
||||
|
||||
@Override
|
||||
public String setRootDir(String rootDir, StorageResource storage) {
|
||||
/*
|
||||
* if (!storage.existPath(rootDir + templateDownloadDir)) { s_logger.info("Creating template download path: " +
|
||||
* rootDir + templateDownloadDir); String result = storage.createPath(rootDir + templateDownloadDir); if (result
|
||||
* != null) { return "Cannot create " + rootDir + templateDownloadDir + " due to " + result; } }
|
||||
* this.templateDownloadDir = rootDir + templateDownloadDir;
|
||||
*/
|
||||
this.publicTemplateRepo = rootDir + publicTemplateRepo;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notified of change of job status. Executed in context of downloader thread
|
||||
*
|
||||
|
||||
@ -6,7 +6,6 @@ import com.cloud.agent.api.storage.DeleteEntityDownloadURLAnswer;
|
||||
import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
|
||||
import com.cloud.agent.api.storage.UploadAnswer;
|
||||
import com.cloud.agent.api.storage.UploadCommand;
|
||||
import com.cloud.storage.StorageResource;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Upload.Status;
|
||||
import com.cloud.utils.component.Manager;
|
||||
@ -54,8 +53,6 @@ public interface UploadManager extends Manager {
|
||||
* @return answer representing status of upload.
|
||||
*/
|
||||
public UploadAnswer handleUploadCommand(UploadCommand cmd);
|
||||
|
||||
public String setRootDir(String rootDir, StorageResource storage);
|
||||
|
||||
public String getPublicTemplateRepo();
|
||||
|
||||
|
||||
@ -24,7 +24,6 @@ import com.cloud.agent.api.storage.UploadCommand;
|
||||
import com.cloud.agent.api.storage.UploadProgressCommand;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.StorageLayer;
|
||||
import com.cloud.storage.StorageResource;
|
||||
import com.cloud.storage.Upload;
|
||||
import com.cloud.storage.UploadVO;
|
||||
import com.cloud.storage.template.TemplateUploader.Status;
|
||||
@ -403,12 +402,6 @@ public class UploadManagerImpl implements UploadManager {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String setRootDir(String rootDir, StorageResource storage) {
|
||||
this.publicTemplateRepo = rootDir + publicTemplateRepo;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
|
||||
@ -1,270 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: createtmplt.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/createtmplt.sh $
|
||||
# createtmplt.sh -- install a template
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -t <template-fs> -n <templatename> -f <root disk file> -s <size in Gigabytes> -c <md5 cksum> -d <descr> -h [-u]\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#set -x
|
||||
|
||||
rollback_if_needed() {
|
||||
if [ $2 -gt 0 ]
|
||||
then
|
||||
printf "$3\n"
|
||||
#back out all changes
|
||||
zfs destroy -r $1
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
verify_cksum() {
|
||||
echo "$1 $2" | md5sum -c --status
|
||||
#printf "$1\t$2" | md5sum -c --status
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Checksum failed, not proceeding with install\n"
|
||||
exit 3
|
||||
fi
|
||||
}
|
||||
|
||||
untar() {
|
||||
local ft=$(file $1| awk -F" " '{print $2}')
|
||||
local basedir=$(dirname $1)
|
||||
case $ft in
|
||||
USTAR) local rootimg=$(tar tf $1 | grep $3)
|
||||
(cd $2; tar xf $1)
|
||||
rm -f $1
|
||||
printf "$2/$rootimg"
|
||||
;;
|
||||
*) printf "$1"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
uncompress() {
|
||||
local ft=$(file $1| awk -F" " '{print $2}')
|
||||
local imgfile=${1%.*} #strip out trailing file suffix
|
||||
local tmpfile=${imgfile}.tmp
|
||||
|
||||
case $ft in
|
||||
gzip) gunzip -c $1 > $tmpfile
|
||||
;;
|
||||
bzip2) bunzip2 -c $1 > $tmpfile
|
||||
;;
|
||||
ZIP) unzip -p $1 | cat > $tmpfile
|
||||
;;
|
||||
*) printf "$1"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to uncompress file, exiting "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mv $tmpfile $imgfile
|
||||
printf "$imgfile"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
create_vol_from_file() {
|
||||
local tmpltfs=$1
|
||||
local tmpltimg=$2
|
||||
local tgtvol=$3
|
||||
local tgtdisk=$4
|
||||
local volsize=$5
|
||||
local cleanup=$6
|
||||
|
||||
zfs list -H -o name $tgtvol
|
||||
|
||||
#create it if it doesn't exist
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
zfs create -V $volsize -s $tgtvol
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to create the target root disk volume\n"
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
|
||||
local osversion=$(uname -v)
|
||||
if [ "$osversion" == "snv_111b" ]
|
||||
then
|
||||
#copy 64k of zeros for LUN metatdata
|
||||
dd if=/dev/zero of=$tgtdisk bs=64k count=1
|
||||
#copy the file to the disk
|
||||
dd if=$tmpltimg of=$tgtdisk bs=64k seek=1
|
||||
else
|
||||
#copy the file to the disk. Could just use 'cp' as well
|
||||
dd if=$tmpltimg of=$tgtdisk bs=1024k
|
||||
fi
|
||||
|
||||
|
||||
rollback_if_needed $tmpltfs $? "Failed to copy root disk"
|
||||
|
||||
if [ "$cleanup" == "true" ]
|
||||
then
|
||||
rm -f $tmpltimg
|
||||
fi
|
||||
}
|
||||
|
||||
tflag=
|
||||
nflag=
|
||||
fflag=
|
||||
sflag=
|
||||
hflag=
|
||||
hvm=false
|
||||
cleanup=false
|
||||
dflag=
|
||||
cflag=
|
||||
|
||||
while getopts 'uht:n:f:s:c:d:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
t) tflag=1
|
||||
tmpltfs="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
tmpltname="$OPTARG"
|
||||
;;
|
||||
f) fflag=1
|
||||
tmpltimg="$OPTARG"
|
||||
;;
|
||||
s) sflag=1
|
||||
volsize="$OPTARG"
|
||||
;;
|
||||
c) cflag=1
|
||||
cksum="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
descr="$OPTARG"
|
||||
;;
|
||||
h) hflag=1
|
||||
hvm="true"
|
||||
;;
|
||||
u) cleanup="true"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$tflag$nflag$fflag$sflag" != "1111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ -n "$cksum" ]
|
||||
then
|
||||
verify_cksum $cksum $tmpltimg
|
||||
fi
|
||||
|
||||
if [ ${tmpltfs:0:1} == / ]
|
||||
then
|
||||
tmpltfs=${tmpltfs:1}
|
||||
fi
|
||||
|
||||
if [ ! -d /$tmpltfs ]
|
||||
then
|
||||
zfs create $tmpltfs
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to create user fs $tmpltfs\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $tmpltfs) != filesystem ]]
|
||||
then
|
||||
printf "template fs doesn't exist\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
tmpltimg2=$(uncompress $tmpltimg)
|
||||
tmpltimg2=$(untar $tmpltimg2 /$tmpltfs vmi-root)
|
||||
|
||||
if [ ! -f $tmpltimg2 ]
|
||||
then
|
||||
rollback_if_needed $tmpltfs 2 "root disk file $tmpltimg doesn't exist\n"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# need the 'G' suffix on volume size
|
||||
if [ ${volsize:(-1)} != G ]
|
||||
then
|
||||
volsize=${volsize}G
|
||||
fi
|
||||
|
||||
#determine source file size -- it needs to be less than or equal to volsize
|
||||
imgsize=$(ls -lh $tmpltimg2| awk -F" " '{print $5}')
|
||||
if [ ${imgsize:(-1)} == G ]
|
||||
then
|
||||
imgsize=${imgsize%G} #strip out the G
|
||||
imgsize=${imgsize%.*} #...and any decimal part
|
||||
let imgsize=imgsize+1 # add 1 to compensate for decimal part
|
||||
volsizetmp=${volsize%G}
|
||||
if [ $volsizetmp -lt $imgsize ]
|
||||
then
|
||||
volsize=${imgsize}G
|
||||
fi
|
||||
fi
|
||||
|
||||
tgtvol=${tmpltfs}/vmi-root-${tmpltname}
|
||||
tgtdisk=/dev/zvol/dsk/${tgtvol}
|
||||
|
||||
create_vol_from_file $tmpltfs $tmpltimg2 $tgtvol $tgtdisk $volsize $cleanup
|
||||
|
||||
tmpltswap=$(ls -lh /$tmpltfs | grep swap)
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
swapsize=$(echo $tmpltswap | awk '{print $5}')
|
||||
tmpltswap=$(echo $tmpltswap | awk '{print $NF}')
|
||||
tmpltswap=/${tmpltfs}/${tmpltswap}
|
||||
tgtvol=${tmpltfs}/vmi-swap-${tmpltname}
|
||||
tgtdisk=/dev/zvol/dsk/${tgtvol}
|
||||
create_vol_from_file $tmpltfs $tmpltswap $tgtvol $tgtdisk $swapsize $cleanup
|
||||
fi
|
||||
|
||||
|
||||
if [ "$hvm" != "true" ]
|
||||
then
|
||||
vmlinuz=$(ls /$tmpltfs/vmlinuz*)
|
||||
if [ "$vmlinuz" == "" ]
|
||||
then
|
||||
touch /$tmpltfs/pygrub
|
||||
fi
|
||||
fi
|
||||
|
||||
rollback_if_needed $tmpltfs $? "Failed to create pygrub file"
|
||||
|
||||
touch /$tmpltfs/template.properties
|
||||
rollback_if_needed $tmpltfs $? "Failed to create template.properties file"
|
||||
echo -n "" > /$tmpltfs/template.properties
|
||||
|
||||
today=$(date '+%m_%d_%Y')
|
||||
echo "snapshot.name=$today" > /$tmpltfs/template.properties
|
||||
echo "description=$descr" >> /$tmpltfs/template.properties
|
||||
echo "name=$tmpltname" >> /$tmpltfs/template.properties
|
||||
echo "checksum=$cksum" >> /$tmpltfs/template.properties
|
||||
echo "hvm=$hvm" >> /$tmpltfs/template.properties
|
||||
echo "volume.size=$volsize" >> /$tmpltfs/template.properties
|
||||
|
||||
zfs snapshot -r $tmpltfs@$today
|
||||
rollback_if_needed $tmpltfs $? "Failed to snapshot filesystem"
|
||||
|
||||
if [ "$cleanup" == "true" ]
|
||||
then
|
||||
rm -f $tmpltimg
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,268 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: createvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/createvm.sh $
|
||||
# createvm.sh -- create a vm image directory by cloning (iscsi mode)
|
||||
# OpenSolaris
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -t <template-fs> -d <disk-fs> -i <instance-fs> -u <user fs>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
logzfs() {
|
||||
if [ -z "$debug" ]
|
||||
then
|
||||
return
|
||||
fi
|
||||
local elapsed=0
|
||||
printf "$(date +'%H:%M:%S') $*\n" >&3
|
||||
if [ "$(echo $1| awk '{print $1}')" == "start:" ]
|
||||
then
|
||||
start="$(/usr/gnu/bin/date +'%s')"
|
||||
return
|
||||
fi
|
||||
if [ "$(echo $1| awk '{print $1}')" == "end:" ]
|
||||
then
|
||||
end="$(/usr/gnu/bin/date +'%s')"
|
||||
let elapsed=end-start
|
||||
printf "t=$elapsed $*\n" >&3
|
||||
fi
|
||||
}
|
||||
|
||||
#ensure that the instance fs is mounted within the user fs
|
||||
check_valid_userfs() {
|
||||
local ifs=$1
|
||||
local ufs=$2
|
||||
local child=${ifs#$ufs}
|
||||
if [ ${#child} -eq $(( ${#ifs}-${#ufs} )) ]
|
||||
then
|
||||
return 0
|
||||
else
|
||||
printf "instance fs $ifs is not contained within user fs $ufs. Bailing\n" >&2
|
||||
exit 3;
|
||||
fi
|
||||
}
|
||||
|
||||
get_instance() {
|
||||
echo $(basename $1)
|
||||
}
|
||||
|
||||
get_latest_snapshot() {
|
||||
local fs=$1
|
||||
local tsnap=$(echo $fs | cut -f1 -d'@')
|
||||
if [ "$tsnap" == "$fs" ]
|
||||
then
|
||||
snap=$(zfs list -r -H -o name -S name -S creation -t snapshot $tsnap| head -1)
|
||||
if [ -z $snap ]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
echo $snap
|
||||
return 0
|
||||
else
|
||||
echo $fs
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
#trap 'echo "killed..." >&3; exec 3>&-; exit 9' TERM INT KILL
|
||||
#set -x
|
||||
|
||||
tflag=
|
||||
iflag=
|
||||
uflag=
|
||||
dflag=
|
||||
sflag=
|
||||
start=
|
||||
end=
|
||||
#debug=1
|
||||
|
||||
while getopts 't:i:u:d:s:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
t) tflag=1
|
||||
templatefs="$OPTARG"
|
||||
;;
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
userfs="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
diskfs="$OPTARG"
|
||||
;;
|
||||
s) sflag=1
|
||||
diskfs=""
|
||||
disksize="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$tflag$iflag$uflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#either -d or -s but not both
|
||||
if [ "$dflag$sflag" == "11" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#if user has provided leading slash, strip it out
|
||||
if [ ${userfs:0:1} == / ]
|
||||
then
|
||||
userfs=${userfs:1}
|
||||
fi
|
||||
|
||||
if [ ${templatefs:0:1} == / ]
|
||||
then
|
||||
templatefs=${templatefs:1}
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
if [ -n "$diskfs" ]
|
||||
then
|
||||
if [ ${diskfs:0:1} == / ]
|
||||
then
|
||||
diskfs=${diskfs:1}
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$disksize" ]
|
||||
then
|
||||
suffix=${disksize:(-1)}
|
||||
echo $suffix
|
||||
case $suffix in
|
||||
G)
|
||||
;;
|
||||
[0-9]) disksize=${disksize}G
|
||||
;;
|
||||
*) printf "Error in disk size: expect G as a suffix or no suffix\n"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
fi
|
||||
|
||||
instance=$(get_instance $instancefs)
|
||||
if [ -n "$debug" ]
|
||||
then
|
||||
exec 3<>$(dirname $0)/../../../logs/create$instance.log
|
||||
fi
|
||||
|
||||
check_valid_userfs $instancefs $userfs
|
||||
|
||||
|
||||
#if user has provided the exact snapshot of the template fs, use it,
|
||||
#else get the latest snapshot
|
||||
tsnap=$(echo $templatefs | cut -f1 -d'@')
|
||||
if [ "$tsnap" == "$templatefs" ]
|
||||
then
|
||||
logzfs "start: get_latest_snapshot"
|
||||
tsnap=$(get_latest_snapshot $templatefs)
|
||||
logzfs "end: get_latest_snapshot"
|
||||
if [ -z "$tsnap" ]
|
||||
then
|
||||
printf "No snapshots exist of filesystem $templatefs..bailing\n" >&2
|
||||
exit 4
|
||||
fi
|
||||
else
|
||||
tsnap=$templatefs
|
||||
templatefs=$(echo $templatefs | cut -f1 -d'@') #strip out snap version
|
||||
fi
|
||||
|
||||
snapt=$(echo $tsnap | cut -f2 -d'@')
|
||||
|
||||
if [ -n "$diskfs" ]
|
||||
then
|
||||
logzfs "start: get_latest_snapshot"
|
||||
disksnap=$(get_latest_snapshot $diskfs)
|
||||
logzfs "end: get_latest_snapshot"
|
||||
if [ -z "$disksnap" ]
|
||||
then
|
||||
printf "No snapshots exist of disk filesystem $diskfs..bailing\n" >&2
|
||||
exit 6
|
||||
fi
|
||||
diskfs=$(echo $diskfs | cut -d'@' -f1)
|
||||
fi
|
||||
|
||||
#Clone root disk and associated files
|
||||
printf "Cloning root disk $tsnap to $instancefs\n" >&2
|
||||
logzfs "start: zfs clone -p $tsnap $instancefs"
|
||||
zfs clone -p $tsnap $instancefs
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to clone root disk $tsnap\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
logzfs "end: zfs clone -p $tsnap $instancefs"
|
||||
|
||||
#get root disk/swapdisk volume contained within templatefs
|
||||
logzfs "start: zfs list -H -o name -t volume -r $templatefs"
|
||||
for vol in $(zfs list -H -o name -t volume -r $templatefs )
|
||||
do
|
||||
#clone the snapshot
|
||||
logzfs "start: zfs clone $vol@$snapt $instancefs/$(basename $vol)"
|
||||
zfs clone $vol@$snapt $instancefs/$(basename $vol)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to clone root disk $vol$snapt\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
sbdadm create-lu /dev/zvol/dsk/$instancefs/$(basename $vol)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to create the lun for /dev/zvol/dsk/$instancefs/$(basename $vol)\n" >&2
|
||||
exit 10
|
||||
fi
|
||||
logzfs "end: zfs clone $vol@$snapt $instancefs/$(basename $vol)"
|
||||
done
|
||||
|
||||
rc=0
|
||||
#Clone datadisk
|
||||
if [ -n "$diskfs" ]
|
||||
then
|
||||
logzfs "start: zfs clone $disksnap $instancefs/datadisk1-$(basename $diskfs)"
|
||||
zfs clone $disksnap $instancefs/datadisk1-$(basename $diskfs)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to clone data disk $disksnap\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
sbdadm create-lu /dev/zvol/dsk/$instancefs/datadisk1-$(basename $diskfs)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to create the lun for /dev/zvol/dsk/$instancefs/datadisk1-$(basename $diskfs)\n" >&2
|
||||
exit 10
|
||||
fi
|
||||
logzfs "end: zfs clone $disksnap $instancefs/datadisk1-$(basename $diskfs)"
|
||||
fi
|
||||
|
||||
if [ -n "$disksize" ]
|
||||
then
|
||||
logzfs "start: zfs create $instancefs/datadisk1"
|
||||
zfs create -V $disksize -s $instancefs/datadisk1 #-s for sparse
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to create data disk $instancefs/datadisk1\n" >&2
|
||||
exit 6
|
||||
fi
|
||||
sbdadm create-lu /dev/zvol/dsk/$instancefs/datadisk1
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to create the lun for /dev/zvol/dsk/$instancefs/datadisk1\n" >&2
|
||||
exit 10
|
||||
fi
|
||||
logzfs "end: zfs create $instancefs/datadisk1"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,203 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: delvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/delvm.sh $
|
||||
# delvm.sh -- delete a cloned image used for a vm
|
||||
# OpenSolaris
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -i <instance-fs> -l <lun,lun,lun> | -u <user fs>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
delete_lu() { # <instance-or-user-fs>
|
||||
local lu=$1
|
||||
local result=
|
||||
result=$(sbdadm delete-lu $lu 2>&1)
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
if [ $? -ne 1 ]
|
||||
then
|
||||
printf "Unable to delete lun: $result\n" >&2
|
||||
return 4
|
||||
fi
|
||||
echo $result | grep "not found"
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "Unable to delete lun: $result\n" >&2
|
||||
return 5
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
delete_all_lu() {
|
||||
local lu_list=$(sbdadm list-lu | grep $1 | awk '{print $1}')
|
||||
local lu
|
||||
for lu in $lu_list
|
||||
do
|
||||
delete_lu $lu
|
||||
done
|
||||
}
|
||||
|
||||
#set -x
|
||||
logzfs() {
|
||||
if [ -z "$debug" ]
|
||||
then
|
||||
return
|
||||
fi
|
||||
local elapsed=0
|
||||
printf "$(date +'%H:%M:%S') $*\n" >&3
|
||||
if [ "$(echo $1| awk '{print $1}')" == "start:" ]
|
||||
then
|
||||
start="$(/usr/gnu/bin/date +'%s')"
|
||||
return
|
||||
fi
|
||||
if [ "$(echo $1| awk '{print $1}')" == "end:" ]
|
||||
then
|
||||
end="$(/usr/gnu/bin/date +'%s')"
|
||||
let elapsed=end-start
|
||||
printf "t=$elapsed $*\n" >&3
|
||||
fi
|
||||
}
|
||||
get_instance() {
|
||||
echo $(basename $1)
|
||||
}
|
||||
|
||||
iflag=
|
||||
uflag=
|
||||
lflag=
|
||||
userfs=
|
||||
instancefs=
|
||||
start=
|
||||
end=
|
||||
tgtname=
|
||||
#debug=1
|
||||
|
||||
while getopts 'i:u:l:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
userfs="$OPTARG"
|
||||
;;
|
||||
l) lflag=1
|
||||
tgtname="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$iflag$uflag" != "1" -a "$iflag$uflag" != "11" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ -n $instancefs && ${instancefs:0:1} == / ]]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
if [[ -n $userfs && ${userfs:0:1} == / ]]
|
||||
then
|
||||
userfs=${userfs:1}
|
||||
fi
|
||||
|
||||
if [ "$iflag" == "1" ]
|
||||
then
|
||||
result=$(zfs get -H -o value -p type $instancefs 2>&1)
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
if [ $result != filesystem ]
|
||||
then
|
||||
printf "Supplied instance fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo $result | grep "dataset does not exist"
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
exit 0
|
||||
else
|
||||
printf "Unable to get information on $instancefs due to $result\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$uflag" == 1 && $(zfs get -H -o value -p type $userfs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied user fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
instance=$(get_instance $instancefs)
|
||||
if [ -n "$debug" ]
|
||||
then
|
||||
exec 3<>$(dirname $0)/../../../logs/del$instance.log
|
||||
fi
|
||||
|
||||
if [ "$iflag" == 1 ]
|
||||
then
|
||||
printf "Going to destroy $instancefs and its children\n"
|
||||
logzfs "start: zfs destroy -r -f $instancefs "
|
||||
if [ "$lflag" == 1 ]
|
||||
then
|
||||
for l in `echo $tgtname | tr ',' ' '`
|
||||
do
|
||||
lu=`echo $l | cut -d':' -f5`
|
||||
delete_lu $lu
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
exit $?
|
||||
fi
|
||||
done
|
||||
else
|
||||
delete_all_lu $instancefs
|
||||
fi
|
||||
|
||||
result=$(zfs destroy -r -f $instancefs 2>&1)
|
||||
rc=$?
|
||||
logzfs "end: zfs destroy -r -f $instancefs "
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
echo $result | grep "dataset does not exist"
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
sleep 10
|
||||
printf "Trying again to destroy instance fs $instancefs \n" >&2
|
||||
result=$(zfs destroy -r -f $instancefs 2>&1)
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "Failed to destroy instance fs $instancefs, numchildren=$numc, result=$result\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$uflag" == 1 ]
|
||||
then
|
||||
printf "Going to destroy $userfs and its children\n"
|
||||
logzfs "start: zfs destroy -r -f $userfs"
|
||||
delete_all_lu $userfs
|
||||
zfs destroy -r -f $userfs
|
||||
rc=$?
|
||||
logzfs "end: zfs destroy -r -f $userfs"
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
numc=$(zfs list -Hr $userfs 2> /dev/null| wc -l)
|
||||
if [ "$numc" -eq 1 ]
|
||||
then
|
||||
printf "Trying again to destroy user fs $userfs \n" >&2
|
||||
zfs destroy -r -f $userfs
|
||||
else
|
||||
printf "Failed to destroy user fs $userfs, numchildren=$numc\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,247 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: createtmplt.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/filebacked/createtmplt.sh $
|
||||
# createtmplt.sh -- install a template
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -t <template-fs> -n <templatename> -f <root disk file> -s <size in Gigabytes> -c <md5 cksum> -d <descr> -h [-u]\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#set -x
|
||||
|
||||
rollback_if_needed() {
|
||||
if [ $2 -gt 0 ]
|
||||
then
|
||||
printf "$3\n"
|
||||
#back out all changes
|
||||
zfs destroy -r $1
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
verify_cksum() {
|
||||
echo "$1 $2" | md5sum -c --status
|
||||
#printf "$1\t$2" | md5sum -c --status
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Checksum failed, not proceeding with install\n"
|
||||
exit 3
|
||||
fi
|
||||
}
|
||||
|
||||
untar() {
|
||||
local ft=$(file $1| awk -F" " '{print $2}')
|
||||
local basedir=$(dirname $1)
|
||||
case $ft in
|
||||
USTAR) local rootimg=$(tar tf $1 | grep $3)
|
||||
(cd $2; tar xf $1)
|
||||
rm -f $1
|
||||
printf "$2/$rootimg"
|
||||
;;
|
||||
*) printf "$1"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
uncompress() {
|
||||
local ft=$(file $1| awk -F" " '{print $2}')
|
||||
local imgfile=${1%.*} #strip out trailing file suffix
|
||||
local tmpfile=${imgfile}.tmp
|
||||
|
||||
case $ft in
|
||||
gzip) gunzip -c $1 > $tmpfile
|
||||
;;
|
||||
bzip2) bunzip2 -c $1 > $tmpfile
|
||||
;;
|
||||
ZIP) unzip -p $1 | cat > $tmpfile
|
||||
;;
|
||||
*) printf "$1"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to uncompress file, exiting "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mv $tmpfile $imgfile
|
||||
printf "$imgfile"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
create_from_file() {
|
||||
local tmpltfs=$1
|
||||
local tmpltimg=$2
|
||||
local tgtfile=$3
|
||||
local volsize=$4
|
||||
local cleanup=$5
|
||||
|
||||
#copy 64k of zeros for LUN metatdata
|
||||
dd if=/dev/zero of=/$tgtfile bs=64k count=1
|
||||
|
||||
#copy the file to the disk
|
||||
dd if=$tmpltimg of=/$tgtfile bs=64k seek=1
|
||||
|
||||
rollback_if_needed $tmpltfs $? "Failed to copy root disk"
|
||||
|
||||
if [ "$cleanup" == "true" ]
|
||||
then
|
||||
rm -f $tmpltimg
|
||||
fi
|
||||
}
|
||||
|
||||
tflag=
|
||||
nflag=
|
||||
fflag=
|
||||
sflag=
|
||||
hflag=
|
||||
hvm=false
|
||||
cleanup=false
|
||||
dflag=
|
||||
cflag=
|
||||
|
||||
while getopts 'uht:n:f:s:c:d:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
t) tflag=1
|
||||
tmpltfs="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
tmpltname="$OPTARG"
|
||||
;;
|
||||
f) fflag=1
|
||||
tmpltimg="$OPTARG"
|
||||
;;
|
||||
s) sflag=1
|
||||
volsize="$OPTARG"
|
||||
;;
|
||||
c) cflag=1
|
||||
cksum="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
descr="$OPTARG"
|
||||
;;
|
||||
h) hflag=1
|
||||
hvm="true"
|
||||
;;
|
||||
u) cleanup="true"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$tflag$nflag$fflag$sflag" != "1111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ -n "$cksum" ]
|
||||
then
|
||||
verify_cksum $cksum $tmpltimg
|
||||
fi
|
||||
|
||||
if [ ${tmpltfs:0:1} == / ]
|
||||
then
|
||||
tmpltfs=${tmpltfs:1}
|
||||
fi
|
||||
|
||||
if [ ! -d /$tmpltfs ]
|
||||
then
|
||||
zfs create $tmpltfs
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to create user fs $tmpltfs\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $tmpltfs) != filesystem ]]
|
||||
then
|
||||
printf "template fs doesn't exist\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
tmpltimg2=$(uncompress $tmpltimg)
|
||||
tmpltimg2=$(untar $tmpltimg2 /$tmpltfs vmi-root)
|
||||
|
||||
if [ ! -f $tmpltimg2 ]
|
||||
then
|
||||
rollback_if_needed $tmpltfs 2 "root disk file $tmpltimg doesn't exist\n"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# need the 'G' suffix on volume size
|
||||
if [ ${volsize:(-1)} != G ]
|
||||
then
|
||||
volsize=${volsize}G
|
||||
fi
|
||||
|
||||
#determine source file size -- it needs to be less than or equal to volsize
|
||||
imgsize=$(ls -lh $tmpltimg2| awk -F" " '{print $5}')
|
||||
if [ ${imgsize:(-1)} == G ]
|
||||
then
|
||||
imgsize=${imgsize%G} #strip out the G
|
||||
imgsize=${imgsize%.*} #...and any decimal part
|
||||
let imgsize=imgsize+1 # add 1 to compensate for decimal part
|
||||
volsizetmp=${volsize%G}
|
||||
if [ $volsizetmp -lt $imgsize ]
|
||||
then
|
||||
volsize=${imgsize}G
|
||||
fi
|
||||
fi
|
||||
|
||||
tgtfile=${tmpltfs}/vmi-root-${tmpltname}
|
||||
|
||||
create_from_file $tmpltfs $tmpltimg2 $tgtfile $volsize $cleanup
|
||||
|
||||
tmpltswap=$(ls -lh /$tmpltfs | grep swap)
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
swapsize=$(echo $tmpltswap | awk '{print $5}')
|
||||
tmpltswap=$(echo $tmpltswap | awk '{print $NF}')
|
||||
tmpltswap=/${tmpltfs}/${tmpltswap}
|
||||
tgtfile=${tmpltfs}/vmi-swap-${tmpltname}
|
||||
create_from_file $tmpltfs $tmpltswap $tgtfile $swapsize $cleanup
|
||||
fi
|
||||
|
||||
|
||||
if [ "$hvm" != "true" ]
|
||||
then
|
||||
vmlinuz=$(ls /$tmpltfs/vmlinuz*)
|
||||
if [ "$vmlinuz" == "" ]
|
||||
then
|
||||
touch /$tmpltfs/pygrub
|
||||
fi
|
||||
fi
|
||||
|
||||
rollback_if_needed $tmpltfs $? "Failed to create pygrub file"
|
||||
|
||||
touch /$tmpltfs/template.properties
|
||||
rollback_if_needed $tmpltfs $? "Failed to create template.properties file"
|
||||
echo -n "" > /$tmpltfs/template.properties
|
||||
|
||||
today=$(date '+%m_%d_%Y')
|
||||
echo "snapshot.name=$today" > /$tmpltfs/template.properties
|
||||
echo "description=$descr" >> /$tmpltfs/template.properties
|
||||
echo "name=$tmpltname" >> /$tmpltfs/template.properties
|
||||
echo "checksum=$cksum" >> /$tmpltfs/template.properties
|
||||
echo "hvm=$hvm" >> /$tmpltfs/template.properties
|
||||
echo "volume.size=$volsize" >> /$tmpltfs/template.properties
|
||||
|
||||
zfs snapshot -r $tmpltfs@vmops_ss
|
||||
rollback_if_needed $tmpltfs $? "Failed to snapshot filesystem"
|
||||
|
||||
if [ "$cleanup" == "true" ]
|
||||
then
|
||||
rm -f $tmpltimg
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,253 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: createvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/filebacked/createvm.sh $
|
||||
# createvm.sh -- create a vm image directory by cloning (iscsi mode)
|
||||
# OpenSolaris
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -t <template-fs> -d <disk-fs> -i <instance-fs> -u <user fs>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
logzfs() {
|
||||
if [ -z "$debug" ]
|
||||
then
|
||||
return
|
||||
fi
|
||||
local elapsed=0
|
||||
printf "$(date +'%H:%M:%S') $*\n" >&3
|
||||
if [ "$(echo $1| awk '{print $1}')" == "start:" ]
|
||||
then
|
||||
start="$(/usr/gnu/bin/date +'%s')"
|
||||
return
|
||||
fi
|
||||
if [ "$(echo $1| awk '{print $1}')" == "end:" ]
|
||||
then
|
||||
end="$(/usr/gnu/bin/date +'%s')"
|
||||
let elapsed=end-start
|
||||
printf "t=$elapsed $*\n" >&3
|
||||
fi
|
||||
}
|
||||
|
||||
#ensure that the instance fs is mounted within the user fs
|
||||
check_valid_userfs() {
|
||||
local ifs=$1
|
||||
local ufs=$2
|
||||
local child=${ifs#$ufs}
|
||||
if [ ${#child} -eq $(( ${#ifs}-${#ufs} )) ]
|
||||
then
|
||||
return 0
|
||||
else
|
||||
printf "instance fs $ifs is not contained within user fs $ufs. Bailing\n" >&2
|
||||
exit 3;
|
||||
fi
|
||||
}
|
||||
|
||||
get_instance() {
|
||||
echo $(basename $1)
|
||||
}
|
||||
|
||||
get_latest_snapshot() {
|
||||
local fs=$1
|
||||
local tsnap=$(echo $fs | cut -f1 -d'@')
|
||||
if [ "$tsnap" == "$fs" ]
|
||||
then
|
||||
snap=$(zfs list -r -H -o name -S creation -t snapshot $tsnap | egrep "@([0-9][0-9]_[0-9][0-9]_[0-9][0-9][0-9][0-9]|vmops_ss)$" | head -1)
|
||||
if [ -z $snap ]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
echo $snap
|
||||
return 0
|
||||
else
|
||||
echo $fs
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
#trap 'echo "killed..." >&3; exec 3>&-; exit 9' TERM INT KILL
|
||||
# set -x
|
||||
|
||||
kflag=
|
||||
tflag=
|
||||
iflag=
|
||||
uflag=
|
||||
dflag=
|
||||
sflag=
|
||||
start=
|
||||
end=
|
||||
#debug=1
|
||||
|
||||
while getopts 't:i:u:s:k' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
k) kflag=1
|
||||
;;
|
||||
t) tflag=1
|
||||
templatefs="$OPTARG"
|
||||
;;
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
userfs="$OPTARG"
|
||||
;;
|
||||
s) sflag=1
|
||||
disksize="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$tflag$iflag$uflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#either -d or -s but not both
|
||||
if [ "$dflag$sflag" == "11" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#if user has provided leading slash, strip it out
|
||||
if [ ${userfs:0:1} == / ]
|
||||
then
|
||||
userfs=${userfs:1}
|
||||
fi
|
||||
|
||||
if [ ${templatefs:0:1} == / ]
|
||||
then
|
||||
templatefs=${templatefs:1}
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [ -n "$disksize" ]
|
||||
then
|
||||
suffix=${disksize:(-1)}
|
||||
echo $suffix
|
||||
case $suffix in
|
||||
G)
|
||||
;;
|
||||
[0-9]) disksize=${disksize}G
|
||||
;;
|
||||
*) printf "Error in disk size: expect G as a suffix or no suffix\n"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
fi
|
||||
|
||||
instance=$(get_instance $instancefs)
|
||||
if [ -n "$debug" ]
|
||||
then
|
||||
exec 3<>$(dirname $0)/../../../logs/create$instance.log
|
||||
fi
|
||||
|
||||
check_valid_userfs $instancefs $userfs
|
||||
|
||||
|
||||
#if user has provided the exact snapshot of the template fs, use it,
|
||||
#else get the latest snapshot
|
||||
tsnap=$(echo $templatefs | cut -f1 -d'@')
|
||||
if [ "$tsnap" == "$templatefs" ]
|
||||
then
|
||||
logzfs "start: get_latest_snapshot"
|
||||
tsnap=$(get_latest_snapshot $templatefs)
|
||||
logzfs "end: get_latest_snapshot"
|
||||
if [ -z "$tsnap" ]
|
||||
then
|
||||
printf "No snapshots exist of filesystem $templatefs..bailing\n" >&2
|
||||
exit 4
|
||||
fi
|
||||
else
|
||||
tsnap=$templatefs
|
||||
templatefs=$(echo $templatefs | cut -f1 -d'@') #strip out snap version
|
||||
fi
|
||||
|
||||
snapt=$(echo $tsnap | cut -f2 -d'@')
|
||||
|
||||
|
||||
if [ "$kflag" == "1" ]; then
|
||||
# clone the data disk as well -- the tsnap variable and instancefs variables are not set up properly by this time
|
||||
printf "Cloning private template $tsnap to $instancefs\n" >&2
|
||||
logzfs "start: zfs clone -p $tsnap $instancefs"
|
||||
zfs clone -p $tsnap $instancefs
|
||||
zfs clone -p $templatefs/rootdisk@$snapt $instancefs/rootdisk
|
||||
zfs clone -p $templatefs/datadisk1@$snapt $instancefs/datadisk1
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to clone template $tsnap\n" >&2
|
||||
exit 9
|
||||
fi
|
||||
rootdisk=$(ls /$instancefs/rootdisk/vmi-root*)
|
||||
sbdadm create-lu $rootdisk
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "Failed to create the lun\n" >&2
|
||||
exit 10;
|
||||
fi
|
||||
|
||||
datadisk=$(ls /$instancefs/datadisk1/data*)
|
||||
sbdadm create-lu -s $disksize $datadisk
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "Failed to create the lun\n" >&2
|
||||
exit 10;
|
||||
fi
|
||||
|
||||
logzfs "end: zfs clone -p $tsnap $instancefs"
|
||||
else
|
||||
|
||||
#Clone root disk and associated files
|
||||
printf "Cloning root disk $tsnap to $instancefs\n" >&2
|
||||
logzfs "start: zfs clone -p $tsnap $instancefs"
|
||||
zfs clone -p $tsnap $instancefs/rootdisk
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to clone root disk $tsnap\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
rootdisk=$(ls /$instancefs/rootdisk/vmi-root*)
|
||||
sbdadm create-lu $rootdisk
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "Failed to create the lun\n" >&2
|
||||
exit 10;
|
||||
fi
|
||||
|
||||
logzfs "end: zfs clone -p $tsnap $instancefs"
|
||||
|
||||
rc=0
|
||||
if [ -n "$disksize" ]
|
||||
then
|
||||
logzfs "start: zfs create $instancefs/datadisk1"
|
||||
zfs create $instancefs/datadisk1
|
||||
rc=$?
|
||||
touch /$instancefs/datadisk1/datadisk1
|
||||
if [ $rc -eq 0 ]
|
||||
then
|
||||
sbdadm create-lu -s $disksize /$instancefs/datadisk1/datadisk1
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "Failed to create the lun\n" >&2
|
||||
exit 10;
|
||||
fi
|
||||
fi
|
||||
logzfs "end: zfs create $instancefs/datadisk1"
|
||||
fi
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to create data disk $instancefs/datadisk1/datadisk1\n" >&2
|
||||
exit 6
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,35 +0,0 @@
|
||||
#
|
||||
# $Id: functions.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/filebacked/functions.sh $
|
||||
# functions.sh - OpenSolaris utility functions
|
||||
#
|
||||
|
||||
list_views() {
|
||||
for lu in $(sbdadm list-lu | awk '{print $1}')
|
||||
do
|
||||
if stmfadm list-view -l $lu >/dev/null 2>/dev/null
|
||||
then
|
||||
echo $lu
|
||||
stmfadm list-view -l $lu
|
||||
else
|
||||
echo $lu "no_view"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
list_zvol() { # <zvol-path>
|
||||
for lu in $(sbdadm list-lu | grep zvol | awk '{print $1}')
|
||||
do
|
||||
if stmfadm list-lu -v $lu | grep $1 >/dev/null
|
||||
then
|
||||
echo "lu = $lu"
|
||||
stmfadm list-view -l $lu
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# takes about 3 seconds per volume
|
||||
destroy_zvol () { # <zvol-path>
|
||||
local luname=$(sbdadm list-lu | grep $1 | awk '{print $1}');
|
||||
sbdadm delete-lu $luname;
|
||||
zfs destroy $1
|
||||
}
|
||||
@ -1,114 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: listvmdisk.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/filebacked/listvmdisk.sh $
|
||||
# listvmdisk.sh -- list disks of a VM (iscsi mode)
|
||||
# OpenSolaris
|
||||
# Bugs: does not handle hexadecimal numbers. Decimal only!
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -i <instance-fs> [-r | -w | -d <num> ] \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
hosted() {
|
||||
uname -a | grep "101b" > /dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
path_and_iqn() {
|
||||
local ifs=$1
|
||||
local pattern=$2
|
||||
|
||||
local diskfs=$(zfs list -r -H -o name $ifs | grep $pattern)
|
||||
if [ "$diskfs" != "" ]
|
||||
then
|
||||
local luname=$(sbdadm list-lu | grep $diskfs | awk '{print $1}')
|
||||
local tgtname=$(itadm list-target | tail -1 | awk '{print $1}')
|
||||
if [ "$tgtname" != "" -a "$luname" != "" ]
|
||||
then
|
||||
tgtname=$tgtname:lu:$luname
|
||||
else
|
||||
tgtname=""
|
||||
fi
|
||||
fi
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
return 6
|
||||
fi
|
||||
if [ "$diskfs" != "" -a "$tgtname" != "" ]
|
||||
then
|
||||
printf "$diskfs,$tgtname\n"
|
||||
return 0
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
iflag=
|
||||
rflag=
|
||||
dflag=
|
||||
wflag=
|
||||
disknum=
|
||||
instancefs=
|
||||
|
||||
while getopts 'i:d:rw' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
disknum="$OPTARG"
|
||||
;;
|
||||
r) rflag=1
|
||||
;;
|
||||
w) wflag=1
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$iflag" != "1" -a "$rflag$dflag$wflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $instancefs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied instance fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ "$rflag" == 1 ]
|
||||
then
|
||||
path_and_iqn $instancefs "root"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
if [ "$wflag" == 1 ]
|
||||
then
|
||||
path_and_iqn $instancefs "swap"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
if [ "$dflag" == 1 ]
|
||||
then
|
||||
if [[ $disknum -eq 0 ]]
|
||||
then
|
||||
path_and_iqn $instancefs "root"
|
||||
else
|
||||
path_and_iqn $instancefs "datadisk"$disknum
|
||||
fi
|
||||
|
||||
exit $?
|
||||
fi
|
||||
exit 0
|
||||
@ -1,111 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: listvmdisksize.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/filebacked/listvmdisksize.sh $
|
||||
# listvmdisksize.sh -- list disk sizes of a VM (iscsi mode)
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -d <disk-fs> [-t | -a ] \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#####################################################################
|
||||
# Evaluate a floating point number expression.
|
||||
function float_eval()
|
||||
{
|
||||
local stat=0
|
||||
local result=0.0
|
||||
if [[ $# -gt 0 ]]; then
|
||||
result=$(echo "scale=0; $*" | bc 2>/dev/null)
|
||||
stat=$?
|
||||
if [[ $stat -eq 0 && -z "$result" ]]; then stat=1; fi
|
||||
fi
|
||||
echo $result
|
||||
return $stat
|
||||
}
|
||||
|
||||
kmg_to_number()
|
||||
{
|
||||
local s=$1;
|
||||
local size=${s:0:$((${#s}-1))}
|
||||
local result=$1;
|
||||
local suffix=${s:(-1)}
|
||||
case $suffix in
|
||||
G) result=$(float_eval "$size*1024*1024*1024")
|
||||
;;
|
||||
M) result=$(float_eval "$size*1024*1024")
|
||||
;;
|
||||
K) result=$(float_eval "$size*1024")
|
||||
;;
|
||||
esac
|
||||
|
||||
result=$(echo $result | cut -d"." -f1) #strip out decimal precision
|
||||
echo $result
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
aflag=
|
||||
tflag=
|
||||
aflag=
|
||||
diskfs=
|
||||
|
||||
while getopts 'd:ta' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
d) dflag=1
|
||||
diskfs="$OPTARG"
|
||||
;;
|
||||
t) tflag=1
|
||||
;;
|
||||
a) aflag=1
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$dflag" != "1" -a "$tflag$aflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${diskfs:0:1} == / ]
|
||||
then
|
||||
diskfs=${diskfs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $diskfs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied disk doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ "$aflag" == 1 ]
|
||||
then
|
||||
used=$(zfs list -H -o used $diskfs)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 5
|
||||
fi
|
||||
result=$(kmg_to_number $used)
|
||||
printf "$result\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$tflag" == 1 ]
|
||||
then
|
||||
#total=$(zfs list -H -o refer $diskfs)
|
||||
total=$(sbdadm list-lu | grep $diskfs | awk '{print $2}')
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 5
|
||||
fi
|
||||
printf "$total\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
# $Id: migratetmplts.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/filebacked/migratetmplts.sh $
|
||||
# set -x
|
||||
for dir in $(find /tank/vmops -name template)
|
||||
do
|
||||
dir=${dir:1} #strip out leading slash
|
||||
for tmplt in $(zfs list -H -t volume -o name -r $dir );
|
||||
do
|
||||
dd if=/dev/zvol/dsk/$tmplt of=/$tmplt bs=8096k;
|
||||
today=$(date '+%m_%d_%Y')
|
||||
zfs snapshot -r $(dirname $tmplt)@${today}
|
||||
#zfs destroy -Rf $tmplt
|
||||
echo "Done: $tmplt"
|
||||
done
|
||||
done
|
||||
@ -1,75 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: upgradevmdisk.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/filebacked/upgradevmdisk.sh $
|
||||
# upgradevmdisk.sh -- upgrade size of disks of a VM (iscsi mode)
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -v <instance-fs> -d <size> \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
upgrade_disk() {
|
||||
local ifs=$1
|
||||
local disk_size=$2
|
||||
|
||||
|
||||
local diskfs=$(zfs list -r -H -o name $ifs | grep datadisk1)
|
||||
local datadisk=/${diskfs}/$(ls /$diskfs/)
|
||||
sbdadm modify-lu -s ${disk_size}M ${datadisk}
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
return 7
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
vflag=
|
||||
dflag=
|
||||
disksize=
|
||||
instancefs=
|
||||
|
||||
while getopts 'v:d:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
v) vflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
disksize="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$vflag" != "1" -a "$dflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $instancefs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied instance fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$dflag" == 1 ]
|
||||
then
|
||||
if [[ $disksize -gt 0 ]]
|
||||
then
|
||||
upgrade_disk $instancefs $disksize
|
||||
fi
|
||||
|
||||
exit $?
|
||||
fi
|
||||
exit 0
|
||||
@ -1,35 +0,0 @@
|
||||
#
|
||||
# $Id: functions.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/functions.sh $
|
||||
# functions.sh - OpenSolaris utility functions
|
||||
#
|
||||
|
||||
list_views() {
|
||||
for lu in $(sbdadm list-lu | grep zvol | awk '{print $1}')
|
||||
do
|
||||
if stmfadm list-view -l $lu >/dev/null 2>/dev/null
|
||||
then
|
||||
echo $lu
|
||||
stmfadm list-view -l $lu
|
||||
else
|
||||
echo $lu "no_view"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
list_zvol() { # <zvol-path>
|
||||
for lu in $(sbdadm list-lu | grep zvol | awk '{print $1}')
|
||||
do
|
||||
if stmfadm list-lu -v $lu | grep $1 >/dev/null
|
||||
then
|
||||
echo "lu = $lu"
|
||||
stmfadm list-view -l $lu
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# takes about 3 seconds per volume
|
||||
destroy_zvol () { # <zvol-path>
|
||||
local luname=$(sbdadm list-lu | grep $1 | awk '{print $1}');
|
||||
sbdadm delete-lu $luname;
|
||||
zfs destroy $1
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: host_group_destroy.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/host_group_destroy.sh $
|
||||
# host_group_destroy.sh -- delete all iSCSI host groups
|
||||
#
|
||||
# Usage: host_group_destroy.sh
|
||||
#
|
||||
# Removes all iSCSI host groups that are not in use.
|
||||
#
|
||||
# OpenSolaris
|
||||
|
||||
# Delete iSCSI host groups
|
||||
host_groups=$(stmfadm list-hg | cut -d' ' -f 3)
|
||||
|
||||
for host_group in $host_groups
|
||||
do
|
||||
stmfadm delete-hg $host_group
|
||||
done
|
||||
|
||||
@ -1,109 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: listvmdisk.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/listvmdisk.sh $
|
||||
# listvmdisk.sh -- list disks of a VM (iscsi mode)
|
||||
# OpenSolaris
|
||||
# Bugs: does not handle hexadecimal numbers. Decimal only!
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -i <instance-fs> [-r | -w | -d <num> ] \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
path_and_iqn() {
|
||||
local ifs=$1
|
||||
local pattern=$2
|
||||
|
||||
local diskvol=$(zfs list -r -H -o name -t volume $ifs | grep $pattern)
|
||||
if [ "$diskvol" != "" ]
|
||||
then
|
||||
local luname=$(sbdadm list-lu | grep $diskvol | awk '{print $1}')
|
||||
local tgtname=$(itadm list-target | tail -1 | awk '{print $1}')
|
||||
if [ "$tgtname" != "" -a "$luname" != "" ]
|
||||
then
|
||||
tgtname=$tgtname:lu:$luname
|
||||
else
|
||||
tgtname=""
|
||||
fi
|
||||
fi
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
return 6
|
||||
fi
|
||||
if [ "$diskvol" != "" -a "$tgtname" != "" ]
|
||||
then
|
||||
printf "$diskvol,$tgtname\n"
|
||||
return 0
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
iflag=
|
||||
rflag=
|
||||
dflag=
|
||||
wflag=
|
||||
disknum=
|
||||
instancefs=
|
||||
|
||||
while getopts 'i:d:rw' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
disknum="$OPTARG"
|
||||
;;
|
||||
r) rflag=1
|
||||
;;
|
||||
w) wflag=1
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$iflag" != "1" -a "$rflag$dflag$wflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $instancefs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied instance fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ "$rflag" == 1 ]
|
||||
then
|
||||
path_and_iqn $instancefs "root"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
if [ "$wflag" == 1 ]
|
||||
then
|
||||
path_and_iqn $instancefs "swap"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
if [ "$dflag" == 1 ]
|
||||
then
|
||||
if [[ $disknum -eq 0 ]]
|
||||
then
|
||||
path_and_iqn $instancefs "root"
|
||||
else
|
||||
path_and_iqn $instancefs "datadisk"$disknum
|
||||
fi
|
||||
|
||||
exit $?
|
||||
fi
|
||||
exit 0
|
||||
@ -1,38 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: lu_info.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/lu_info.sh $
|
||||
# lu_info.sh -- provide info on an LU of the form:
|
||||
#
|
||||
# Target: tank/vmops/vm/u000002/r000002/vmi-swap-routing
|
||||
# iSCSI Name: iqn.1986-03.com.sun:02:f8a76fae-6545-4756-9573-dc8154b8c0fa
|
||||
# Connections: 0
|
||||
#
|
||||
# OpenSolaris
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s path \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
hosted() {
|
||||
uname -a | grep "101b" > /dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
if [ $# -ne 1 ]
|
||||
then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if hosted
|
||||
then
|
||||
iscsitadm list target $1
|
||||
else
|
||||
path=$1
|
||||
luname=$(sbdadm list-lu | grep $1 | awk '{print $1}')
|
||||
tgtname=$(itadm list-target | tail -1 | awk '{print $1}')
|
||||
tgtname=$tgtname:lu:$luname
|
||||
conn_count=$(stmfadm list-lu -v $luname | grep View | awk '{print $5}')
|
||||
printf "Target: %s\n" $path
|
||||
printf " iSCSI Name: %s\n" $tgtname
|
||||
printf " Connections: %s\n" $conn_count
|
||||
fi
|
||||
@ -1,295 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: lu_share.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/lu_share.sh $
|
||||
# lu_share.sh -- make a logical unit (LU) available over iSCSI
|
||||
# OpenSolaris
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s -i <initiator-iqn> -t <target-name> [ -u | -m ]\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
valid_target_name() { # <target-name>
|
||||
echo $1 | grep ':lu:' >/dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
target_iqn_from_target_name() { # <target-name>
|
||||
echo $1 | cut -d':' -f1,2,3
|
||||
}
|
||||
|
||||
hg_from_initiator_iqn() { # <initiator-iqn>
|
||||
echo $1
|
||||
return 0
|
||||
}
|
||||
|
||||
lu_name_from_target_name() { # <target-name>
|
||||
echo $1 | cut -d':' -f5
|
||||
}
|
||||
|
||||
view_entry_from_hg_and_lu_name() { # <host-group-name> <lu-name>
|
||||
local hg=$1
|
||||
local lu_name=$2
|
||||
local view=
|
||||
local last_view=
|
||||
local last_hg=
|
||||
for w in $(stmfadm list-view -l $lu_name)
|
||||
do
|
||||
case $w in
|
||||
[0-9]*) last_view=$w
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$w" == "$hg" ]
|
||||
then
|
||||
echo $last_view
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
create_host_group() { # <initiator-iqn>
|
||||
local i_iqn=$1
|
||||
local host_group=
|
||||
local hg=
|
||||
|
||||
local lines=$(stmfadm list-hg -v $i_iqn | grep $i_iqn | wc -l)
|
||||
if [ $lines -eq 2 ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local result=
|
||||
result=$(stmfadm create-hg $i_iqn 2>&1)
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo $result | grep "already exists" > /dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "%s: create-hg %s failed due to %s\n" $(basename $0) $i_iqn $result >&2
|
||||
return 11
|
||||
fi
|
||||
fi
|
||||
|
||||
result=$(stmfadm add-hg-member -g $i_iqn $i_iqn 2>&1)
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo $result | grep "already exists" > /dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "%s: unable to add %s due to %s\n" $(basename $0) $i_iqn $result >&2
|
||||
return 12
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
add_view() { # <hg> <lu_name>
|
||||
local i=1
|
||||
local hg=$1
|
||||
local lu=$2
|
||||
|
||||
while [ $i -lt 500 ]
|
||||
do
|
||||
local lun=$[ ( $RANDOM % 512 ) ]
|
||||
local result=
|
||||
result=$(stmfadm add-view -h $hg -n $lun $lu 2>&1)
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
printf "lun %s for luname %s\n" $lun $lu
|
||||
#stmfadm list-view -l $lu
|
||||
#sbdadm list-lu
|
||||
return 0
|
||||
fi
|
||||
echo $result | grep "view entry exists" > /dev/null
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
echo $result | grep "LUN already in use" > /dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo $result
|
||||
return 1
|
||||
fi
|
||||
let i=i+1
|
||||
done
|
||||
printf "Unable to add view after lots of tries\n" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
add_view_and_hg() { # <initiator_iqn> <lu_name>
|
||||
local i_iqn=$1
|
||||
local lu_name=$2
|
||||
local hg=$(hg_from_initiator_iqn $i_iqn)
|
||||
local result=
|
||||
result=$(add_view $hg $lu_name)
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo $result
|
||||
return 0
|
||||
fi
|
||||
|
||||
# create host group if necessary and try again
|
||||
echo $result | grep "invalid host group" > /dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "Unable to add view due to: $result\n" >&2
|
||||
return 22
|
||||
fi
|
||||
if ! create_host_group $i_iqn
|
||||
then
|
||||
printf "%s: create_host_group failed: %s %s\n" $(basename $0) $i_iqn $lu_name >&2
|
||||
return 22
|
||||
fi
|
||||
result=$(add_view $hg $lu_name)
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo $result
|
||||
return 0
|
||||
fi
|
||||
printf "Unable to create view due to: $result\n" >&2
|
||||
return 24
|
||||
}
|
||||
|
||||
remove_view() { # <initiator-iqn> <lu-name>
|
||||
local i_iqn=$1
|
||||
local lu_name=$2
|
||||
local hg=$(hg_from_initiator_iqn $i_iqn)
|
||||
local view=$(view_entry_from_hg_and_lu_name $hg $lu_name)
|
||||
if [ -n "$hg" -a -n "$view" ]
|
||||
then
|
||||
local result=
|
||||
result=$(stmfadm remove-view -l $lu_name $view 2>&1)
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo $result | grep "not found"
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
echo $result | grep "no views found"
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
printf "Unable to remove view due to: $result\n" >&2
|
||||
return 5
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
remove_view_unknown_init_iqn() { # <lu_name>
|
||||
local view_count=$(stmfadm list-view -l $1 2>/dev/null | grep View | wc -l)
|
||||
local view_number
|
||||
# if no view for LU, then report success
|
||||
if [ $view_count -eq 0 ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
# if no init iqn specified, LU should only have one view
|
||||
# if more than one view, squawk and do nothing
|
||||
if [ "$view_count" == "1" ]
|
||||
then
|
||||
view_number=$(stmfadm list-view -l $1 2>/dev/null | grep View | awk '{print $NF}')
|
||||
stmfadm remove-view -l $1 $view_number
|
||||
else
|
||||
printf "remove_view_unknown_init_iqn: %s views! \n" $view_count >&2
|
||||
fi
|
||||
}
|
||||
|
||||
remove_all_views() { # <lu-name>
|
||||
local lu_name=$1
|
||||
stmfadm remove-view -a -l $lu_name
|
||||
if [ $? -eq 1 ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
if [ $# -lt 4 ]
|
||||
then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
iflag=
|
||||
tflag=
|
||||
uflag=
|
||||
mflag=
|
||||
|
||||
while getopts 'mui:t:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
i) iflag=1
|
||||
init_iqn="$OPTARG"
|
||||
;;
|
||||
m) mflag=1
|
||||
;;
|
||||
t) tflag=1
|
||||
tgtname="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
;;
|
||||
*) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$iflag$tflag" != "11" -o "$mflag$uflag" == "11" ]
|
||||
then
|
||||
usage
|
||||
exit 3
|
||||
fi
|
||||
|
||||
if ! valid_target_name $tgtname
|
||||
then
|
||||
printf "%s: invalid target name format: %s\n" $(basename $0) $tgtname >&2
|
||||
exit 4
|
||||
fi
|
||||
|
||||
lu_name=$(lu_name_from_target_name $tgtname)
|
||||
|
||||
if [ "$uflag" == "1" ]
|
||||
then
|
||||
if [ "$init_iqn" == "unshare_all" ]
|
||||
then
|
||||
if ! remove_all_views $lu_name
|
||||
then
|
||||
printf "%s: remove_all_views failed: %s\n" $(basename $0) $lu_name >&2
|
||||
exit 20
|
||||
fi
|
||||
else
|
||||
if [ "$init_iqn" == "n/a" ]
|
||||
then
|
||||
if ! remove_view_unknown_init_iqn $lu_name
|
||||
then
|
||||
printf "%s: remove_view_unknown_init_iqn failed: %s\n" $(basename $0) $lu_name >&2
|
||||
exit 25
|
||||
fi
|
||||
else
|
||||
if ! remove_view $init_iqn $lu_name
|
||||
then
|
||||
printf "%s: remove_view failed: %s\n" $(basename $0) $lu_name >&2
|
||||
exit 21
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if [ "$mflag" == "1" ]
|
||||
then
|
||||
remove_all_views $lu_name
|
||||
fi
|
||||
# finally add a view of the lu
|
||||
RANDOM=$(perl -e 'print time;')
|
||||
if ! add_view_and_hg $init_iqn $lu_name
|
||||
then
|
||||
printf "%s: add_view failed: %s %s\n" $(basename $0) $host_group $lu_name >&2
|
||||
exit 23
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,79 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: upgradevmdisk.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/upgradevmdisk.sh $
|
||||
# upgradevmdisk.sh -- upgrade size of disks of a VM (iscsi mode)
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -v <instance-fs> -d <size> \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
upgrade_disk() {
|
||||
local ifs=$1
|
||||
local disk_size=$2
|
||||
|
||||
zfs set volsize=${disk_size}M $ifs
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
return 6
|
||||
fi
|
||||
|
||||
sbdadm modify-lu -s ${disk_size}M /dev/zvol/dsk/${ifs}
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
return 7
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
vflag=
|
||||
dflag=
|
||||
disksize=
|
||||
instancefs=
|
||||
|
||||
while getopts 'v:d:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
v) vflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
disksize="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$vflag" != "1" -a "$dflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $instancefs) != volume ]]
|
||||
then
|
||||
printf "Supplied instance fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$dflag" == 1 ]
|
||||
then
|
||||
if [[ $disksize -gt 0 ]]
|
||||
then
|
||||
upgrade_disk $instancefs $disksize
|
||||
fi
|
||||
|
||||
exit $?
|
||||
fi
|
||||
exit 0
|
||||
@ -1,44 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: view_and_lu_remove.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/view_and_lu_remove.sh $
|
||||
# view_and_lu_remove.sh -- remove views and LU's under a ZFS file system tree
|
||||
#
|
||||
# Usage: view_and_lu_remove.sh <zfs-path>
|
||||
#
|
||||
# Removes outstanding views and deletes LU's recursively under a ZFS file
|
||||
# system path.
|
||||
#
|
||||
# OpenSolaris
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: <zfs-path>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
zfspath=$1
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
paths=$(zfs list -Hro name $zfspath)
|
||||
|
||||
if [ -z "$paths" ]
|
||||
then
|
||||
printf "%s: zfs path %s does not exist.\n" $(basename $0) >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
lu_names=$(sbdadm list-lu | grep $zfspath | awk '{print $1}')
|
||||
|
||||
for lu in $lu_names
|
||||
do
|
||||
stmfadm remove-view -a -l $lu 0 2>/dev/null
|
||||
sbdadm delete-lu $lu
|
||||
done
|
||||
|
||||
sleep 2
|
||||
|
||||
exit 0
|
||||
@ -1,48 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: zfs_destroy.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/comstar/zfs_destroy.sh $
|
||||
# zfs_destroy.sh -- delete a cloned image used for a vm
|
||||
#
|
||||
# Usage: zfs_destroy <zfs-path>
|
||||
#
|
||||
# Removes outstanding views, deletes LU's, and then performs a
|
||||
# "zfs destroy -f -r <zfs-path>".
|
||||
#
|
||||
# OpenSolaris
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: <zfs-path>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
get_instance() {
|
||||
echo $(basename $1)
|
||||
}
|
||||
|
||||
zfspath=$1
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
paths=$(zfs list -Hro name $zfspath)
|
||||
|
||||
if [ -z "$paths" ]
|
||||
then
|
||||
printf "%s: zfs path %s does not exist.\n" $(basename $0) >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
lu_names=$(sbdadm list-lu 2>&1 | grep $zfspath | awk '{print $1}')
|
||||
|
||||
for lu in $lu_names
|
||||
do
|
||||
stmfadm remove-view -a -l $lu 0 2>/dev/null
|
||||
sbdadm delete-lu $lu
|
||||
done
|
||||
|
||||
zfs destroy -r -f $zfspath
|
||||
|
||||
exit 0
|
||||
@ -1,107 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: create_private_template.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/create_private_template.sh $
|
||||
# create_private_template.sh -- create a private template from a snapshot
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -p <snapshot path> -n <snapshot name>\n" $(basename $0) >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
create_template() {
|
||||
local fspath=$1
|
||||
local snapshotname=$2
|
||||
local template_path=$3
|
||||
local user_dir=$4
|
||||
local instance_dir=$5
|
||||
local tname=$6
|
||||
|
||||
if [ -d "/$template_path/$user_dir/$instance_dir/$tname" ]; then
|
||||
printf "template exists at path: $template_path/$user_dir/$instance_dir/$tname\n" >&2
|
||||
return 4
|
||||
fi
|
||||
|
||||
if [ ! -d "/$template_path/$user_dir" ]; then
|
||||
zfs create $template_path/$user_dir
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to create private template path $template_path/$user_dir\n" >&2
|
||||
return 6
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d "/$template_path/$user_dir/$instance_dir" ]; then
|
||||
zfs create $template_path/$user_dir/$instance_dir
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to create private template path $template_path/$user_dir/$instance_dir\n" >&2
|
||||
return 6
|
||||
fi
|
||||
fi
|
||||
|
||||
zfs send $fspath@$snapshotname | zfs recv $template_path/$user_dir/$instance_dir/$tname
|
||||
zfs send $fspath/rootdisk@$snapshotname | zfs recv $template_path/$user_dir/$instance_dir/$tname/rootdisk
|
||||
zfs send $fspath/datadisk1@$snapshotname | zfs recv $template_path/$user_dir/$instance_dir/$tname/datadisk1
|
||||
|
||||
##### other things we could try are clone then promote
|
||||
# zfs clone $fspath@$snapshotname $template_path
|
||||
# zfs clone $fspath/rootdisk@$snapshotname $template_path/rootdisk
|
||||
# zfs clone $fspath/datadisk1@$snapshotname $template_path/datadisk1
|
||||
# zfs promote $template_path
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to receive snapshot $snapshotname for path $fspath\n" >&2
|
||||
return 5
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
pflag=
|
||||
nflag=
|
||||
dflag=
|
||||
uflag=
|
||||
iflag=
|
||||
sflag=
|
||||
pathval=
|
||||
templatename=
|
||||
snapshot=
|
||||
install_dir=
|
||||
user_folder=
|
||||
instance_folder=
|
||||
|
||||
while getopts 'p:n:d:u:i:s:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
p) pflag=1
|
||||
pathval="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
templatename="$OPTARG"
|
||||
;;
|
||||
s) sflag=1
|
||||
snapshot="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
install_dir="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
user_folder="$OPTARG"
|
||||
;;
|
||||
i) iflag=1
|
||||
instance_folder="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$pflag$nflag$dflag$uflag$iflag$sflag" != "111111" ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
|
||||
create_template $pathval $snapshot $install_dir $user_folder $instance_folder $templatename
|
||||
exit $?
|
||||
@ -1,79 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: createdatadisk.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/createdatadisk.sh $
|
||||
# createdatadisk.sh -- create a thin-provisioned data disk
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -i <instance-fs> -s <disk size in GB>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#set -x
|
||||
|
||||
iflag=
|
||||
sflag=
|
||||
cflag=
|
||||
disknum=
|
||||
datadisk=
|
||||
|
||||
while getopts 'i:s:c:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
c) cflag=1
|
||||
disknum="$OPTARG"
|
||||
datadisk="datadisk-$disknum"
|
||||
;;
|
||||
s) sflag=1
|
||||
diskfs=""
|
||||
disksize="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$iflag$sflag$cflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [ -n "$disksize" ]
|
||||
then
|
||||
suffix=${disksize:(-1)}
|
||||
echo $suffix
|
||||
case $suffix in
|
||||
G)
|
||||
;;
|
||||
[0-9]) disksize=${disksize}G
|
||||
;;
|
||||
*) printf "Error in disk size: expect G as a suffix or no suffix\n"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
fi
|
||||
|
||||
if [ -n "$disksize" ]
|
||||
then
|
||||
zfs create -V $disksize -s $instancefs/$datadisk #-s for sparse
|
||||
rc=$?
|
||||
fi
|
||||
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to create data disk $instancefs/$datadisk\n" >&2
|
||||
exit 6
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,270 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: createtmplt.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/createtmplt.sh $
|
||||
# createtmplt.sh -- install a template
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -t <template-fs> -n <templatename> -f <root disk file> -s <size in Gigabytes> -c <md5 cksum> -d <descr> -h [-u]\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#set -x
|
||||
|
||||
rollback_if_needed() {
|
||||
if [ $2 -gt 0 ]
|
||||
then
|
||||
printf "$3\n"
|
||||
#back out all changes
|
||||
zfs destroy -r $1
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
verify_cksum() {
|
||||
echo "$1 $2" | md5sum -c --status
|
||||
#printf "$1\t$2" | md5sum -c --status
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Checksum failed, not proceeding with install\n"
|
||||
exit 3
|
||||
fi
|
||||
}
|
||||
|
||||
untar() {
|
||||
local ft=$(file $1| awk -F" " '{print $2}')
|
||||
local basedir=$(dirname $1)
|
||||
case $ft in
|
||||
USTAR) local rootimg=$(tar tf $1 | grep $3)
|
||||
(cd $2; tar xf $1)
|
||||
rm -f $1
|
||||
printf "$2/$rootimg"
|
||||
;;
|
||||
*) printf "$1"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
uncompress() {
|
||||
local ft=$(file $1| awk -F" " '{print $2}')
|
||||
local imgfile=${1%.*} #strip out trailing file suffix
|
||||
local tmpfile=${imgfile}.tmp
|
||||
|
||||
case $ft in
|
||||
gzip) gunzip -c $1 > $tmpfile
|
||||
;;
|
||||
bzip2) bunzip2 -c $1 > $tmpfile
|
||||
;;
|
||||
ZIP) unzip -p $1 | cat > $tmpfile
|
||||
;;
|
||||
*) printf "$1"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to uncompress file, exiting "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mv $tmpfile $imgfile
|
||||
printf "$imgfile"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
create_vol_from_file() {
|
||||
local tmpltfs=$1
|
||||
local tmpltimg=$2
|
||||
local tgtvol=$3
|
||||
local tgtdisk=$4
|
||||
local volsize=$5
|
||||
local cleanup=$6
|
||||
|
||||
zfs list -H -o name $tgtvol
|
||||
|
||||
#create it if it doesn't exist
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
zfs create -V $volsize -s $tgtvol
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to create the target root disk volume\n"
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
|
||||
local osversion=$(uname -v)
|
||||
if [ "$osversion" == "snv_111b" ]
|
||||
then
|
||||
#copy 64k of zeros for LUN metatdata
|
||||
dd if=/dev/zero of=$tgtdisk bs=64k count=1
|
||||
#copy the file to the disk
|
||||
dd if=$tmpltimg of=$tgtdisk bs=64k seek=1
|
||||
else
|
||||
#copy the file to the disk. Could just use 'cp' as well
|
||||
dd if=$tmpltimg of=$tgtdisk bs=1024k
|
||||
fi
|
||||
|
||||
|
||||
rollback_if_needed $tmpltfs $? "Failed to copy root disk"
|
||||
|
||||
if [ "$cleanup" == "true" ]
|
||||
then
|
||||
rm -f $tmpltimg
|
||||
fi
|
||||
}
|
||||
|
||||
tflag=
|
||||
nflag=
|
||||
fflag=
|
||||
sflag=
|
||||
hflag=
|
||||
hvm=false
|
||||
cleanup=false
|
||||
dflag=
|
||||
cflag=
|
||||
|
||||
while getopts 'uht:n:f:s:c:d:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
t) tflag=1
|
||||
tmpltfs="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
tmpltname="$OPTARG"
|
||||
;;
|
||||
f) fflag=1
|
||||
tmpltimg="$OPTARG"
|
||||
;;
|
||||
s) sflag=1
|
||||
volsize="$OPTARG"
|
||||
;;
|
||||
c) cflag=1
|
||||
cksum="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
descr="$OPTARG"
|
||||
;;
|
||||
h) hflag=1
|
||||
hvm="true"
|
||||
;;
|
||||
u) cleanup="true"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$tflag$nflag$fflag$sflag" != "1111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ -n "$cksum" ]
|
||||
then
|
||||
verify_cksum $cksum $tmpltimg
|
||||
fi
|
||||
|
||||
if [ ${tmpltfs:0:1} == / ]
|
||||
then
|
||||
tmpltfs=${tmpltfs:1}
|
||||
fi
|
||||
|
||||
if [ ! -d /$tmpltfs ]
|
||||
then
|
||||
zfs create $tmpltfs
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to create user fs $tmpltfs\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $tmpltfs) != filesystem ]]
|
||||
then
|
||||
printf "template fs doesn't exist\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
tmpltimg2=$(uncompress $tmpltimg)
|
||||
tmpltimg2=$(untar $tmpltimg2 /$tmpltfs vmi-root)
|
||||
|
||||
if [ ! -f $tmpltimg2 ]
|
||||
then
|
||||
rollback_if_needed $tmpltfs 2 "root disk file $tmpltimg doesn't exist\n"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# need the 'G' suffix on volume size
|
||||
if [ ${volsize:(-1)} != G ]
|
||||
then
|
||||
volsize=${volsize}G
|
||||
fi
|
||||
|
||||
#determine source file size -- it needs to be less than or equal to volsize
|
||||
imgsize=$(ls -lh $tmpltimg2| awk -F" " '{print $5}')
|
||||
if [ ${imgsize:(-1)} == G ]
|
||||
then
|
||||
imgsize=${imgsize%G} #strip out the G
|
||||
imgsize=${imgsize%.*} #...and any decimal part
|
||||
let imgsize=imgsize+1 # add 1 to compensate for decimal part
|
||||
volsizetmp=${volsize%G}
|
||||
if [ $volsizetmp -lt $imgsize ]
|
||||
then
|
||||
volsize=${imgsize}G
|
||||
fi
|
||||
fi
|
||||
|
||||
tgtvol=${tmpltfs}/vmi-root-${tmpltname}
|
||||
tgtdisk=/dev/zvol/dsk/${tgtvol}
|
||||
|
||||
create_vol_from_file $tmpltfs $tmpltimg2 $tgtvol $tgtdisk $volsize $cleanup
|
||||
|
||||
tmpltswap=$(ls -lh /$tmpltfs | grep swap)
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
swapsize=$(echo $tmpltswap | awk '{print $5}')
|
||||
tmpltswap=$(echo $tmpltswap | awk '{print $NF}')
|
||||
tmpltswap=/${tmpltfs}/${tmpltswap}
|
||||
tgtvol=${tmpltfs}/vmi-swap-${tmpltname}
|
||||
tgtdisk=/dev/zvol/dsk/${tgtvol}
|
||||
create_vol_from_file $tmpltfs $tmpltswap $tgtvol $tgtdisk $swapsize $cleanup
|
||||
fi
|
||||
|
||||
|
||||
if [ "$hvm" != "true" ]
|
||||
then
|
||||
vmlinuz=$(ls /$tmpltfs/vmlinuz*)
|
||||
if [ "$vmlinuz" == "" ]
|
||||
then
|
||||
touch /$tmpltfs/pygrub
|
||||
fi
|
||||
fi
|
||||
|
||||
rollback_if_needed $tmpltfs $? "Failed to create pygrub file"
|
||||
|
||||
touch /$tmpltfs/template.properties
|
||||
rollback_if_needed $tmpltfs $? "Failed to create template.properties file"
|
||||
echo -n "" > /$tmpltfs/template.properties
|
||||
|
||||
today=$(date '+%m_%d_%Y')
|
||||
echo "snapshot.name=$today" > /$tmpltfs/template.properties
|
||||
echo "description=$descr" >> /$tmpltfs/template.properties
|
||||
echo "name=$tmpltname" >> /$tmpltfs/template.properties
|
||||
echo "checksum=$cksum" >> /$tmpltfs/template.properties
|
||||
echo "hvm=$hvm" >> /$tmpltfs/template.properties
|
||||
echo "volume.size=$volsize" >> /$tmpltfs/template.properties
|
||||
|
||||
zfs snapshot -r $tmpltfs@$today
|
||||
rollback_if_needed $tmpltfs $? "Failed to snapshot filesystem"
|
||||
|
||||
if [ "$cleanup" == "true" ]
|
||||
then
|
||||
rm -f $tmpltimg
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,248 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: createvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/createvm.sh $
|
||||
# createvm.sh -- create a vm image directory by cloning (iscsi mode)
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -t <template-fs> -d <disk-fs> -i <instance-fs> -u <user fs>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
logzfs() {
|
||||
if [ -z "$debug" ]
|
||||
then
|
||||
return
|
||||
fi
|
||||
local elapsed=0
|
||||
printf "$(date +'%H:%M:%S') $*\n" >&3
|
||||
if [ "$(echo $1| awk '{print $1}')" == "start:" ]
|
||||
then
|
||||
start="$(/usr/gnu/bin/date +'%s')"
|
||||
return
|
||||
fi
|
||||
if [ "$(echo $1| awk '{print $1}')" == "end:" ]
|
||||
then
|
||||
end="$(/usr/gnu/bin/date +'%s')"
|
||||
let elapsed=end-start
|
||||
printf "t=$elapsed $*\n" >&3
|
||||
fi
|
||||
}
|
||||
|
||||
#ensure that the instance fs is mounted within the user fs
|
||||
check_valid_userfs() {
|
||||
local ifs=$1
|
||||
local ufs=$2
|
||||
local child=${ifs#$ufs}
|
||||
if [ ${#child} -eq $(( ${#ifs}-${#ufs} )) ]
|
||||
then
|
||||
return 0
|
||||
else
|
||||
printf "instance fs $ifs is not contained within user fs $ufs. Bailing\n" >&2
|
||||
exit 3;
|
||||
fi
|
||||
}
|
||||
|
||||
get_instance() {
|
||||
echo $(basename $1)
|
||||
}
|
||||
|
||||
get_latest_snapshot() {
|
||||
local fs=$1
|
||||
local tsnap=$(echo $fs | cut -f1 -d'@')
|
||||
if [ "$tsnap" == "$fs" ]
|
||||
then
|
||||
snap=$(zfs list -r -H -o name -S name -S creation -t snapshot $tsnap| head -1)
|
||||
if [ -z $snap ]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
echo $snap
|
||||
return 0
|
||||
else
|
||||
echo $fs
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
trap 'echo "killed..." >&3; exec 3>&-; exit 9' TERM INT KILL
|
||||
#set -x
|
||||
|
||||
tflag=
|
||||
iflag=
|
||||
uflag=
|
||||
dflag=
|
||||
sflag=
|
||||
start=
|
||||
end=
|
||||
debug=1
|
||||
|
||||
while getopts 't:i:u:d:s:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
t) tflag=1
|
||||
templatefs="$OPTARG"
|
||||
;;
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
userfs="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
diskfs="$OPTARG"
|
||||
;;
|
||||
s) sflag=1
|
||||
diskfs=""
|
||||
disksize="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$tflag$iflag$uflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#either -d or -s but not both
|
||||
if [ "$dflag$sflag" == "11" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#if user has provided leading slash, strip it out
|
||||
if [ ${userfs:0:1} == / ]
|
||||
then
|
||||
userfs=${userfs:1}
|
||||
fi
|
||||
|
||||
if [ ${templatefs:0:1} == / ]
|
||||
then
|
||||
templatefs=${templatefs:1}
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
if [ -n "$diskfs" ]
|
||||
then
|
||||
if [ ${diskfs:0:1} == / ]
|
||||
then
|
||||
diskfs=${diskfs:1}
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$disksize" ]
|
||||
then
|
||||
suffix=${disksize:(-1)}
|
||||
echo $suffix
|
||||
case $suffix in
|
||||
G)
|
||||
;;
|
||||
[0-9]) disksize=${disksize}G
|
||||
;;
|
||||
*) printf "Error in disk size: expect G as a suffix or no suffix\n"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
fi
|
||||
|
||||
instance=$(get_instance $instancefs)
|
||||
if [ -n "$debug" ]
|
||||
then
|
||||
exec 3<>$(dirname $0)/../../logs/create$instance.log
|
||||
fi
|
||||
|
||||
check_valid_userfs $instancefs $userfs
|
||||
|
||||
|
||||
#if user has provided the exact snapshot of the template fs, use it,
|
||||
#else get the latest snapshot
|
||||
tsnap=$(echo $templatefs | cut -f1 -d'@')
|
||||
if [ "$tsnap" == "$templatefs" ]
|
||||
then
|
||||
logzfs "start: get_latest_snapshot"
|
||||
tsnap=$(get_latest_snapshot $templatefs)
|
||||
logzfs "end: get_latest_snapshot"
|
||||
if [ -z "$tsnap" ]
|
||||
then
|
||||
printf "No snapshots exist of filesystem $templatefs..bailing\n" >&2
|
||||
exit 4
|
||||
fi
|
||||
else
|
||||
tsnap=$templatefs
|
||||
templatefs=$(echo $templatefs | cut -f1 -d'@') #strip out snap version
|
||||
fi
|
||||
|
||||
snapt=$(echo $tsnap | cut -f2 -d'@')
|
||||
|
||||
if [ -n "$diskfs" ]
|
||||
then
|
||||
logzfs "start: get_latest_snapshot"
|
||||
disksnap=$(get_latest_snapshot $diskfs)
|
||||
logzfs "end: get_latest_snapshot"
|
||||
if [ -z "$disksnap" ]
|
||||
then
|
||||
printf "No snapshots exist of disk filesystem $diskfs..bailing\n" >&2
|
||||
exit 6
|
||||
fi
|
||||
diskfs=$(echo $diskfs | cut -d'@' -f1)
|
||||
fi
|
||||
|
||||
#Clone root disk and associated files
|
||||
printf "Cloning root disk $tsnap to $instancefs\n" >&2
|
||||
logzfs "start: zfs clone -p $tsnap $instancefs"
|
||||
zfs clone -p $tsnap $instancefs
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to clone root disk $snap\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
logzfs "end: zfs clone -p $tsnap $instancefs"
|
||||
|
||||
#get root disk/swapdisk volume contained within templatefs
|
||||
logzfs "start: zfs list -H -o name -t volume -r $templatefs"
|
||||
for vol in $(zfs list -H -o name -t volume -r $templatefs )
|
||||
do
|
||||
#clone the snapshot
|
||||
logzfs "start: zfs clone $vol@$snapt $instancefs/$(basename $vol)"
|
||||
zfs clone $vol@$snapt $instancefs/$(basename $vol)
|
||||
rc=$?
|
||||
logzfs "end: zfs clone $vol@$snapt $instancefs/$(basename $vol)"
|
||||
done
|
||||
|
||||
rc=0
|
||||
#Clone datadisk
|
||||
if [ -n "$diskfs" ]
|
||||
then
|
||||
logzfs "start: zfs clone $disksnap $instancefs/datadisk1-$(basename $diskfs)"
|
||||
zfs clone $disksnap $instancefs/datadisk1-$(basename $diskfs)
|
||||
rc=$?
|
||||
logzfs "end: zfs clone $disksnap $instancefs/datadisk1-$(basename $diskfs)"
|
||||
fi
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to clone data disk $disksnap\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
if [ -n "$disksize" ]
|
||||
then
|
||||
logzfs "start: zfs create $instancefs/datadisk1"
|
||||
zfs create -V $disksize -s $instancefs/datadisk1 #-s for sparse
|
||||
rc=$?
|
||||
logzfs "end: zfs create $instancefs/datadisk1"
|
||||
fi
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to create data disk $instancefs/datadisk1\n" >&2
|
||||
exit 6
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,133 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: delvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/delvm.sh $
|
||||
# delvm.sh -- delete a cloned image used for a vm
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -i <instance-fs> -u <user fs>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#set -x
|
||||
logzfs() {
|
||||
if [ -z "$debug" ]
|
||||
then
|
||||
return
|
||||
fi
|
||||
local elapsed=0
|
||||
printf "$(date +'%H:%M:%S') $*\n" >&3
|
||||
if [ "$(echo $1| awk '{print $1}')" == "start:" ]
|
||||
then
|
||||
start="$(/usr/gnu/bin/date +'%s')"
|
||||
return
|
||||
fi
|
||||
if [ "$(echo $1| awk '{print $1}')" == "end:" ]
|
||||
then
|
||||
end="$(/usr/gnu/bin/date +'%s')"
|
||||
let elapsed=end-start
|
||||
printf "t=$elapsed $*\n" >&3
|
||||
fi
|
||||
}
|
||||
get_instance() {
|
||||
echo $(basename $1)
|
||||
}
|
||||
|
||||
iflag=
|
||||
uflag=
|
||||
userfs=
|
||||
instancefs=
|
||||
start=
|
||||
end=
|
||||
debug=1
|
||||
|
||||
while getopts 'i:u:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
userfs="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$iflag$uflag" != "1" -a "$iflag$uflag" != "11" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ -n $instancefs && ${instancefs:0:1} == / ]]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
if [[ -n $userfs && ${userfs:0:1} == / ]]
|
||||
then
|
||||
userfs=${userfs:1}
|
||||
fi
|
||||
|
||||
if [[ "$iflag" == 1 && $(zfs get -H -o value -p type $instancefs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied instance fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$uflag" == 1 && $(zfs get -H -o value -p type $userfs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied user fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
instance=$(get_instance $instancefs)
|
||||
if [ -n "$debug" ]
|
||||
then
|
||||
exec 3<>$(dirname $0)/../../logs/del$instance.log
|
||||
fi
|
||||
|
||||
if [ "$iflag" == 1 ]
|
||||
then
|
||||
printf "Going to destroy $instancefs and its children\n"
|
||||
logzfs "start: zfs destroy -r -f $instancefs "
|
||||
zfs destroy -r -f $instancefs
|
||||
rc=$?
|
||||
logzfs "end: zfs destroy -r -f $instancefs "
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
numc=$(zfs list -Hr $instancefs 2> /dev/null| wc -l)
|
||||
if [ "$numc" -eq 1 ]
|
||||
then
|
||||
printf "Trying again to destroy instance fs $instancefs \n" >&2
|
||||
zfs destroy -r -f $instancefs
|
||||
else
|
||||
printf "Failed to destroy instance fs $instancefs, numchildren=$numc\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$uflag" == 1 ]
|
||||
then
|
||||
printf "Going to destroy $userfs and its children\n"
|
||||
logzfs "start: zfs destroy -r -f $userfs"
|
||||
zfs destroy -r -f $userfs
|
||||
rc=$?
|
||||
logzfs "end: zfs destroy -r -f $userfs"
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
numc=$(zfs list -Hr $userfs 2> /dev/null| wc -l)
|
||||
if [ "$numc" -eq 1 ]
|
||||
then
|
||||
printf "Trying again to destroy user fs $userfs \n" >&2
|
||||
zfs destroy -r -f $userfs
|
||||
else
|
||||
printf "Failed to destroy user fs $userfs, numchildren=$numc\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,51 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: get_iqn.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/get_iqn.sh $
|
||||
# get_iqn.sh -- return iSCSI iqn of initiator (Linux) or target (OpenSolaris)
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
linux() {
|
||||
uname -a | grep "Linux" > /dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
opensolaris() {
|
||||
uname -a | grep "SunOS" > /dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
hosted() {
|
||||
uname -a | grep "101b" > /dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
if [ $# -ne 0 ]
|
||||
then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if linux
|
||||
then
|
||||
initiator_iqn=$(cat /etc/iscsi/initiatorname.iscsi | cut -d'=' -f2)
|
||||
printf "%s\n" $initiator_iqn
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if opensolaris && hosted
|
||||
then
|
||||
printf "unique_iqn_per_zvol\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if opensolaris
|
||||
then
|
||||
tgt_iqn=$(itadm list-target | tail -1 | awk '{print $1}')
|
||||
printf "%s\n" $tgt_iqn
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf "Unexpected operating system!\n" >&2
|
||||
exit 2
|
||||
@ -1,101 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: listvmdisk.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/listvmdisk.sh $
|
||||
# listvmdisk.sh -- list disks of a VM (iscsi mode)
|
||||
# Bugs: does not handle hexadecimal numbers. Decimal only!
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -i <instance-fs> [-r | -w | -d <num> ] \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
path_and_iqn() {
|
||||
local ifs=$1
|
||||
local pattern=$2
|
||||
|
||||
local diskvol=$(zfs list -r -H -o name -t volume $ifs | grep $pattern)
|
||||
if [ "$diskvol" != "" ]
|
||||
then
|
||||
local tgtname=$(iscsitadm list target $diskvol | grep Name | awk '{print $3}')
|
||||
fi
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
return 6
|
||||
fi
|
||||
if [ "$diskvol" != "" -a "$tgtname" != "" ]
|
||||
then
|
||||
printf "$diskvol,$tgtname\n"
|
||||
return 0
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
iflag=
|
||||
rflag=
|
||||
dflag=
|
||||
wflag=
|
||||
disknum=
|
||||
instancefs=
|
||||
|
||||
while getopts 'i:d:rw' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
disknum="$OPTARG"
|
||||
;;
|
||||
r) rflag=1
|
||||
;;
|
||||
w) wflag=1
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$iflag" != "1" -a "$rflag$dflag$wflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $instancefs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied instance fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ "$rflag" == 1 ]
|
||||
then
|
||||
path_and_iqn $instancefs "root"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
if [ "$wflag" == 1 ]
|
||||
then
|
||||
path_and_iqn $instancefs "swap"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
if [ "$dflag" == 1 ]
|
||||
then
|
||||
if [[ $disknum -eq 0 ]]
|
||||
then
|
||||
path_and_iqn $instancefs "root"
|
||||
else
|
||||
path_and_iqn $instancefs "datadisk"$disknum
|
||||
fi
|
||||
|
||||
exit $?
|
||||
fi
|
||||
exit 0
|
||||
@ -1,111 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: listvmdisksize.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/listvmdisksize.sh $
|
||||
# listvmdisksize.sh -- list disk sizes of a VM (iscsi mode)
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -d <disk-fs> [-t | -a ] \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#####################################################################
|
||||
# Evaluate a floating point number expression.
|
||||
function float_eval()
|
||||
{
|
||||
local stat=0
|
||||
local result=0.0
|
||||
if [[ $# -gt 0 ]]; then
|
||||
result=$(echo "scale=0; $*" | bc 2>/dev/null)
|
||||
stat=$?
|
||||
if [[ $stat -eq 0 && -z "$result" ]]; then stat=1; fi
|
||||
fi
|
||||
echo $result
|
||||
return $stat
|
||||
}
|
||||
|
||||
kmg_to_number()
|
||||
{
|
||||
local s=$1;
|
||||
local size=${s:0:$((${#s}-1))}
|
||||
local result=$1;
|
||||
local suffix=${s:(-1)}
|
||||
case $suffix in
|
||||
G) result=$(float_eval "$size*1024*1024*1024")
|
||||
;;
|
||||
M) result=$(float_eval "$size*1024*1024")
|
||||
;;
|
||||
K) result=$(float_eval "$size*1024")
|
||||
;;
|
||||
esac
|
||||
|
||||
result=$(echo $result | cut -d"." -f1) #strip out decimal precision
|
||||
echo $result
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
aflag=
|
||||
tflag=
|
||||
aflag=
|
||||
diskfs=
|
||||
|
||||
while getopts 'd:ta' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
d) dflag=1
|
||||
diskfs="$OPTARG"
|
||||
;;
|
||||
t) tflag=1
|
||||
;;
|
||||
a) aflag=1
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$dflag" != "1" -a "$tflag$aflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${diskfs:0:1} == / ]
|
||||
then
|
||||
diskfs=${diskfs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $diskfs) != volume ]]
|
||||
then
|
||||
printf "Supplied disk volume doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ "$aflag" == 1 ]
|
||||
then
|
||||
used=$(zfs list -H -o used -t volume $diskfs)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 5
|
||||
fi
|
||||
result=$(kmg_to_number $used)
|
||||
printf "$result\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$tflag" == 1 ]
|
||||
then
|
||||
total=$(zfs list -H -o volsize $diskfs)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 5
|
||||
fi
|
||||
result=$(kmg_to_number $total)
|
||||
printf "$result\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,51 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: listvmtmplt.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/listvmtmplt.sh $
|
||||
# listtmplt.sh -- list templates under a directory
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -r <root dir> \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#set -x
|
||||
|
||||
rflag=
|
||||
rootdir=
|
||||
|
||||
while getopts 'r:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
r) rflag=1
|
||||
rootdir="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$rflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${rootdir:0:1} == / ]
|
||||
then
|
||||
rootdir=${rootdir:1}
|
||||
fi
|
||||
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $rootdir) != filesystem ]]
|
||||
then
|
||||
printf "Supplied root directory fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for i in $(find /$rootdir -name template.properties -size +0 );
|
||||
do
|
||||
d=$(dirname $i)
|
||||
echo ${d#/} #remove leading slash
|
||||
done
|
||||
|
||||
exit 0
|
||||
@ -1,4 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: lu_info.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/lu_info.sh $
|
||||
|
||||
iscsitadm list target $1
|
||||
@ -1 +0,0 @@
|
||||
# $Id: lu_share.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/lu_share.sh $
|
||||
@ -1,105 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: managesnapshot.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/managesnapshot.sh $
|
||||
# managesnapshot.sh -- manage snapshots (create, destroy, rollback)
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -c <path> -n <snapshot name>\n" $(basename $0) >&2
|
||||
printf "Usage: %s: -d <path> -n <snapshot name>\n" $(basename $0) >&2
|
||||
printf "Usage: %s: -r <path> -n <snapshot name>\n" $(basename $0) >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
create_snapshot() {
|
||||
local fspath=$1
|
||||
local snapshotname=$2
|
||||
|
||||
zfs snapshot -r $fspath@$snapshotname
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to create snapshot $snapshotname for path $fspath\n" >&2
|
||||
return 5
|
||||
fi
|
||||
}
|
||||
|
||||
destroy_snapshot() {
|
||||
local fspath=$1
|
||||
local snapshotname=$2
|
||||
|
||||
zfs destroy -rRf $fspath@$snapshotname
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to destroy snapshot $snapshotname for path $fspath\n" >&2
|
||||
return 6
|
||||
fi
|
||||
}
|
||||
|
||||
rollback_snapshot() {
|
||||
local fspath=$1
|
||||
local snapshotname=$2
|
||||
|
||||
zfs rollback -r $fspath/datadisk1@$snapshotname
|
||||
zfs rollback -r $fspath/rootdisk@$snapshotname
|
||||
zfs rollback -r $fspath@$snapshotname
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to rollback to snapshot $snapshotname for path $fspath\n" >&2
|
||||
return 7
|
||||
fi
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
cflag=
|
||||
dflag=
|
||||
rflag=
|
||||
nflag=
|
||||
pathval=
|
||||
snapshot=
|
||||
|
||||
while getopts 'c:d:r:n:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
c) cflag=1
|
||||
pathval="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
pathval="$OPTARG"
|
||||
;;
|
||||
r) rflag=1
|
||||
pathval="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
snapshot="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$nflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$cflag$dflag$rflag" != "1" ]
|
||||
then
|
||||
printf "***Specify one of -c (create), -d (destroy), or -r (rollback) and a path for the target snapshot\n" >&2
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$cflag" == "1" ]
|
||||
then
|
||||
create_snapshot $pathval $snapshot
|
||||
exit $?
|
||||
elif [ "$dflag" == "1" ]
|
||||
then
|
||||
destroy_snapshot $pathval $snapshot
|
||||
exit $?
|
||||
elif [ "$rflag" == "1" ]
|
||||
then
|
||||
rollback_snapshot $pathval $snapshot
|
||||
exit $?
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,163 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: managevolume.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/managevolume.sh $
|
||||
# modifyvolume.sh -- add or delete a disk volume
|
||||
#
|
||||
|
||||
usage() {
|
||||
echo "Usage: modifydisk.sh -f <folder of volume> -p <path of volume> -s <size of volume> [-d <delete>] \n"
|
||||
}
|
||||
|
||||
check_params() {
|
||||
# The folder, path, and size must be passed in
|
||||
if [ "$fflag$pflag$sflag" != "111" ]
|
||||
then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup_and_exit_if_error() {
|
||||
local return_code=$1
|
||||
local msg=$2
|
||||
local path=$3
|
||||
|
||||
if [ $return_code -gt 0 ]
|
||||
then
|
||||
delete_disk $path
|
||||
exit_if_error $return_code "$msg"
|
||||
fi
|
||||
}
|
||||
|
||||
exit_if_error() {
|
||||
local return_code=$1
|
||||
local msg=$2
|
||||
|
||||
if [ $return_code -gt 0 ]
|
||||
then
|
||||
printf "${msg}\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
make_folder() {
|
||||
local folder=$1
|
||||
|
||||
if [ ! -d ${folder} ]
|
||||
then
|
||||
mkdir -p ${folder}
|
||||
fi
|
||||
}
|
||||
|
||||
check_disk() {
|
||||
local folder=$1
|
||||
local path=$2
|
||||
|
||||
make_folder $folder
|
||||
|
||||
if [ -f $path ]
|
||||
then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
delete_disk() {
|
||||
local path=$1
|
||||
|
||||
if [ -f $path ]
|
||||
then
|
||||
rm $path
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
create_disk() {
|
||||
local path=$1
|
||||
local size=$2
|
||||
|
||||
size=$(convert_size_to_gb $size)
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
|
||||
qemu-img create -f qcow2 $path $size
|
||||
|
||||
return $?
|
||||
}
|
||||
|
||||
convert_size_to_gb() {
|
||||
local size=$1
|
||||
|
||||
suffix=${size:(-1)}
|
||||
case $suffix in
|
||||
G)
|
||||
;;
|
||||
[0-9]) size=${size}G
|
||||
;;
|
||||
*) printf "Error in disk size: expect G as a suffix or no suffix\n"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo $size
|
||||
return 0
|
||||
}
|
||||
|
||||
# set -x
|
||||
|
||||
fflag=0
|
||||
pflag=0
|
||||
sflag=0
|
||||
dflag=0
|
||||
|
||||
while getopts 'f:p:s:d:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
f) fflag=1
|
||||
folder="$OPTARG"
|
||||
;;
|
||||
p) pflag=1
|
||||
path="$OPTARG"
|
||||
;;
|
||||
s) sflag=1
|
||||
size="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check all parameters
|
||||
check_params
|
||||
exit_if_error $? "$(usage)"
|
||||
|
||||
if [ "$dflag" == "0" ]
|
||||
then
|
||||
# Add the volume
|
||||
|
||||
# Create the folder if necessary, and make sure there is no existing disk there
|
||||
check_disk $folder $path
|
||||
cleanup_and_exit_if_error $? "Failed to create disk at $path; path already exists." $path
|
||||
|
||||
# Create the disk
|
||||
create_disk $path $size
|
||||
cleanup_and_exit_if_error $? "Failed to create disk at $path of size $datadisksize." $path
|
||||
|
||||
else
|
||||
# Delete the volume
|
||||
|
||||
delete_disk $path
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
|
||||
@ -1,99 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: showdisks.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/showdisks.sh $
|
||||
# mapiscsi.sh -- list of active iscsi sessions and the corresponding VM
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s <vm name> \n" $(basename $0) >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
get_disktype () {
|
||||
local vmdisk=$1
|
||||
if [[ $vmdisk =~ ^.*root.*$ ]]
|
||||
then
|
||||
echo "root";
|
||||
return 0
|
||||
fi
|
||||
if [[ $vmdisk =~ ^.*swap.*$ ]]
|
||||
then
|
||||
echo "swap";
|
||||
return 0
|
||||
fi
|
||||
if [[ $vmdisk =~ ^.*datadisk.*$ ]]
|
||||
then
|
||||
echo "datadisk";
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
mirror_state0() {
|
||||
local vmname=$1
|
||||
local disktype=$2
|
||||
mirr=$(ls -l /dev/md/ | grep $vmname-$disktype | awk '{print $(NF-2)}')
|
||||
mdadm --query /dev/md/$mirr &> /dev/null
|
||||
if [ $? -ne 0 -o "$mirr" == "" ]
|
||||
then
|
||||
state="Not mirrored"
|
||||
else
|
||||
state=$(mdadm --detail /dev/md/$mirr | grep "State : " | awk '{print $3 $4 $5}')
|
||||
fi
|
||||
echo $state
|
||||
}
|
||||
|
||||
mirror_state1() {
|
||||
local vmname=$1
|
||||
local disktype=$2
|
||||
local disk=$3
|
||||
mirr=$(ls -l /dev/md/ | grep $vmname-$disktype | awk '{print $(NF-2)}')
|
||||
mdadm --query /dev/md/$mirr &> /dev/null
|
||||
if [ $? -eq 0 -a "$mirr" != "" ]
|
||||
then
|
||||
state=$(mdadm --detail /dev/md/$mirr | grep "$disk" | awk '{print $(NF-2), $(NF-1)}')
|
||||
fi
|
||||
echo $state
|
||||
}
|
||||
|
||||
if [ "$1" == "" ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
vmname=$1
|
||||
|
||||
if ! xm list | grep -w $vmname > /dev/null
|
||||
then
|
||||
printf "%s: vm $vmname not found\n" $(basename $0)
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#set -x
|
||||
|
||||
disks=$(ls -l /dev/disk/by-vm | grep $vmname | awk '{print $NF}')
|
||||
for d in $disks
|
||||
do
|
||||
vmdisk=$(ls -l /dev/disk/by-vm | grep -w $d | awk '{print $(NF-2)}')
|
||||
disktype=$(get_disktype $vmdisk)
|
||||
lasttoken=$(echo $vmdisk | awk -F"-" '{print $NF}')
|
||||
case "$lasttoken" in
|
||||
"root");;
|
||||
"swap");;
|
||||
"[0-9]") ;;
|
||||
*) vmdisk=${vmdisk%-*} #strip the ip address of storage host;;
|
||||
esac
|
||||
|
||||
if [[ $vmdisk =~ ^.*datadisk.*$ ]]; then vmdisk=${vm%-*}; fi
|
||||
disk=$d
|
||||
d=${d##*/}
|
||||
iqn=$(ls -l /dev/disk/by-path | grep -w $d | awk '{print $(NF-2)}')
|
||||
ip=$(echo $iqn | awk -F: '{print $1}')
|
||||
ip=${ip#ip-}
|
||||
|
||||
mirrstate="[$(mirror_state0 $vmname $disktype)]"
|
||||
diskstate="[$(mirror_state1 $vmname $disktype $disk)]"
|
||||
|
||||
echo $vmname $disktype $disk $ip $mirrstate $diskstate
|
||||
|
||||
|
||||
done
|
||||
exit 0
|
||||
|
||||
@ -1,72 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: upgradevmdisk.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/iscsi/upgradevmdisk.sh $
|
||||
# upgradevmdisk.sh -- upgrade size of disks of a VM (iscsi mode)
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -f <instance-fs> -d <size> \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
upgrade_disk() {
|
||||
local ifs=$1
|
||||
local disk_size=$2
|
||||
|
||||
zfs set volsize=${disk_size}M $ifs
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
return 6
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
vflag=
|
||||
dflag=
|
||||
disksize=
|
||||
instancefs=
|
||||
|
||||
while getopts 'v:d:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
v) vflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
disksize="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$vflag" != "1" -a "$dflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $instancefs) != volume ]]
|
||||
then
|
||||
printf "Supplied instance fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$dflag" == 1 ]
|
||||
then
|
||||
if [[ $disksize -gt 0 ]]
|
||||
then
|
||||
upgrade_disk $instancefs $disksize
|
||||
fi
|
||||
|
||||
exit $?
|
||||
fi
|
||||
exit 0
|
||||
@ -1,174 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: createvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/nfs/createvm.sh $
|
||||
# createvm.sh -- create a vm image directory by cloning
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -t <template-fs> -d <disk-fs> -i <instance-fs> -u <user fs>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
#ensure that the instance fs is mounted within the user fs
|
||||
check_valid_userfs() {
|
||||
local ifs=$1
|
||||
local ufs=$2
|
||||
local child=${ifs#$ufs}
|
||||
if [ ${#child} -eq $(( ${#ifs}-${#ufs} )) ]
|
||||
then
|
||||
return 0
|
||||
else
|
||||
printf "instance fs $ifs is not contained within user fs $ufs. Bailing\n" >&2
|
||||
exit 3;
|
||||
fi
|
||||
}
|
||||
|
||||
get_latest_snapshot() {
|
||||
local fs=$1
|
||||
snap=$(zfs list -r -H -o name -S creation -t snapshot $fs| head -1)
|
||||
if [ -z $snap ]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
echo $snap
|
||||
return 0
|
||||
}
|
||||
|
||||
clone_contained_datadisks() {
|
||||
local templatefs=$1
|
||||
local instancefs=$2
|
||||
for diskfs in $(find /$templatefs -type d | grep datadisk)
|
||||
do
|
||||
diskfs=${diskfs:1} #strip out leading slash
|
||||
disksnap=$(get_latest_snapshot $diskfs)
|
||||
if [ -z $disksnap ]
|
||||
then
|
||||
printf "No snapshots exist of disk filesystem $diskfs..bailing\n" >&2
|
||||
return 6
|
||||
fi
|
||||
disk=$(basename $disksnap | cut -f1 -d'@')
|
||||
disk="$instancefs/$disk"
|
||||
printf "Cloning datadisk $disksnap to $disk\n" >&2
|
||||
zfs clone $disksnap $disk
|
||||
#printf "disksnap=$disksnap target=$disk\n"
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to clone datadisk $disksnap\n" >&2
|
||||
return 7
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
tflag=
|
||||
iflag=
|
||||
uflag=
|
||||
dflag=
|
||||
|
||||
while getopts 't:i:u:d:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
t) tflag=1
|
||||
templatefs="$OPTARG"
|
||||
;;
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
userfs="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
diskfs="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$tflag$iflag$uflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#if user has provided leading slash, strip it out
|
||||
if [ ${userfs:0:1} == / ]
|
||||
then
|
||||
userfs=${userfs:1}
|
||||
fi
|
||||
|
||||
if [ ${templatefs:0:1} == / ]
|
||||
then
|
||||
templatefs=${templatefs:1}
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
if [ -n "$diskfs" ]
|
||||
then
|
||||
if [ ${diskfs:0:1} == / ]
|
||||
then
|
||||
diskfs=${diskfs:1}
|
||||
fi
|
||||
fi
|
||||
|
||||
check_valid_userfs $instancefs $userfs
|
||||
|
||||
#if userfs doesn't exist, create it
|
||||
if [ ! -d /$userfs ]
|
||||
then
|
||||
zfs create $userfs
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to create user fs $userfs\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
|
||||
#if user has provided the exact snapshot of the template fs, use it,
|
||||
#else get the latest snapshot
|
||||
tsnap=$(echo $templatefs | cut -f2 -d'@')
|
||||
if [ $tsnap == $templatefs ]
|
||||
then
|
||||
tsnap=$(get_latest_snapshot $templatefs)
|
||||
if [ -z $tsnap ]
|
||||
then
|
||||
printf "No snapshots exist of filesystem $templatefs..bailing\n" >&2
|
||||
exit 4
|
||||
fi
|
||||
else
|
||||
tsnap=$templatefs
|
||||
templatefs=$(echo $templatefs | cut -f1 -d'@') #strip out snap version
|
||||
fi
|
||||
|
||||
if [ -n "$diskfs" ]
|
||||
then
|
||||
disksnap=$(get_latest_snapshot $diskfs)
|
||||
if [ -z $disksnap ]
|
||||
then
|
||||
printf "No snapshots exist of disk filesystem $diskfs..bailing\n" >&2
|
||||
exit 6
|
||||
fi
|
||||
fi
|
||||
|
||||
#Clone root disk and associated files
|
||||
printf "Cloning root disk $tsnap to $instancefs\n" >&2
|
||||
zfs clone $tsnap $instancefs
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to clone root disk $snap\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
#Clone datadisk
|
||||
if [ -n "$diskfs" ]
|
||||
then
|
||||
zfs clone $disksnap $instancefs/datadisk1
|
||||
else
|
||||
clone_contained_datadisks $templatefs $instancefs
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,81 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: delvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/nfs/delvm.sh $
|
||||
# delvm.sh -- delete a cloned image used for a vm
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -i <instance-fs> -u <user fs>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#set -x
|
||||
|
||||
iflag=
|
||||
uflag=
|
||||
userfs=
|
||||
instancefs=
|
||||
|
||||
while getopts 'i:u:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
userfs="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$iflag$uflag" != "1" -a "$iflag$uflag" != "11" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ -n $instancefs && ${instancefs:0:1} == / ]]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
if [[ -n $userfs && ${userfs:0:1} == / ]]
|
||||
then
|
||||
userfs=${userfs:1}
|
||||
fi
|
||||
|
||||
if [[ "$iflag" == 1 && $(zfs get -H -o value -p type $instancefs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied instance fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$uflag" == 1 && $(zfs get -H -o value -p type $userfs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied user fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$iflag" == 1 ]
|
||||
then
|
||||
zfs destroy -r $instancefs
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to destroy instance fs\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$uflag" == 1 ]
|
||||
then
|
||||
zfs destroy -r $userfs
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to destroy user fs\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,31 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: listclones.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/nfs/listclones.sh $
|
||||
# listclones.sh -- list all cloned filesystems under a parent fs
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -p <parent-fs> \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#set -x
|
||||
|
||||
pflag=
|
||||
|
||||
while getopts 'p:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
p) pflag=1
|
||||
parentFs="$OPTARG"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$pflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
|
||||
zfs list -H -r -o name,origin $parentFs | awk '$2 != "-" {print $1}' | grep -v datadisk
|
||||
@ -1,79 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: listvmdisk.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/nfs/listvmdisk.sh $
|
||||
# listvmdisk.sh -- list disks of a VM
|
||||
# Bugs: does not handle hexadecimal numbers. Decimal only!
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -i <instance-fs> [-r | -d <num> ] \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#set -x
|
||||
|
||||
iflag=
|
||||
rflag=
|
||||
dflag=
|
||||
disknum=
|
||||
instancefs=
|
||||
|
||||
while getopts 'i:d:r' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
i) iflag=1
|
||||
instancefs="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
disknum="$OPTARG"
|
||||
;;
|
||||
r) rflag=1
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$iflag" != "1" -a "$rflag$dflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${instancefs:0:1} == / ]
|
||||
then
|
||||
instancefs=${instancefs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $instancefs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied instance fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ "$rflag" == 1 ]
|
||||
then
|
||||
zfs list -r -H -o name -t filesystem $instancefs | grep -v datadisk
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 5
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$dflag" == 1 ]
|
||||
then
|
||||
if [[ $disknum -eq 0 ]]
|
||||
then
|
||||
zfs list -r -H -o name -t filesystem $instancefs | grep -v datadisk
|
||||
else
|
||||
zfs list -r -H -o name -t filesystem $instancefs | grep datadisk$disknum
|
||||
fi
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
exit 0
|
||||
@ -1,104 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: listvmdisksize.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/nfs/listvmdisksize.sh $
|
||||
# listvmdisksize.sh -- list disk sizes of a VM
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -d <disk-fs> [-t | -a ] \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
#####################################################################
|
||||
# Evaluate a floating point number expression.
|
||||
function float_eval()
|
||||
{
|
||||
local stat=0
|
||||
local result=0.0
|
||||
if [[ $# -gt 0 ]]; then
|
||||
result=$(echo "scale=0; $*" | bc 2>/dev/null)
|
||||
stat=$?
|
||||
if [[ $stat -eq 0 && -z "$result" ]]; then stat=1; fi
|
||||
fi
|
||||
echo $result
|
||||
return $stat
|
||||
}
|
||||
|
||||
|
||||
#set -x
|
||||
|
||||
aflag=
|
||||
tflag=
|
||||
aflag=
|
||||
diskfs=
|
||||
|
||||
while getopts 'd:ta' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
d) dflag=1
|
||||
diskfs="$OPTARG"
|
||||
;;
|
||||
t) tflag=1
|
||||
;;
|
||||
a) aflag=1
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$dflag" != "1" -a "$tflag$aflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ${diskfs:0:1} == / ]
|
||||
then
|
||||
diskfs=${diskfs:1}
|
||||
fi
|
||||
|
||||
|
||||
if [[ $(zfs get -H -o value -p type $diskfs) != filesystem ]]
|
||||
then
|
||||
printf "Supplied disk fs doesn't exist\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ "$aflag" == 1 ]
|
||||
then
|
||||
used=$(zfs list -H -o used -t filesystem $diskfs)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 5
|
||||
fi
|
||||
result=$used
|
||||
size=${used:0:$((${#used}-1))}
|
||||
suffix=${used:(-1)}
|
||||
case $suffix in
|
||||
G) result=$(float_eval "$size*1024*1024*1024")
|
||||
;;
|
||||
M) result=$(float_eval "$size*1024*1024")
|
||||
;;
|
||||
K) result=$(float_eval "$size*1024")
|
||||
;;
|
||||
esac
|
||||
|
||||
result=$(echo $result | cut -d"." -f1) #strip out decimal precision
|
||||
printf "$result\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$tflag" == 1 ]
|
||||
then
|
||||
result=$(ls -l /$diskfs | grep vmi-root | awk '{print $5}')
|
||||
if [ "$result" == "" ]
|
||||
then
|
||||
result=$(ls -l /$diskfs | grep vmi-data| awk '{print $5}')
|
||||
fi
|
||||
printf "$result\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,196 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: rundomr.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/nfs/rundomr.sh $
|
||||
# rundomr.sh -- start a domR
|
||||
#
|
||||
#
|
||||
#set -x
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -v <vnet-id> -i <eth1 ip-address> -m <memory in MB> -a <eth0 mac address> -A <eth1 mac address> -p <eth2 mac address> -P <eth2 ip addr> -n <eth1 eth1mask> -N <eth2 eth1mask> -g <default gw ip> -l <vm label> <image-dir>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
check_vnetd_running() {
|
||||
/sbin/lsmod | grep vnet_module > /dev/null
|
||||
local module_loaded=$?
|
||||
if [[ ( -z $(pidof vnetd) ) && ( $module_loaded -ne 0 ) ]]
|
||||
then
|
||||
printf 'vnet: Neither userspace daemon running nor kernel module loaded!, not starting vm '"$vmname\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# check if ip address is already used
|
||||
check_ip() {
|
||||
ping -c 1 -n -q $1 > /dev/null
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
printf "Error: ip address $1 already in use...exiting\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
create_vnet () {
|
||||
local vnetid=$1
|
||||
local bridgeid="vnbr""$vnetid"
|
||||
local vnifid="vnif""$vnetid"
|
||||
local longvnetid="0000:0000:0000:0000:0000:0000:0000:""$vnetid"
|
||||
|
||||
eval "$2=$bridgeid"
|
||||
|
||||
# Create the vnet even if it already exists. /usr/sbin/vn operation is
|
||||
# idempotent
|
||||
vn vnet-create -b ${bridgeid} ${longvnetid} &> /dev/null
|
||||
|
||||
#echo $bridgeid $vnifid $longvnetid
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
vflag=
|
||||
iflag=
|
||||
mflag=
|
||||
aflag=
|
||||
gflag=
|
||||
lflag=
|
||||
nflag=
|
||||
Aflag=
|
||||
dflag=
|
||||
bflag=
|
||||
pflag=
|
||||
Iflag=
|
||||
Nflag=
|
||||
dnsoptions=
|
||||
xenbr=
|
||||
|
||||
while getopts 'v:i:m:a:A:g:l:n:d:b:p:I:N:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
v) vflag=1
|
||||
vnetid="$OPTARG"
|
||||
;;
|
||||
i) iflag=1
|
||||
eth1ip="$OPTARG"
|
||||
;;
|
||||
m) mflag=1
|
||||
ram="$OPTARG"
|
||||
;;
|
||||
a) aflag=1
|
||||
eth0mac="$OPTARG"
|
||||
;;
|
||||
A) Aflag=1
|
||||
eth1mac="mac=$OPTARG"
|
||||
;;
|
||||
g) gflag=1
|
||||
gateway="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
eth1mask="$OPTARG"
|
||||
;;
|
||||
l) lflag=1
|
||||
vmname="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
dnsoptions="$OPTARG"
|
||||
;;
|
||||
p) pflag=1
|
||||
eth2mac="$OPTARG"
|
||||
;;
|
||||
I) Iflag=1
|
||||
eth2ip="$OPTARG"
|
||||
;;
|
||||
N) Nflag=1
|
||||
eth2mask="$OPTARG"
|
||||
;;
|
||||
b) bflag=1
|
||||
xenbr="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
#-d & -b is optional
|
||||
if [ "$Aflag$vflag$mflag$iflag$aflag$nflag$gflag$lflag" != "11111111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
imagedir=$1
|
||||
|
||||
if [ -z $imagedir ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
|
||||
if xm list $vmname &>/dev/null
|
||||
then
|
||||
printf "Error: domR $vmname already exists\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#make sure vnetd is running
|
||||
check_vnetd_running
|
||||
|
||||
# grab the kernel, bootloader and disk images
|
||||
kernel="$imagedir/"$(ls $imagedir | grep vmlinuz)
|
||||
ramdisk="$imagedir/"$(ls $imagedir | grep initrd)
|
||||
rootdisk="$imagedir/"$(ls $imagedir | grep vmi-root)
|
||||
swapdisk="$imagedir/"$(ls $imagedir | grep swap)
|
||||
|
||||
if [ "$rootdisk" == "$imagedir/" ]
|
||||
then
|
||||
printf "Error: No root disk found\nVM $vmname not started\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
|
||||
if [ "$kernel" == "$imagedir/" ] || [ "$ramdisk" == "$imagedir/" ]
|
||||
then
|
||||
printf "Could not find kernel and initrd images, exiting\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#ensure no ip address clash
|
||||
check_ip $eth1ip
|
||||
|
||||
|
||||
|
||||
# Create the vnet locally if not already created
|
||||
bridge=""
|
||||
if ! create_vnet "$vnetid" bridge ; then
|
||||
printf "Failed to create vnet, exiting\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
eth2br=
|
||||
if [ -n "$xenbr" ]
|
||||
then
|
||||
eth2br=",bridge=$xenbr"
|
||||
fi
|
||||
#echo $eth2br
|
||||
|
||||
# create the domR. Pass eth1 ip configuration in the "extra" flag
|
||||
xm new /dev/null kernel="$kernel" name="$vmname" disk="tap:aio:$rootdisk,xvda1,w" disk="tap:aio:$swapdisk,xvda2,w" ramdisk="$ramdisk" memory=$ram vif="mac=$eth0mac,bridge=$bridge" vif="$eth1mac,bridge=eth0" vif="mac=$eth2mac$eth2br" root="/dev/xvda1 ro" ip="$eth1ip" extra="fastboot eth1ip=$eth1ip eth1mask=$eth1mask eth2ip=$eth2ip eth2mask=$eth2mask gateway=$gateway $dnsoptions"
|
||||
|
||||
|
||||
if [ $? -gt 0 ]; then
|
||||
exit 10
|
||||
fi
|
||||
|
||||
#Kick off the vm
|
||||
xm start $vmname
|
||||
|
||||
if [ $? -gt 0 ]; then
|
||||
exit 20
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
|
||||
@ -1,304 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: runvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/nfs/runvm.sh $
|
||||
# runvm.sh -- start a vm from a directory containing the kernel and os images
|
||||
#
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -v <vnet-id> -i <ip-address> -m <memory in MB> -a <mac address> -g <gateway ip addr> -c <vnc console #> -w <vnc password>-l <vm label> -n <# cores> -u <compute unites in pct> <image-dir>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
check_vnetd_running() {
|
||||
/sbin/lsmod | grep vnet_module > /dev/null
|
||||
local module_loaded=$?
|
||||
if [[ ( -z $(pidof vnetd) ) && ( $module_loaded -ne 0 ) ]]
|
||||
then
|
||||
printf 'vnet: Neither userspace daemon running nor kernel module loaded!, not starting vm '"$vmname\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
is_xen_3_3 () {
|
||||
local a;
|
||||
local b;
|
||||
a=$(xm info | grep xen_minor | cut -d":" -f2);
|
||||
b=$(echo $a)
|
||||
if [ $b -lt 3 ]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
get_dom0_ip () {
|
||||
if ifconfig eth0 &> /dev/null;
|
||||
then
|
||||
eval "$1=$(ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}')"
|
||||
return 0
|
||||
elif ifconfig eth1 &> /dev/null;
|
||||
then
|
||||
eval "$1=$(ifconfig eth1 | awk '/inet addr/ {split ($2,A,":"); print A[2]}')"
|
||||
return 0;
|
||||
fi
|
||||
return 1;
|
||||
}
|
||||
|
||||
create_vnet () {
|
||||
local vnetid=$1
|
||||
local bridgeid="vnbr""$vnetid"
|
||||
local vnifid="vnif""$vnetid"
|
||||
local longvnetid="0000:0000:0000:0000:0000:0000:0000:""$vnetid"
|
||||
|
||||
eval "$2=$bridgeid"
|
||||
|
||||
# Create the vnet even if it already exists. /usr/sbin/vn operation is
|
||||
# idempotent
|
||||
vn vnet-create -b ${bridgeid} ${longvnetid} &> /dev/null
|
||||
|
||||
#echo $bridgeid $vnifid $longvnetid
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
# check if gateway domain is up and running
|
||||
check_gw() {
|
||||
ping -c 1 -n -q $1 > /dev/null
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
sleep 1
|
||||
ping -c 1 -n -q $1 > /dev/null
|
||||
fi
|
||||
return $?;
|
||||
}
|
||||
|
||||
#Append an entry into dhcp hosts file and knock the dhcp server on its head
|
||||
add_dhcp_entry() {
|
||||
local gw=$1
|
||||
local mac=$2
|
||||
local ip=$3
|
||||
local vm=$4
|
||||
ssh -o StrictHostKeyChecking=no -i ./id_rsa root@$gw "/root/edithosts.sh $mac $ip $vm" >/dev/null
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
$5=1
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
vflag=
|
||||
iflag=
|
||||
mflag=
|
||||
aflag=
|
||||
gflag=
|
||||
lflag=
|
||||
cflag=
|
||||
vcpus=0
|
||||
cpucap=0
|
||||
vncpwd="password"
|
||||
|
||||
while getopts 'v:i:m:a:g:l:c:n:u:w:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
v) vflag=1
|
||||
vnetid="$OPTARG"
|
||||
;;
|
||||
i) iflag=1
|
||||
ipaddr="$OPTARG"
|
||||
;;
|
||||
m) mflag=1
|
||||
ram="$OPTARG"
|
||||
;;
|
||||
a) aflag=1
|
||||
macaddr="$OPTARG"
|
||||
;;
|
||||
g) gflag=1
|
||||
gateway="$OPTARG"
|
||||
;;
|
||||
l) lflag=1
|
||||
vmname="$OPTARG"
|
||||
;;
|
||||
c) cflag=1
|
||||
vncconsole="$OPTARG"
|
||||
;;
|
||||
w) wflag=1
|
||||
vncpwd="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
vcpus="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
cpucap="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$vflag$mflag$iflag$aflag$gflag$lflag$cflag" != "1111111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
wincpuopts=""
|
||||
if [ "$vcpus" == 0 -a "$cpucap" == 0 ]
|
||||
then
|
||||
#Windows doesn't like it
|
||||
wincpuopts=""
|
||||
elif [ "$vcpus" == 0 ]
|
||||
then
|
||||
wincpuopts="cpu_cap=$cpucap"
|
||||
elif [ "$cpucap" == 0 ]
|
||||
then
|
||||
wincpuopts="vcpus=$vcpus"
|
||||
else
|
||||
wincpuopts="vcpus=$vcpus cpu_cap=$cpucap"
|
||||
fi
|
||||
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
imagedir=$1
|
||||
|
||||
if [ -z $imagedir ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
if [ "$vmname" == gateway ]
|
||||
then
|
||||
printf "Error: $vmname is illegal (this is the hostname of domR)\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
if xm list $vmname &>/dev/null
|
||||
then
|
||||
printf "Error: vm $vmname already exists\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ "$ipaddr" == "10.1.1.1" ]
|
||||
then
|
||||
printf "Error: 10.1.1.1 is the gateway and cannot be assigned to a vm\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#make sure vnetd is running
|
||||
check_vnetd_running
|
||||
|
||||
# grab the kernel, bootloader and disk images
|
||||
kernel="$imagedir/"$(ls $imagedir | grep vmlinuz)
|
||||
ramdisk="$imagedir/"$(ls $imagedir | grep initrd)
|
||||
rootdisk="$imagedir/"$(ls $imagedir | grep vmi-root)
|
||||
swapdisk="$imagedir/"$(ls $imagedir | grep swap)
|
||||
datadisk1="$imagedir/"$(ls $imagedir | grep vmi-data1)
|
||||
datadisk2="$imagedir/"$(ls $imagedir | grep vmi-data2)
|
||||
|
||||
#set -x
|
||||
|
||||
if [ "$rootdisk" == "$imagedir/" ]
|
||||
then
|
||||
printf "Error: No root disk found\nVM $vmname not started\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [ "$datadisk1" == "$imagedir/" ]
|
||||
then
|
||||
#look for subdirs called 'datadisk'
|
||||
i=0
|
||||
datadisks=( )
|
||||
for diskfs in $(find $imagedir -type d | grep datadisk)
|
||||
do
|
||||
datadisks[$i]=$(find $diskfs | grep vmi-data | head -1) #expect only 1 disk
|
||||
let i=i+1
|
||||
done
|
||||
datadisk1=${datadisks[0]};
|
||||
if [ -z "$datadisk1" ]
|
||||
then
|
||||
printf "Error: No data disk found\nVM $vmname not started\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
linux=0
|
||||
windows=0
|
||||
pygr=0
|
||||
|
||||
if [ "$kernel" != "$imagedir/" ] && [ "$ramdisk" != "$imagedir/" ]
|
||||
then
|
||||
#Linux kernel
|
||||
linux=1
|
||||
builder="linux"
|
||||
device_model=""
|
||||
elif [ -f "$imagedir/pygrub" ]
|
||||
then
|
||||
#pygrub linux image
|
||||
pygr=1
|
||||
else
|
||||
kernel="/usr/lib/xen/boot/hvmloader"
|
||||
windows=1
|
||||
builder="hvm"
|
||||
device_model="/usr/lib64/xen/bin/qemu-dm"
|
||||
fi
|
||||
|
||||
#get dom 0 ip to figure out which ip to bind vnc to
|
||||
dom0ip=""
|
||||
get_dom0_ip dom0ip
|
||||
|
||||
# check if gateway domain is up and running
|
||||
if ! check_gw "$gateway"
|
||||
then
|
||||
printf "Unable to ping the gateway domain, exiting\n" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
#Append an entry into dhcp hosts file and knock the dhcp server on its head
|
||||
added=0
|
||||
if ! add_dhcp_entry $gateway $macaddr $ipaddr $vmname $added
|
||||
then
|
||||
printf "Unable add dhcp entry on gateway (reason=$added), exiting\n" >&2
|
||||
exit 4
|
||||
fi
|
||||
|
||||
# Create the vnet locally if not already created
|
||||
bridge=""
|
||||
if ! create_vnet "$vnetid" bridge ; then
|
||||
printf "Failed to create vnet, exiting\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
#hvm disk prefix for 3.1 is file:, for 3.3 it is tap:aio
|
||||
hvmdisk="tap:aio"
|
||||
if ! is_xen_3_3
|
||||
then
|
||||
hvmdisk="file"
|
||||
fi
|
||||
|
||||
# create the vm (linux)
|
||||
if [ $linux -eq 1 ]; then
|
||||
xm new /dev/null kernel="$kernel" name="$vmname" disk="tap:aio:$rootdisk,xvda1,w" disk="tap:aio:$swapdisk,xvda2,w" disk="tap:aio:$datadisk1,xvda3,w" ramdisk="$ramdisk" memory=$ram vif="mac=$macaddr,bridge=$bridge" dhcp="dhcp" root="/dev/xvda1 ro" vnc=1 vnclisten="$dom0ip" vfb="type=vnc,vncdisplay=$vncconsole,vncpasswd=$vncpwd" ip="$ipaddr" extra="fastboot" vcpus=$vcpus cpu_cap=$cpucap
|
||||
elif [ $pygr -eq 1 ]; then
|
||||
xm new /dev/null bootloader="/usr/bin/pygrub" name="$vmname" disk="tap:aio:$rootdisk,sda,w" disk="tap:aio:$datadisk1,sdb,w" memory=$ram vif="mac=$macaddr,bridge=$bridge" dhcp="dhcp" root="/dev/sda ro" vnc=1 vnclisten="$dom0ip" vfb="type=vnc,vncdisplay=$vncconsole,vncpasswd=$vncpwd" ip="$ipaddr" extra="fastboot" vcpus=$vcpus cpu_cap=$cpucap
|
||||
else
|
||||
#create the vm (windows/HVM)
|
||||
xm new /dev/null kernel="$kernel" name="$vmname" disk="$hvmdisk:$rootdisk,hda,w" disk="$hvmdisk:$datadisk1,hdb,w" builder="$builder" device_model="$device_model" memory=$ram vif="mac=$macaddr,bridge=$bridge,type=ioemu" dhcp="dhcp" vnc=1 vnclisten="$dom0ip" vncdisplay="$vncconsole" vncpasswd="$vncpwd" usbdevice="tablet" localtime="yes" $wincpuopts
|
||||
fi
|
||||
|
||||
if [ $? -gt 0 ]; then
|
||||
exit 10
|
||||
fi
|
||||
|
||||
#Kick off the vm
|
||||
xm start $vmname
|
||||
|
||||
if [ $? -gt 0 ]; then
|
||||
exit 20
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
|
||||
@ -1,109 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: stopvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/nfs/stopvm.sh $
|
||||
# stopvm.sh -- stop one or all vm
|
||||
#
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: <-a|-l <vm label>> \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
unmount_disks() {
|
||||
disks=$(xm list -l $1 | grep tap:aio | cut -d":" -f3 | cut -d")" -f1)
|
||||
imagedirs=$(for d in $disks; do dskdir=$(dirname $d); echo ${#dskdir}:$dskdir; done | sort -n -r | cut -d":" -f2 | uniq)
|
||||
for i in $imagedirs
|
||||
do
|
||||
umount $i
|
||||
printf "Unmounted $i result=$?\n"
|
||||
done
|
||||
}
|
||||
|
||||
stop_one_vm() {
|
||||
if ! xm list $1 &>/dev/null
|
||||
then
|
||||
printf "Error: vm $1 does not exist\n" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
|
||||
local domId=0;
|
||||
if xm list $1 -l | grep domid
|
||||
then
|
||||
status=($(xm list $1 | grep $1))
|
||||
domId=${status[1]};
|
||||
fi
|
||||
|
||||
if [ $domId -gt 0 ]
|
||||
then
|
||||
#Try a graceful shutdown
|
||||
xm shutdown $1 -w
|
||||
unmount_disks $1
|
||||
else
|
||||
#printf "Domain $1 is already shutdown\n"
|
||||
unmount_disks $1
|
||||
xm delete $1
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ $? -gt 0 ]; then
|
||||
#Try an undignified shutdown
|
||||
xm destroy $1 -w
|
||||
unmount_disks $1
|
||||
fi
|
||||
|
||||
if [ $? -gt 0 ]; then
|
||||
#Try an undignified shutdown
|
||||
printf "Failed to terminate instance $1\n">&2
|
||||
return 20
|
||||
else
|
||||
xm delete $1
|
||||
fi
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
stop_all_vms() {
|
||||
for i in `xm list | grep -v Domain-0| grep -v Name| awk -F" " '{print $1}'`
|
||||
do
|
||||
stop_one_vm $i
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
lflag=
|
||||
aflag=
|
||||
|
||||
while getopts 'al:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
l) lflag=1
|
||||
vmname="$OPTARG"
|
||||
;;
|
||||
a) aflag=1
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$aflag$lflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ "$aflag" == "1" ]
|
||||
then
|
||||
stop_all_vms;
|
||||
exit 0
|
||||
fi
|
||||
|
||||
stop_one_vm $vmname
|
||||
|
||||
exit 0
|
||||
|
||||
|
||||
@ -1,74 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: zfs_mount_recovery.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/zfs/zfs_mount_recovery.sh $
|
||||
# zfs_mount_recovery.sh -- recover from early boot zfs mount failure
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# zfs_mount_recovery.sh [-f]
|
||||
#
|
||||
# Command line options:
|
||||
#
|
||||
# -f Force: Unmount/remount nonroot zfs filesystem even if the
|
||||
# system/filesystem/local service is working properly.
|
||||
#
|
||||
# OpenSolaris
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s [-f]\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
if [ $# -gt 2 ]
|
||||
then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
force_flag=
|
||||
|
||||
while getopts 'f' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
f) force_flag=1
|
||||
;;
|
||||
*) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
state=$(svcs -a | grep system/filesystem/local | awk '{print $1}')
|
||||
|
||||
if [ "$state" == "online" -a -z "$force_flag" ]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
rootpool_name="rootpool"
|
||||
|
||||
pool_name=$(zpool list -H | grep -v $rootpool_name | awk '{print $1}')
|
||||
|
||||
if [ -z "$pool_name" ]
|
||||
then
|
||||
printf "no storage pool configured\n" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# unmount any mounted child filesystems of affected storage pool
|
||||
|
||||
for path in $(zfs mount | grep $pool_name | awk '{print $1}')
|
||||
do
|
||||
zfs unmount -f $path 2>/dev/null
|
||||
done
|
||||
|
||||
rm -rf /${pool_name:-zzz}
|
||||
|
||||
for path in $(zfs list -H -o name,type | grep ^$pool_name | grep filesystem | awk '{print $1}')
|
||||
do
|
||||
zfs mount -O $path
|
||||
done
|
||||
|
||||
svcadm clear system/filesystem/local
|
||||
|
||||
exit 0
|
||||
@ -1,168 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: iscsi_common.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/comstar/iscsi_common.sh $
|
||||
# iscsi_common.sh -- mount volume from ISCSI server
|
||||
#
|
||||
#
|
||||
|
||||
# check if server is up and running
|
||||
check_iscsi_server() {
|
||||
local pings=1
|
||||
while ! ping -c 1 -n -q $1 > /dev/null && [ $pings -ne $2 ]
|
||||
do
|
||||
let pings=pings+1
|
||||
done
|
||||
|
||||
printf "##check_iscsi_server: number of pings=%s\n" $pings
|
||||
[ $pings -eq $2 ] && return 1
|
||||
return 0;
|
||||
}
|
||||
|
||||
target_iqn() { # either iscsitgtd <target-name> or comstar <target-iqn:lu:lu-name>
|
||||
if echo $1 | grep :lu: >/dev/null
|
||||
then
|
||||
echo $1 | cut -d':' -f1,2,3
|
||||
else
|
||||
echo $1
|
||||
fi
|
||||
}
|
||||
|
||||
do_iscsi_login () {
|
||||
local t_iqn=$(target_iqn $1)
|
||||
local rc=0
|
||||
#create a record in the client database
|
||||
iscsiadm -m node -T $t_iqn -p $2 -o new
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to create ISCSI initiator record for target rc=$rc\n" >&2
|
||||
return 6
|
||||
fi
|
||||
# do not autologin upon restart
|
||||
iscsiadm -m node -T $t_iqn -p $2 -o update -n node.startup -v manual
|
||||
|
||||
#login to the target
|
||||
iscsiadm -m node -T $t_iqn -p $2 -l
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to login to target, rc=$rc\n" >&2
|
||||
return 7
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
get_device_links() {
|
||||
local n=20
|
||||
local dev=
|
||||
local host=$1
|
||||
local iqn=$2
|
||||
local disktype=$3
|
||||
while [ -z "$dev" -a $n -gt 0 ]
|
||||
do
|
||||
sleep 3;
|
||||
let n=n-1;
|
||||
dev=$(ls -l /dev/disk/by-path/ip-$host*$iqn*| awk '{print $NF}' | awk -F"/" '{print $NF}' | head -1)
|
||||
done
|
||||
|
||||
if [ $n -eq 0 ]
|
||||
then
|
||||
printf "****Timed out waiting for $disktype device to register**\n"
|
||||
fi
|
||||
printf "$dev\n"
|
||||
}
|
||||
|
||||
do_iscsi_logout() {
|
||||
local t_iqn=$(target_iqn $1)
|
||||
local rc=0
|
||||
if [ "$1" == "" ]
|
||||
then
|
||||
return $rc
|
||||
fi
|
||||
iscsiadm -m node -T $t_iqn -u #logout
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to logout of $1 rc=$rc\n"
|
||||
fi
|
||||
iscsiadm -m node -T $t_iqn -o delete #delete record from db
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to delete iscsi record $1 rc=$rc\n"
|
||||
fi
|
||||
return $rc
|
||||
}
|
||||
|
||||
# unmount a local directory and all data disks within
|
||||
unmount_all() {
|
||||
local rc=0
|
||||
local err=0
|
||||
local localdir=$1
|
||||
local vmname=$2
|
||||
local disks=$(ls -l $DISKDIR | grep $vmname | awk '{print $NF}') #/dev/sdb
|
||||
for d in $disks ;
|
||||
do
|
||||
disknum=$(echo $d | awk -F"/" '{print $NF}') #sdb
|
||||
tgt=$(ls -l /dev/disk/by-path | grep -w $disknum | awk '{print $(NF-2)}' | grep -v part | cut -d: -f2- | cut -d- -f3-)
|
||||
softlink=$(ls -l $DISKDIR |grep $vmname| grep $d | awk '{print $(NF-2)}') #vmname-root or vmname-swap or vmname-data
|
||||
rm $DISKDIR/$softlink #delete soft link
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to delete $DISKDIR/$softlink rc=$rc\n"
|
||||
let err=err+1
|
||||
fi
|
||||
do_iscsi_logout $tgt
|
||||
let err=err+$?
|
||||
done
|
||||
|
||||
#unmount the image filesystem from nfs
|
||||
local errmsg=$(umount $localdir 2>&1)
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
echo $errmsg | grep "not mounted"
|
||||
if [ $? -eq 1 ]
|
||||
then
|
||||
printf "*****Warning: unmount failed rc=$rc\n"
|
||||
let err=err+1
|
||||
fi
|
||||
fi
|
||||
rm -fr $localdir
|
||||
|
||||
return $err
|
||||
}
|
||||
|
||||
#find the block device for a particular vm disk
|
||||
get_blkdev() {
|
||||
local vmname=$1
|
||||
local disktype=$2
|
||||
local disk=$(ls -l $DISKDIR | grep $vmname-$disktype | awk '{print $NF}') #/dev/sdb
|
||||
echo $disk
|
||||
}
|
||||
|
||||
# unmount an iscsi disk
|
||||
unmount_disk() {
|
||||
local rc=0
|
||||
local err=0
|
||||
local vmname=$1
|
||||
local disktype=$2
|
||||
local disks=$(ls -l $DISKDIR | grep $vmname | grep $disktype | awk '{print $NF}') #/dev/sdb
|
||||
for d in $disks ;
|
||||
do
|
||||
local disknum=$(echo $d | awk -F"/" '{print $NF}') #sdb
|
||||
local tgt=$(ls -l /dev/disk/by-path | grep -w $disknum | awk '{print $(NF-2)}' | grep -v part | cut -d: -f2- | cut -d- -f3-)
|
||||
local softlink=$(ls -l $DISKDIR |grep $vmname| grep $d | awk '{print $(NF-2)}') #vmname-root or vmname-swap or vmname-data
|
||||
rm $DISKDIR/$softlink #delete soft link
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to delete $DISKDIR/$softlink rc=$rc\n"
|
||||
let err=err+1
|
||||
fi
|
||||
do_iscsi_logout $tgt
|
||||
let err=err+$?
|
||||
done
|
||||
return $err
|
||||
}
|
||||
|
||||
DISKDIR="/dev/disk/by-vm/"
|
||||
@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: mapiscsi.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/comstar/mapiscsi.sh $
|
||||
# mapiscsi.sh -- list of active iscsi sessions and the corresponding VM
|
||||
#
|
||||
# COMSTAR version
|
||||
#
|
||||
# typical output:
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
iqn="iqn.2009-99.unk.nown:02:00000000-0000-0000-0000-000000000000:lu:00000000000000000000000000000000"
|
||||
|
||||
for vm in $(ls -l /dev/disk/by-vm | grep dev | awk '{print $(NF-2)}')
|
||||
do
|
||||
lasttoken=$(echo $vm | awk -F"-" '{print $NF}')
|
||||
case "$lasttoken" in
|
||||
"root");;
|
||||
"swap");;
|
||||
[0-9]) ;;
|
||||
*) vm=${vm%-*} #strip the ip address of storage host;;
|
||||
esac
|
||||
|
||||
if [[ $vm =~ ^.*datadisk.*$ ]]; then vm=${vm%-*}; fi
|
||||
echo $iqn $vm
|
||||
done
|
||||
@ -1,235 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: mountrootdisk.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/comstar/mountrootdisk.sh $
|
||||
# mountrootdisk.sh -- mount image directory from NFS and ISCSI server
|
||||
#
|
||||
#
|
||||
|
||||
dir=$(dirname $0)
|
||||
. $dir/iscsi_common.sh
|
||||
. $dir/mirror_common.sh
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: [-u | -m ] -h <iscsi-target-host> -r <remote-dir> -t <root disk target-name> -w <swap disk target name> -l <local dir> -n <vm-name> -b <bootloader> [-M -H <mirror-host> -T <mirror-disk-root-target> -W <mirror-swap-disk-target>]\n" $(basename $0) >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
login() {
|
||||
local vmname=$1
|
||||
local iqn=$2
|
||||
local host=$3
|
||||
local localdir=$4
|
||||
do_iscsi_login $iqn $host
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to login to $iqn at $host\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 5
|
||||
fi
|
||||
}
|
||||
|
||||
make_links() {
|
||||
local vmname=$1
|
||||
local host=$2
|
||||
local iqn=$3
|
||||
local disktype=$4
|
||||
local localdir=$5
|
||||
blkdev=$(get_device_links $host $iqn $disktype)
|
||||
if [ "$blkdev" == "" ]
|
||||
then
|
||||
printf "***Failed to get device links for $iqn $vmname $disktype\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 8
|
||||
fi
|
||||
echo "/dev/$blkdev"
|
||||
ln -s /dev/$blkdev $DISKDIR/$vmname-$disktype-$host
|
||||
return $?
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
hflag=
|
||||
rflag=
|
||||
lflag=
|
||||
uflag=
|
||||
mflag=
|
||||
nflag=
|
||||
tflag=
|
||||
Mflag=
|
||||
Tflag=
|
||||
Wflag=
|
||||
bflag=
|
||||
rootname=
|
||||
swpname=
|
||||
rootmirror=
|
||||
swpmirror=
|
||||
tgthost=
|
||||
tgtmirror=
|
||||
bootloader="PyGrub"
|
||||
|
||||
while getopts 'umxw:t:n:h:H:r:l:T:W:Mb:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
h) hflag=1
|
||||
tgthost="$OPTARG"
|
||||
;;
|
||||
H) Hflag=1
|
||||
tgtmirror="$OPTARG"
|
||||
;;
|
||||
r) rflag=1
|
||||
remotedir="$OPTARG"
|
||||
;;
|
||||
t) tflag=1
|
||||
rootname="$OPTARG"
|
||||
;;
|
||||
T) Tflag=1
|
||||
rootmirror="$OPTARG"
|
||||
;;
|
||||
w) wflag=1
|
||||
swpname="$OPTARG"
|
||||
;;
|
||||
b) bflag=1
|
||||
bootloader="$OPTARG"
|
||||
;;
|
||||
W) Wflag=1
|
||||
swpmirror="$OPTARG"
|
||||
;;
|
||||
l) lflag=1
|
||||
localdir="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
vmname="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
;;
|
||||
m) mflag=1
|
||||
;;
|
||||
M) Mflag=1
|
||||
;;
|
||||
x) set -x
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$hflag$rflag$lflag$nflag$tflag" != "11111" ] && [ "$uflag$lflag$nflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$uflag$mflag" != "1" ]
|
||||
then
|
||||
printf "***Specify one of -u (unmount) or -m (mount)\n" >&2
|
||||
usage
|
||||
fi
|
||||
|
||||
|
||||
if [ "$uflag" == "1" ]
|
||||
then
|
||||
if [ "$Mflag$uflag" == "1" ]
|
||||
then
|
||||
unmount_all $localdir $vmname
|
||||
rc=$?
|
||||
exit $rc
|
||||
elif [ "$Mflag$uflag" == "11" ]
|
||||
then
|
||||
stop_mirror $vmname root
|
||||
rc=$?
|
||||
stop_mirror $vmname swap
|
||||
unmount_all $localdir $vmname
|
||||
rc=$?
|
||||
exit $rc
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
#create the local dir if necessary
|
||||
if ! mkdir -p $localdir
|
||||
then
|
||||
printf "***Unable to create local directory, exiting\n" >&2
|
||||
fi
|
||||
|
||||
#create disk directory if needed
|
||||
if [ ! -d $DISKDIR ];
|
||||
then
|
||||
mkdir $DISKDIR
|
||||
fi
|
||||
|
||||
#check if the iscsi target portal is up and running
|
||||
if ! check_iscsi_server "$tgthost" 4
|
||||
then
|
||||
printf "***Unable to ping the iscsi target host $tgthost, exiting\n" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
if [ "$Mflag" == 1 ]
|
||||
then
|
||||
if ! check_iscsi_server "$tgtmirror" 4
|
||||
then
|
||||
printf "***Unable to ping the iscsi target host $tgtmirror, exiting\n" >&2
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
|
||||
bootloader=$(echo $bootloader | tr [A-Z] [a-z])
|
||||
if [ "$bootloader" == "external" ]
|
||||
then
|
||||
#mount the local dir (for kernel, ramdisk, etc)
|
||||
mount -t nfs $tgthost:$remotedir $localdir -o intr,rsize=32768,wsize=32768,hard
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to mount $remotedir at $localdir\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
|
||||
login $vmname $rootname $tgthost $localdir
|
||||
sleep 1
|
||||
|
||||
if [ -n "$swpname" ]
|
||||
then
|
||||
login $vmname $swpname $tgthost $localdir
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
if [ -n "$rootmirror" ]
|
||||
then
|
||||
login $vmname $rootmirror $tgtmirror $localdir
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
if [ -n "$swpmirror" ]
|
||||
then
|
||||
login $vmname $swpmirror $tgtmirror $localdir
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
#figure out the device number and make a softlink
|
||||
root0dev=$(make_links $vmname $tgthost $rootname root $localdir)
|
||||
|
||||
if [ -n "$swpname" ]
|
||||
then
|
||||
swap0dev=$(make_links $vmname $tgthost $swpname swap $localdir)
|
||||
fi
|
||||
|
||||
if [ -n "$rootmirror" ]
|
||||
then
|
||||
root1dev=$(make_links $vmname $tgtmirror $rootmirror root $localdir)
|
||||
fi
|
||||
|
||||
if [ -n "$swpmirror" ]
|
||||
then
|
||||
swap1dev=$(make_links $vmname $tgtmirror $swpmirror swap $localdir)
|
||||
fi
|
||||
|
||||
if [ "$Mflag" == "1" ]
|
||||
then
|
||||
build_mirror $vmname root $root0dev $root1dev
|
||||
if [ "$swap0dev" ]
|
||||
then
|
||||
build_mirror $vmname swap $swap0dev $swap1dev
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,469 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: mountvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/comstar/mountvm.sh $
|
||||
# mountvm.sh -- mount image directory from NFS and ISCSI server
|
||||
#
|
||||
# COMSTAR version
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: [-u | -m ] -h <iscsi-target-host> -r <remote-dir> -t <root disk target-name> -w <swap disk target name> -1 <datadisk target name> -l <local dir> -n <vm-name>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
# check if server is up and running
|
||||
check_iscsi_server() {
|
||||
local pings=1
|
||||
while ! ping -c 1 -n -q $1 > /dev/null && [ $pings -ne $2 ]
|
||||
do
|
||||
let pings=pings+1
|
||||
done
|
||||
|
||||
printf "##check_iscsi_server: number of pings=%s\n" $pings
|
||||
[ $pings -eq $2 ] && return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
target_iqn() { # either iscsitgtd <target-name> or comstar <target-iqn:lu:lu-name>
|
||||
echo $1 | cut -d':' -f1,2,3
|
||||
}
|
||||
|
||||
get_lu_name() { # <target-iqn:lu:lu-name>
|
||||
# <target-iqn:lu:lu-name>
|
||||
echo $1 | cut -d':' -f5
|
||||
}
|
||||
|
||||
do_iscsi_login () { # target-iqn # ip-addr
|
||||
local t_iqn=$(target_iqn $1)
|
||||
local rc=0
|
||||
|
||||
local sid=
|
||||
# if already logged in, rescan scsi and return success
|
||||
sid=$(iscsiadm -m session | grep $2 | grep $t_iqn | awk '{print $2}' | tr -d '[]')
|
||||
if [ -n "$sid" ]
|
||||
then
|
||||
return $sid
|
||||
fi
|
||||
|
||||
#create a record in the client database
|
||||
iscsiadm -m node -T $t_iqn -p $2 -o new
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to create ISCSI initiator record for target rc=$rc\n" >&2
|
||||
return -6
|
||||
fi
|
||||
# do not autologin upon restart
|
||||
iscsiadm -m node -T $t_iqn -p $2 -o update -n node.startup -v manual
|
||||
|
||||
# login to the target
|
||||
iscsiadm -m node -T $t_iqn -p $2 -l
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to login to target, rc=$rc\n" >&2
|
||||
return -7
|
||||
fi
|
||||
|
||||
sid=$(iscsiadm -m session | grep $2 | grep $t_iqn | awk '{print $2}' | tr -d '[]')
|
||||
if [ -n "$sid" ]
|
||||
then
|
||||
return $sid
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
get_device_links() { # <sid> <tgt-iqn:lu:lu-name> <root|swap|data>
|
||||
local n=20
|
||||
local dev=
|
||||
local lu_name=$(get_lu_name $2)
|
||||
local disks=
|
||||
local lu=
|
||||
local sid=$1
|
||||
|
||||
# Let's unplug all the unused devices first
|
||||
unplug_unused_scsi_by_sid $sid 1>&2
|
||||
|
||||
while [ $n -gt 0 ]
|
||||
do
|
||||
let n=n-1
|
||||
iscsiadm -m session -r $sid --rescan > /dev/null 2>&1
|
||||
disks=$(iscsiadm -m session -r $sid -P 3 | grep Attached | grep running | awk '{print $4}')
|
||||
for d in $disks
|
||||
do
|
||||
lu=$(scsi_id -g -s /block/$d)
|
||||
if [ "$lu" == "3$lu_name" ]
|
||||
then
|
||||
# we found it but now wait for the /dev to appear.
|
||||
local m=10
|
||||
while [ $m -gt 0 ]
|
||||
do
|
||||
if ls -l /dev/$d > /dev/null 2>&1; then
|
||||
printf "$d\n"
|
||||
return 0
|
||||
fi
|
||||
let m=m-1
|
||||
printf "Waiting for /dev/$d to appear\n" >&2
|
||||
sleep 1
|
||||
done
|
||||
printf "Unable to get /dev/$d to appear\n" >&2
|
||||
return 2
|
||||
fi
|
||||
done
|
||||
sleep 3
|
||||
done
|
||||
|
||||
if [ $n -eq 0 ]
|
||||
then
|
||||
printf "****Timed out waiting for $3 device to register**\n" >&2
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
#unplug scsi disk by lun
|
||||
unplug_scsi_by_lu() { # lu
|
||||
local rc=0
|
||||
local unplug_lu=$1
|
||||
if [ -z "$unplug_lu" ]
|
||||
then
|
||||
return $rc
|
||||
fi
|
||||
disks=$(iscsiadm -m session -P 3 | grep Attached | grep running | awk '{print $4}')
|
||||
for d in $disks
|
||||
do
|
||||
lu=$(scsi_id -g -s /block/$d)
|
||||
if [ "$lu" == "$unplug_lu" ]
|
||||
then
|
||||
fsync /dev/$d > /dev/null 2>&1
|
||||
echo 1 >/sys/block/$d/device/delete
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: fail to unplug iscsi disk $d\n" >&2
|
||||
else
|
||||
printf "*****Info: succeed to unplug iscsi disk $d\n" >&2
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
#unplug scsi disk
|
||||
unplug_scsi_by_disk() { # disk sd*
|
||||
local rc=0
|
||||
if [ "$1" == "" ]
|
||||
then
|
||||
return $rc
|
||||
fi
|
||||
echo 1 >/sys/block/$1/device/delete
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: fail to unplug iscsi disk $1\n" >&2
|
||||
else
|
||||
printf "*****Info: succeed to unplug iscsi disk $1\n" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
# unmount a local directory and all data disks within
|
||||
unmount_all() {
|
||||
local rc=0
|
||||
local err=0
|
||||
local localdir=$1
|
||||
local vmname=$2
|
||||
local disks=$(ls -1 $DISKDIR/$vmname*) #/dev/sdb
|
||||
for softlink in $disks
|
||||
do
|
||||
local disknum=$(ls -l $softlink | awk '{print $NF}' | awk -F"/" '{print $NF}') #sdb
|
||||
printf " $disknum \n" >&2
|
||||
if [ -n "$softlink" ]
|
||||
then
|
||||
rm -f $softlink #delete soft link
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to delete $softlink rc=$rc\n" >&2
|
||||
let err=err+1
|
||||
fi
|
||||
fi
|
||||
|
||||
lun=$(ls -l /dev/disk/by-path/ip* | grep -w $disknum | awk '{print $(NF-2)}' | grep -v part | cut -d: -f2- | cut -d- -f3-)
|
||||
printf " $lun \n" >&2
|
||||
if [ -n "$lun" ]
|
||||
then
|
||||
pathids=$(ls -l /dev/disk/by-path/ip*$lun | awk -F"/" '{print $NF}')
|
||||
printf " $pathids \n" >&2
|
||||
for pathid in $pathids
|
||||
do
|
||||
unplug_scsi_by_disk $pathid
|
||||
let err=err+$?
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
#unmount the image filesystem from nfs
|
||||
local errmsg=$(umount $localdir 2>&1)
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
echo $errmsg | grep "not mounted"
|
||||
if [ $? -eq 1 ]
|
||||
then
|
||||
printf "*****Warning: unmount failed rc=$rc\n" >&2
|
||||
let err=err+1
|
||||
fi
|
||||
fi
|
||||
rm -fr $localdir
|
||||
|
||||
return $err
|
||||
}
|
||||
|
||||
|
||||
# unplug all unused scsi device under /dev/sd*
|
||||
unplug_unused_scsi_by_sid() { # sid
|
||||
local rc=0
|
||||
# clean LUN without disk map
|
||||
local session=session$1
|
||||
local targets=$(ls /sys/class/iscsi_session/$session/device/ -1 | grep target)
|
||||
if [ -z "$targets" ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
for target in $targets
|
||||
do
|
||||
local luns=$(ls /sys/class/iscsi_session/$session/device/$target/ | grep :)
|
||||
if [ -z "$luns" ]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
for lun in $luns
|
||||
do
|
||||
local disk=$(ls /sys/class/iscsi_session/$session/device/$target/$lun/ | grep "block:" | cut -d: -f2)
|
||||
if [ -z "$disk" ]
|
||||
then
|
||||
echo 1 > /sys/class/iscsi_session/$session/device/$target/$lun/delete
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: fail to delete lun $lun\n" >&2
|
||||
else
|
||||
printf "*****Info: succeed to delete lun $lun\n" >&2
|
||||
fi
|
||||
else
|
||||
local lu=$(scsi_id -g -s /block/$disk)
|
||||
if [ -z "$lu" ]
|
||||
then
|
||||
temp=$(ls -l /dev/disk/by-vm | grep "$disk$")
|
||||
if [ -z "$temp" ]
|
||||
then
|
||||
unplug_scsi_by_disk $disk
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
return $err
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
hflag=
|
||||
rflag=
|
||||
lflag=
|
||||
uflag=
|
||||
mflag=
|
||||
nflag=
|
||||
tflag=
|
||||
dflag=
|
||||
bflag=
|
||||
tgtname=
|
||||
swpname=
|
||||
datatgtname=
|
||||
bootloader='PyGrub'
|
||||
DISKDIR="/dev/disk/by-vm"
|
||||
|
||||
while getopts 'umxw:t:n:h:r:l:1:b:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
h) hflag=1
|
||||
iscsitgthost="$OPTARG"
|
||||
;;
|
||||
r) rflag=1
|
||||
remotedir="$OPTARG"
|
||||
;;
|
||||
t) tflag=1
|
||||
tgtname="$OPTARG"
|
||||
;;
|
||||
w) wflag=1
|
||||
swpname="$OPTARG"
|
||||
;;
|
||||
l) lflag=1
|
||||
localdir="$OPTARG"
|
||||
;;
|
||||
1) dflag=1
|
||||
datatgtname="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
vmname="$OPTARG"
|
||||
;;
|
||||
b) bflag=1
|
||||
bootloader="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
;;
|
||||
m) mflag=1
|
||||
;;
|
||||
x) set -x
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
bootloader=$(echo $bootloader | tr '[A-Z]' '[a-z]')
|
||||
|
||||
if [ "$hflag$rflag$lflag$nflag$tflag" != "11111" ] && [ "$uflag$lflag$nflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ "$uflag$mflag" != "1" ] && [ "$uflag$mflag" != "" ]
|
||||
then
|
||||
printf "***Specify one of -u (unmount) or -m (mount)\n" >&2
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ "$uflag" == "1" ]
|
||||
then
|
||||
unmount_all $localdir $vmname
|
||||
rc=$?
|
||||
exit $rc
|
||||
fi
|
||||
|
||||
#create the local dir if necessary
|
||||
if ! mkdir -p $localdir
|
||||
then
|
||||
printf "***Unable to create local directory, exiting\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#create disk directory if needed
|
||||
if [ ! -d $DISKDIR ]
|
||||
then
|
||||
mkdir $DISKDIR
|
||||
fi
|
||||
|
||||
#check if the iscsi target portal is up and running
|
||||
if ! check_iscsi_server "$iscsitgthost" 4
|
||||
then
|
||||
printf "***Unable to ping the iscsi target host $iscsitgthost, exiting\n" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
if [ "$bootloader" == "external" ]
|
||||
then
|
||||
#mount the local dir (for kernel, ramdisk, etc)
|
||||
mount -t nfs $iscsitgthost:$remotedir $localdir -o intr,rsize=32768,wsize=32768,hard
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to mount $remotedir at $localdir\n" >&2
|
||||
exit 4
|
||||
fi
|
||||
fi
|
||||
|
||||
do_iscsi_login $tgtname $iscsitgthost
|
||||
rootsid=$?
|
||||
if [ $rootsid -lt 0 ]
|
||||
then
|
||||
printf "***Failed to login to $tgtname at $iscsitgthost\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 5
|
||||
fi
|
||||
sleep 1
|
||||
|
||||
swapsid=
|
||||
if [ -n "$swpname" ]
|
||||
then
|
||||
do_iscsi_login $swpname $iscsitgthost
|
||||
swapsid=$?
|
||||
if [ $swapsid -lt 0 ]
|
||||
then
|
||||
printf "***Failed to login to $swapname at $iscsitgthost\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 6
|
||||
fi
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
datasid=
|
||||
if [ -n "$datatgtname" ]
|
||||
then
|
||||
do_iscsi_login $datatgtname $iscsitgthost
|
||||
datasid=$?
|
||||
if [ $datasid -lt 0 ]
|
||||
then
|
||||
printf "***Failed to login to $datatgtname at $iscsitgthost\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 7
|
||||
fi
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
#figure out the device number and make a softlink
|
||||
rootdev=$(get_device_links $rootsid $tgtname root)
|
||||
if [ "$rootdev" == "" ]
|
||||
then
|
||||
printf "***Failed to get device links for $tgtname\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 8
|
||||
fi
|
||||
|
||||
ln -s /dev/$rootdev $DISKDIR/$vmname-root
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "***Failed to create softlink from /dev/$rootdev to $DISKDIR/$vmname-root\n" >&2
|
||||
exit 9
|
||||
fi
|
||||
|
||||
printf "$DISKDIR/$vmname-root = $rootdev"
|
||||
|
||||
swapdev=
|
||||
if [ -n "$swpname" ]
|
||||
then
|
||||
swapdev=$(get_device_links $swapsid $swpname swap)
|
||||
if [ "$swapdev" == "" ]
|
||||
then
|
||||
printf "***Failed to get device links for $swapname\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 9
|
||||
fi
|
||||
ln -s /dev/$swapdev $DISKDIR/$vmname-swap
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "***Failed to create softlink from /dev/$swapdev to $DISKDIR/$vmname-swap\n" >&2
|
||||
exit 10
|
||||
fi
|
||||
printf "$DISKDIR/$vmname-swap = $swapdev"
|
||||
fi
|
||||
|
||||
datadev=
|
||||
if [ -n "$datatgtname" ]
|
||||
then
|
||||
datadev=$(get_device_links $datasid $datatgtname data)
|
||||
if [ "$datadev" == "" ]
|
||||
then
|
||||
printf "***Failed to get device links for $datatgtname\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 10
|
||||
fi
|
||||
ln -s /dev/$datadev $DISKDIR/$vmname-datadisk-1
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
printf "***Failed to create softlink from /dev/$datadev to $DISKDIR/$vmanme-datadisk-1\n" >&2
|
||||
exit 11
|
||||
fi
|
||||
printf "$DISKDIR/$vmname-datadisk-1 = $datadev"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,51 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: get_iqn.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/get_iqn.sh $
|
||||
# get_iqn.sh -- return iSCSI iqn of initiator (Linux) or target (OpenSolaris)
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
linux() {
|
||||
uname -a | grep "Linux" > /dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
opensolaris() {
|
||||
uname -a | grep "SunOS" > /dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
hosted() {
|
||||
uname -a | grep "101b" > /dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
if [ $# -ne 0 ]
|
||||
then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if linux
|
||||
then
|
||||
initiator_iqn=$(cat /etc/iscsi/initiatorname.iscsi | cut -d'=' -f2)
|
||||
printf "%s\n" $initiator_iqn
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if opensolaris && hosted
|
||||
then
|
||||
printf "unique_iqn_per_zvol\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if opensolaris
|
||||
then
|
||||
tgt_iqn=$(itadm list-target | tail -1 | awk '{print $1}')
|
||||
printf "%s\n" $tgt_iqn
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf "Unexpected operating system!\n" >&2
|
||||
exit 2
|
||||
@ -1,157 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: iscsi_common.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/iscsi_common.sh $
|
||||
# iscsi_common.sh -- mount volume from ISCSI server
|
||||
#
|
||||
#
|
||||
|
||||
# check if server is up and running
|
||||
check_iscsi_server() {
|
||||
local pings=1
|
||||
while ! ping -c 1 -n -q $1 > /dev/null && [ $pings -ne $2 ]
|
||||
do
|
||||
let pings=pings+1
|
||||
done
|
||||
|
||||
printf "##check_iscsi_server: number of pings=$pings\n"
|
||||
[ $pings -eq $2 ] && return 1
|
||||
return 0;
|
||||
}
|
||||
|
||||
do_iscsi_login () {
|
||||
local rc=0
|
||||
#create a record in the client database
|
||||
iscsiadm -m node -T $1 -p $2 -o new
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to create ISCSI initiator record for target rc=$rc\n" >&2
|
||||
return 6
|
||||
fi
|
||||
# do not autologin upon restart
|
||||
iscsiadm -m node -T $1 -p $2 -o update -n node.startup -v manual
|
||||
|
||||
#login to the target
|
||||
iscsiadm -m node -T $1 -p $2 -l
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to login to target, rc=$rc\n" >&2
|
||||
return 7
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
get_device_links() {
|
||||
local n=20
|
||||
local dev=
|
||||
local host=$1
|
||||
local iqn=$2
|
||||
local disktype=$3
|
||||
while [ -z "$dev" -a $n -gt 0 ]
|
||||
do
|
||||
sleep 3;
|
||||
let n=n-1;
|
||||
dev=$(ls -l /dev/disk/by-path/ip-$host*$iqn*| awk '{print $NF}' | awk -F"/" '{print $NF}' | head -1)
|
||||
done
|
||||
|
||||
if [ $n -eq 0 ]
|
||||
then
|
||||
printf "****Timed out waiting for $disktype device to register**\n"
|
||||
fi
|
||||
printf "$dev\n"
|
||||
}
|
||||
|
||||
do_iscsi_logout() {
|
||||
local rc=0
|
||||
if [ "$1" == "" ]
|
||||
then
|
||||
return $rc
|
||||
fi
|
||||
iscsiadm -m node -T $1 -u #logout
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to logout of $1 rc=$rc\n"
|
||||
fi
|
||||
iscsiadm -m node -T $1 -o delete #delete record from db
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to delete iscsi record $1 rc=$rc\n"
|
||||
fi
|
||||
return $rc
|
||||
}
|
||||
|
||||
# unmount a local directory and all data disks within
|
||||
unmount_all() {
|
||||
local rc=0
|
||||
local err=0
|
||||
local localdir=$1
|
||||
local vmname=$2
|
||||
local disks=$(ls -l $DISKDIR | grep $vmname | awk '{print $NF}') #/dev/sdb
|
||||
for d in $disks ;
|
||||
do
|
||||
disknum=$(echo $d | awk -F"/" '{print $NF}') #sdb
|
||||
tgt=$(ls -l /dev/disk/by-path | grep -w $disknum | awk '{print $(NF-2)}' | grep -v part | cut -d: -f2- | cut -d- -f3-)
|
||||
softlink=$(ls -l $DISKDIR |grep $vmname| grep $d | awk '{print $(NF-2)}') #vmname-root or vmname-swap or vmname-data
|
||||
rm $DISKDIR/$softlink #delete soft link
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to delete $DISKDIR/$softlink rc=$rc\n"
|
||||
let err=err+1
|
||||
fi
|
||||
do_iscsi_logout $tgt
|
||||
let err=err+$?
|
||||
done
|
||||
|
||||
#unmount the image filesystem from nfs
|
||||
local errmsg=$(umount $localdir 2>&1)
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
echo $errmsg | grep "not mounted"
|
||||
if [ $? -eq 1 ]
|
||||
then
|
||||
printf "*****Warning: unmount failed rc=$rc\n"
|
||||
let err=err+1
|
||||
fi
|
||||
fi
|
||||
rm -fr $localdir
|
||||
|
||||
return $err
|
||||
}
|
||||
|
||||
#find the block device for a particular vm disk
|
||||
get_blkdev() {
|
||||
local vmname=$1
|
||||
local disktype=$2
|
||||
local disk=$(ls -l $DISKDIR | grep $vmname-$disktype | awk '{print $NF}') #/dev/sdb
|
||||
echo $disk
|
||||
}
|
||||
|
||||
# unmount an iscsi disk
|
||||
unmount_disk() {
|
||||
local rc=0
|
||||
local err=0
|
||||
local vmname=$1
|
||||
local disktype=$2
|
||||
local disks=$(ls -l $DISKDIR | grep $vmname | grep $disktype | awk '{print $NF}') #/dev/sdb
|
||||
for d in $disks ;
|
||||
do
|
||||
local disknum=$(echo $d | awk -F"/" '{print $NF}') #sdb
|
||||
local tgt=$(ls -l /dev/disk/by-path | grep -w $disknum | awk '{print $(NF-2)}' | grep -v part | cut -d: -f2- | cut -d- -f3-)
|
||||
local softlink=$(ls -l $DISKDIR |grep $vmname| grep $d | awk '{print $(NF-2)}') #vmname-root or vmname-swap or vmname-data
|
||||
rm $DISKDIR/$softlink #delete soft link
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to delete $DISKDIR/$softlink rc=$rc\n"
|
||||
let err=err+1
|
||||
fi
|
||||
do_iscsi_logout $tgt
|
||||
let err=err+$?
|
||||
done
|
||||
return $err
|
||||
}
|
||||
|
||||
DISKDIR="/dev/disk/by-vm/"
|
||||
@ -1,76 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: iscsikill.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/iscsikill.sh $
|
||||
#
|
||||
# iscsikill.sh
|
||||
#
|
||||
# kill all vms with disk to a iscsi connection and log out of the iscsi connection.
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -r <iscsi session id> -t <target iqn> -p <portal> \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
rflag=
|
||||
tflag=
|
||||
pflag=0
|
||||
|
||||
while getopts 'r:t:p:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
r) rflag=1
|
||||
sessionid="$OPTARG"
|
||||
;;
|
||||
t) tflag=1
|
||||
target="$OPTARG"
|
||||
;;
|
||||
p) pflag=1
|
||||
portal="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$rflag$tflag$pflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
state=`iscsiadm -m session -r $sessionid -P 3 | grep "iSCSI Session State:" | awk '{print $NF}'`
|
||||
if [ $state == "FREE" -o $state == "FAILED" ]
|
||||
then
|
||||
for disk in `iscsiadm -m session -r $sessionid -P 3 | grep "Attached scsi disk" | awk '{print "/dev/"$4}'`
|
||||
do
|
||||
vmname=`ls -l /dev/disk/by-vm | grep $disk | grep -v datadisk | awk '{print $9}'`
|
||||
if [ "$vmname" != "" ]
|
||||
then
|
||||
vmname=${vmname%-*}
|
||||
echo "Shutting down vm: $vmname"
|
||||
xm shutdown $vmname > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "Deleting vm: $vmname"
|
||||
xm delete $vmname > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "Deleted vm: $vmname"
|
||||
else
|
||||
echo "Failed to delete vm: $vmname"
|
||||
fi
|
||||
else
|
||||
echo "Failed to shutdown vm: $vmname"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
iscsiadm -m session -r $sessionid -u
|
||||
iscsiadm -m node -T $target -p $portal -o delete
|
||||
else
|
||||
echo "session is no longer in FREE or FAILED state"
|
||||
fi
|
||||
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: iscsimon.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/iscsimon.sh $
|
||||
#
|
||||
# iscsimon.sh
|
||||
#
|
||||
# Monitor iscsi connections for failures, and stop vm's if necessary
|
||||
#
|
||||
|
||||
err=0
|
||||
for sid in `iscsiadm -m session | awk '{print $2}' | tr -d '[]'`
|
||||
do
|
||||
state=`iscsiadm -m session -r $sid -P 1 | grep "iSCSI Session State:" | awk '{print $NF}'`
|
||||
if [ $state == "FREE" -o $state == "FAILED" ]
|
||||
then
|
||||
echo "DOWN" $sid `iscsiadm -m session -r $sid -P 1 | grep Target | awk '{print $2}'` `iscsiadm -m session -r $sid -P 1 | grep "Current Portal" | awk '{print $3}'`
|
||||
err=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $err -eq 0 ]
|
||||
then
|
||||
echo "OK"
|
||||
fi
|
||||
@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: mapiscsi.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/mapiscsi.sh $
|
||||
# mapiscsi.sh -- list of active iscsi sessions and the corresponding VM
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: \n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
#set -x
|
||||
for i in $(iscsiadm -m session 2> /dev/null | awk '{print $4}')
|
||||
do
|
||||
ls -l /dev/disk/by-path/*$i* > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
disknum=$(ls -l /dev/disk/by-path/*$i*| grep -v part | awk '{print $NF}' | awk -F"/" '{print $NF}'); # sdb etc
|
||||
vm=$(ls -l /dev/disk/by-vm | grep $disknum | awk '{print $(NF-2)}')
|
||||
lasttoken=$(echo $vm | awk -F"-" '{print $NF}')
|
||||
case "$lasttoken" in
|
||||
"root");;
|
||||
"swap");;
|
||||
[0-9]) ;;
|
||||
*) vm=${vm%-*} #strip the ip address of storage host;;
|
||||
esac
|
||||
|
||||
if [[ $vm =~ ^.*datadisk.*$ ]]; then vm=${vm%-*}; fi
|
||||
fi
|
||||
echo $i $vm
|
||||
done
|
||||
@ -1,259 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: mirror.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/mirror.sh $
|
||||
# mirror.sh -- modify a mirrored disk
|
||||
#
|
||||
#
|
||||
|
||||
dir=$(dirname $0)
|
||||
. $dir/iscsi_common.sh
|
||||
. $dir/mirror_common.sh
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: -m -h <iscsi-target-host> -t <root disk target-name> -w <swap disk target name> -n <vm-name> \n" $(basename $0) >&2
|
||||
printf "Usage: %s: -m -h <iscsi-target-host> -d <data disk target-name> -c <disk num> -n <vm-name> \n" $(basename $0) >&2
|
||||
printf "Usage: %s: -u -h <iscsi-target-host> -T -W -n <vm-name> \n" $(basename $0) >&2
|
||||
printf "Usage: %s: -u -h <iscsi-target-host> -D -c <disknum> -n <vm-name> \n" $(basename $0) >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
login() {
|
||||
local vmname=$1
|
||||
local iqn=$2
|
||||
local host=$3
|
||||
do_iscsi_login $iqn $host
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to login to $iqn at $host\n" >&2
|
||||
return 5
|
||||
fi
|
||||
}
|
||||
|
||||
make_links() {
|
||||
local vmname=$1
|
||||
local host=$2
|
||||
local iqn=$3
|
||||
local disktype=$4
|
||||
blkdev=$(get_device_links $host $iqn $disktype)
|
||||
if [ "$blkdev" == "" ]
|
||||
then
|
||||
printf "***Failed to get device links for $iqn $vmname $disktype\n" >&2
|
||||
return 8
|
||||
fi
|
||||
echo "/dev/$blkdev"
|
||||
ln -s /dev/$blkdev $DISKDIR/$vmname-$disktype-$host
|
||||
return $?
|
||||
}
|
||||
|
||||
login_and_add_to_mirror() {
|
||||
local vmname=$1
|
||||
local iqn=$2
|
||||
local host=$3
|
||||
local disktype=$4
|
||||
|
||||
part_of_mirror $vmname $disktype $iqn
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
|
||||
login $vmname $iqn $host
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed ISCSI login: $disktype disk for $vmname on $host\n" >&2
|
||||
return 5
|
||||
fi
|
||||
blkdev=$(make_links $vmname $host $iqn $disktype)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
unmount_disk $vmname $disktype-$host
|
||||
printf "Failed to get block dev for $disktype disk on $host\n" >&2
|
||||
return 5
|
||||
fi
|
||||
add_disk_to_mirror $vmname $disktype $blkdev
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
unmount_disk $vmname $disktype-$host
|
||||
printf "Failed to add $disktype disk on $host to mirror for $vmname\n" >&2
|
||||
return 6
|
||||
fi
|
||||
echo $blkdev
|
||||
}
|
||||
|
||||
validate_flags() {
|
||||
if [ "$mflag" == "1" ]
|
||||
then
|
||||
if [ "$hflag$nflag" != "11" ] && [ "$Dflag$Tflag$Wflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
if [ "$dflag$cflag" != "11" ] && [ "$tflag" != "1" ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$uflag" == "1" ]
|
||||
then
|
||||
if [ "$uflag$hflag" != "11" ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$uflag$Tflag" != "11" ] && [ "$uflag$Dflag$cflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$uflag$mflag" != "1" ] || [ "$uflag$mflag" == "" ]
|
||||
then
|
||||
printf "***Specify one of -u (unmount) or -m (mount)\n" >&2
|
||||
usage
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
hflag=
|
||||
uflag=
|
||||
mflag=
|
||||
nflag=
|
||||
cflag=
|
||||
tflag=
|
||||
Dflag=
|
||||
Tflag=
|
||||
Wflag=
|
||||
rootname=
|
||||
swpname=
|
||||
dataname=
|
||||
disknum=
|
||||
datadisk=
|
||||
|
||||
#set -x
|
||||
|
||||
|
||||
while getopts 'umw:t:n:h:d:c:TWD' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
h) hflag=1
|
||||
tgthost="$OPTARG"
|
||||
;;
|
||||
t) tflag=1
|
||||
rootname="$OPTARG"
|
||||
;;
|
||||
T) Tflag=1
|
||||
;;
|
||||
w) wflag=1
|
||||
swpname="$OPTARG"
|
||||
;;
|
||||
W) Wflag=1
|
||||
;;
|
||||
d) dflag=1
|
||||
dataname="$OPTARG"
|
||||
;;
|
||||
c) cflag=1
|
||||
disknum="$OPTARG"
|
||||
datadisk=datadisk-$disknum
|
||||
;;
|
||||
D) Dflag=1
|
||||
;;
|
||||
n) nflag=1
|
||||
vmname="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
;;
|
||||
m) mflag=1
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
validate_flags
|
||||
|
||||
#create disk directory if needed
|
||||
if [ ! -d $DISKDIR ];
|
||||
then
|
||||
mkdir $DISKDIR
|
||||
fi
|
||||
|
||||
if [ "$uflag" == "1" ] #unmount
|
||||
then
|
||||
if [ "$Tflag" == "1" ] #root disk
|
||||
then
|
||||
disk=$(get_blkdev $vmname root-$tgthost)
|
||||
remove_disk_from_mirror $vmname root $disk
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]
|
||||
then
|
||||
unmount_disk $vmname root-$tgthost
|
||||
rc=$?
|
||||
fi
|
||||
fi
|
||||
if [ "$Wflag" == "1" ] #swap disk
|
||||
then
|
||||
disk=$(get_blkdev $vmname swap-$tgthost)
|
||||
remove_disk_from_mirror $vmname swap $disk
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]
|
||||
then
|
||||
unmount_disk $vmname swap-$tgthost
|
||||
rc=$?
|
||||
fi
|
||||
fi
|
||||
if [ "$Dflag" == "1" ] #data disk
|
||||
then
|
||||
disk=$(get_blkdev $vmname $datadisk-$tgthost)
|
||||
remove_disk_from_mirror $vmname $datadisk $disk
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]
|
||||
then
|
||||
unmount_disk $vmname $datadisk-$tgthost
|
||||
rc=$?
|
||||
fi
|
||||
fi
|
||||
exit $rc
|
||||
fi
|
||||
|
||||
# rest of the script deals with mounting and adding a disk
|
||||
|
||||
#check if the iscsi target portal is up and running
|
||||
if ! check_iscsi_server "$tgthost" 4
|
||||
then
|
||||
printf "***Unable to ping the iscsi target host $tgthost, exiting\n" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
if [ -n "$rootname" ]
|
||||
then
|
||||
rootdev=$(login_and_add_to_mirror $vmname $rootname $tgthost root)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 5
|
||||
fi
|
||||
if [ -n "$swpname" ]
|
||||
then
|
||||
swapdev=$(login_and_add_to_mirror $vmname $swpname $tgthost swap)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
# undo the root disk configuration
|
||||
remove_disk_from_mirror $vmname root $rootdev
|
||||
unmount_disk $vmname root-$tgthost
|
||||
unmount_disk $vmname swap-$tgthost
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
if [ -n "$dataname" ]
|
||||
then
|
||||
datadev=$(login_and_add_to_mirror $vmname $dataname $tgthost $datadisk)
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,101 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: mirror_common.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/mirror_common.sh $
|
||||
# mirror_common.sh -- md operations
|
||||
#
|
||||
#
|
||||
export MDADM_NO_UDEV=1
|
||||
# build a mirror of 2 disks
|
||||
# $1 = vm name
|
||||
# $2 = disk type (root/swap/data)
|
||||
# $3 = block device #1 (/dev/sdX)
|
||||
# $4 = block device #2 (/dev/sdX)
|
||||
build_mirror() {
|
||||
local vmname=$1
|
||||
local disktype=$2
|
||||
local bd1=$3
|
||||
local bd2=$4
|
||||
mkdir -p /var/md
|
||||
mkdir -p /dev/md
|
||||
mdadm --build /dev/md/$vmname-$disktype --level=mirror --raid-devices=2 $bd1 $bd2 --assume-clean -b /var/md/$vmname-$disktype
|
||||
return $?
|
||||
}
|
||||
|
||||
# stop a mirror of 2 disks
|
||||
# $1 = vm name
|
||||
# $2 = disk type (root/swap/data)
|
||||
stop_mirror () {
|
||||
local vmname=$1
|
||||
local disktype=$2
|
||||
mdadm --stop /dev/md/$vmname-$disktype
|
||||
rm -f /var/md/$vmname-$disktype
|
||||
rm -f /dev/md/$vmname-$disktype
|
||||
return $?
|
||||
}
|
||||
|
||||
|
||||
# remove one disk of a mirrored pair
|
||||
# $1 = vm name
|
||||
# $2 = disk type (root/swap/data)
|
||||
# $3 = block device to remove
|
||||
remove_disk_from_mirror() {
|
||||
local vmname=$1
|
||||
local disktype=$2
|
||||
local bd=$3
|
||||
mdadm /dev/md/$vmname-$disktype --fail $bd
|
||||
local rc=$?
|
||||
local i=0
|
||||
while [ $rc -gt 0 -a $i -lt 5 ] #sometimes get device busy
|
||||
do
|
||||
sleep 2;
|
||||
mdadm /dev/md/$vmname-$disktype --fail $bd
|
||||
rc=$?
|
||||
let i=i+1
|
||||
done
|
||||
i=0
|
||||
mdadm /dev/md/$vmname-$disktype --remove $bd
|
||||
rc=$?
|
||||
while [ $rc -gt 0 -a $i -lt 5 ] #sometimes get device busy
|
||||
do
|
||||
sleep 2;
|
||||
mdadm /dev/md/$vmname-$disktype --remove $bd
|
||||
rc=$?
|
||||
let i=i+1
|
||||
done
|
||||
return $?
|
||||
}
|
||||
|
||||
# add one disk to a mirrored set
|
||||
# $1 = vm name
|
||||
# $2 = disk type (root/swap/data)
|
||||
# $3 = block device to add
|
||||
add_disk_to_mirror() {
|
||||
local vmname=$1
|
||||
local disktype=$2
|
||||
local bd=$3
|
||||
mdadm /dev/md/$vmname-$disktype --add $bd
|
||||
return $?
|
||||
}
|
||||
|
||||
# is iscsi disk part of the mirror already?
|
||||
# $1 = vm name
|
||||
# $2 = disk type (root/swap/data)
|
||||
# $3 = iqn of the iscsi disk
|
||||
part_of_mirror() {
|
||||
local vmname=$1
|
||||
local disktype=$2
|
||||
local iqn=$3
|
||||
local mdisks=$(mdadm --detail /dev/md/$vmname-$disktype | grep "/dev/sd" | awk '{print $NF}')
|
||||
local idisk=$(ls -al /dev/disk/by-path/ | grep -v part | grep $iqn | awk '{print $NF}' )
|
||||
idisk=${idisk##*/} #strip everything till last slash
|
||||
for md in $mdisks
|
||||
do
|
||||
md=${md##*/}
|
||||
if [ "$md" == "$idisk" ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
@ -1,181 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: mountdatadisk.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/mountdatadisk.sh $
|
||||
# mountdatadisk.sh -- mount/unmount data disk from ISCSI server
|
||||
#
|
||||
#
|
||||
|
||||
dir=$(dirname $0)
|
||||
. $dir/iscsi_common.sh
|
||||
. $dir/mirror_common.sh
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: [-u | -m ] -h <iscsi-target-host> -d <datadisk target name> -c <0-9> -n <vm-name>\n" $(basename $0) >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
login() {
|
||||
local vmname=$1
|
||||
local iqn=$2
|
||||
local host=$3
|
||||
do_iscsi_login $iqn $host
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to login to $iqn at $host\n" >&2
|
||||
return 5
|
||||
fi
|
||||
}
|
||||
|
||||
make_links() {
|
||||
local vmname=$1
|
||||
local host=$2
|
||||
local iqn=$3
|
||||
local disktype=$4
|
||||
|
||||
blkdev=$(get_device_links $host $iqn $disktype)
|
||||
if [ "$blkdev" == "" ]
|
||||
then
|
||||
printf "***Failed to get device links for $iqn $vmname $disktype\n" >&2
|
||||
unmount_disk $vmname $disktype
|
||||
return 8
|
||||
fi
|
||||
echo "/dev/$blkdev"
|
||||
ln -s /dev/$blkdev $DISKDIR/$vmname-$disktype-$host
|
||||
return $?
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
hflag=
|
||||
rflag=
|
||||
lflag=
|
||||
uflag=
|
||||
mflag=
|
||||
nflag=
|
||||
tflag=
|
||||
dflag=
|
||||
cflag=
|
||||
Hflag=
|
||||
Dflag=
|
||||
Mflag=
|
||||
tgtname=
|
||||
tgthost1=
|
||||
swpname=
|
||||
datatgt0=
|
||||
disknum=
|
||||
datadisk=
|
||||
datatgt1=
|
||||
DISKDIR="/dev/disk/by-vm/"
|
||||
|
||||
while getopts 'umn:h:d:c:MH:D:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
h) hflag=1
|
||||
tgthost0="$OPTARG"
|
||||
;;
|
||||
H) Hflag=1
|
||||
tgthost1="$OPTARG"
|
||||
;;
|
||||
d) dflag=1
|
||||
datatgt0="$OPTARG"
|
||||
;;
|
||||
D) Dflag=1
|
||||
datatgt1="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
vmname="$OPTARG"
|
||||
;;
|
||||
c) cflag=1
|
||||
disknum="$OPTARG"
|
||||
datadisk=datadisk-$disknum
|
||||
;;
|
||||
u) uflag=1
|
||||
;;
|
||||
m) mflag=1
|
||||
;;
|
||||
M) Mflag=1
|
||||
;;
|
||||
?) usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$hflag$nflag$cflag" != "111" ] && [ "$uflag$nflag$cflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$uflag$mflag" != "1" ]
|
||||
then
|
||||
printf "***Specify one of -u (unmount) or -m (mount)\n" >&2
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$uflag" == "1" ]
|
||||
then
|
||||
if [ "$uflag$Mflag" == "1" ]
|
||||
then
|
||||
unmount_disk $vmname $datadisk
|
||||
exit $?
|
||||
elif [ "$uflag$Mflag" == "11" ]
|
||||
then
|
||||
stop_mirror $vmname $datadisk
|
||||
unmount_disk $vmname $datadisk
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
#create disk directory if needed
|
||||
if [ ! -d $DISKDIR ];
|
||||
then
|
||||
mkdir $DISKDIR
|
||||
fi
|
||||
|
||||
#check if the iscsi target portal is up and running
|
||||
if ! check_iscsi_server "$tgthost0" 4
|
||||
then
|
||||
printf "***Unable to ping the iscsi target host $tgthost0, exiting\n" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
login $vmname $datatgt0 $tgthost0
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 5
|
||||
fi
|
||||
|
||||
#figure out the device number and make a softlink
|
||||
datadev0=$(make_links $vmname $tgthost0 $datatgt0 $datadisk )
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
exit 6
|
||||
fi
|
||||
|
||||
login $vmname $datatgt1 $tgthost1
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
unmount_disk $vmname $datadisk
|
||||
exit 5
|
||||
fi
|
||||
|
||||
datadev1=$(make_links $vmname $tgthost1 $datatgt1 $datadisk )
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
unmount_disk $vmname $datadisk
|
||||
exit 6
|
||||
fi
|
||||
|
||||
if [ "$Mflag" == "1" ]
|
||||
then
|
||||
build_mirror $vmname $datadisk $datadev0 $datadev1
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
unmount_disk $vmname $datadisk
|
||||
exit 7
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,235 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: mountrootdisk.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/mountrootdisk.sh $
|
||||
# mountrootdisk.sh -- mount image directory from NFS and ISCSI server
|
||||
#
|
||||
#
|
||||
|
||||
dir=$(dirname $0)
|
||||
. $dir/iscsi_common.sh
|
||||
. $dir/mirror_common.sh
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: [-u | -m ] -h <iscsi-target-host> -r <remote-dir> -t <root disk target-name> -w <swap disk target name> -l <local dir> -n <vm-name> -b <bootloader> [-M -H <mirror-host> -T <mirror-disk-root-target> -W <mirror-swap-disk-target>]\n" $(basename $0) >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
login() {
|
||||
local vmname=$1
|
||||
local iqn=$2
|
||||
local host=$3
|
||||
local localdir=$4
|
||||
do_iscsi_login $iqn $host
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to login to $iqn at $host\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 5
|
||||
fi
|
||||
}
|
||||
|
||||
make_links() {
|
||||
local vmname=$1
|
||||
local host=$2
|
||||
local iqn=$3
|
||||
local disktype=$4
|
||||
local localdir=$5
|
||||
blkdev=$(get_device_links $host $iqn $disktype)
|
||||
if [ "$blkdev" == "" ]
|
||||
then
|
||||
printf "***Failed to get device links for $iqn $vmname $disktype\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 8
|
||||
fi
|
||||
echo "/dev/$blkdev"
|
||||
ln -s /dev/$blkdev $DISKDIR/$vmname-$disktype-$host
|
||||
return $?
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
hflag=
|
||||
rflag=
|
||||
lflag=
|
||||
uflag=
|
||||
mflag=
|
||||
nflag=
|
||||
tflag=
|
||||
bflag=
|
||||
Mflag=
|
||||
Tflag=
|
||||
Wflag=
|
||||
rootname=
|
||||
swpname=
|
||||
rootmirror=
|
||||
swpmirror=
|
||||
tgthost=
|
||||
tgtmirror=
|
||||
bootloader="PyGrub"
|
||||
|
||||
while getopts 'umxw:t:n:h:H:r:l:T:W:Mb:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
h) hflag=1
|
||||
tgthost="$OPTARG"
|
||||
;;
|
||||
H) Hflag=1
|
||||
tgtmirror="$OPTARG"
|
||||
;;
|
||||
r) rflag=1
|
||||
remotedir="$OPTARG"
|
||||
;;
|
||||
t) tflag=1
|
||||
rootname="$OPTARG"
|
||||
;;
|
||||
T) Tflag=1
|
||||
rootmirror="$OPTARG"
|
||||
;;
|
||||
b) bflag=1
|
||||
bootloader="$OPTARG"
|
||||
;;
|
||||
w) wflag=1
|
||||
swpname="$OPTARG"
|
||||
;;
|
||||
W) Wflag=1
|
||||
swpmirror="$OPTARG"
|
||||
;;
|
||||
l) lflag=1
|
||||
localdir="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
vmname="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
;;
|
||||
m) mflag=1
|
||||
;;
|
||||
M) Mflag=1
|
||||
;;
|
||||
x) set -x
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$hflag$rflag$lflag$nflag$tflag" != "11111" ] && [ "$uflag$lflag$nflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$uflag$mflag" != "1" ]
|
||||
then
|
||||
printf "***Specify one of -u (unmount) or -m (mount)\n" >&2
|
||||
usage
|
||||
fi
|
||||
|
||||
|
||||
if [ "$uflag" == "1" ]
|
||||
then
|
||||
if [ "$Mflag$uflag" == "1" ]
|
||||
then
|
||||
unmount_all $localdir $vmname
|
||||
rc=$?
|
||||
exit $rc
|
||||
elif [ "$Mflag$uflag" == "11" ]
|
||||
then
|
||||
stop_mirror $vmname root
|
||||
rc=$?
|
||||
stop_mirror $vmname swap
|
||||
unmount_all $localdir $vmname
|
||||
rc=$?
|
||||
exit $rc
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
#create the local dir if necessary
|
||||
if ! mkdir -p $localdir
|
||||
then
|
||||
printf "***Unable to create local directory, exiting\n" >&2
|
||||
fi
|
||||
|
||||
#create disk directory if needed
|
||||
if [ ! -d $DISKDIR ];
|
||||
then
|
||||
mkdir $DISKDIR
|
||||
fi
|
||||
|
||||
#check if the iscsi target portal is up and running
|
||||
if ! check_iscsi_server "$tgthost" 4
|
||||
then
|
||||
printf "***Unable to ping the iscsi target host $tgthost, exiting\n" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
if [ "$Mflag" == 1 ]
|
||||
then
|
||||
if ! check_iscsi_server "$tgtmirror" 4
|
||||
then
|
||||
printf "***Unable to ping the iscsi target host $tgtmirror, exiting\n" >&2
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
|
||||
bootloader=$(echo $bootloader | tr [A-Z] [a-z])
|
||||
if [ "$bootloader" == "external" ]
|
||||
then
|
||||
#mount the local dir (for kernel, ramdisk, etc)
|
||||
mount -t nfs $tgthost:$remotedir $localdir -o intr,rsize=32768,wsize=32768,hard
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to mount $remotedir at $localdir\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
fi
|
||||
|
||||
login $vmname $rootname $tgthost $localdir
|
||||
sleep 1
|
||||
|
||||
if [ -n "$swpname" ]
|
||||
then
|
||||
login $vmname $swpname $tgthost $localdir
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
if [ -n "$rootmirror" ]
|
||||
then
|
||||
login $vmname $rootmirror $tgtmirror $localdir
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
if [ -n "$swpmirror" ]
|
||||
then
|
||||
login $vmname $swpmirror $tgtmirror $localdir
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
#figure out the device number and make a softlink
|
||||
root0dev=$(make_links $vmname $tgthost $rootname root $localdir)
|
||||
|
||||
if [ -n "$swpname" ]
|
||||
then
|
||||
swap0dev=$(make_links $vmname $tgthost $swpname swap $localdir)
|
||||
fi
|
||||
|
||||
if [ -n "$rootmirror" ]
|
||||
then
|
||||
root1dev=$(make_links $vmname $tgtmirror $rootmirror root $localdir)
|
||||
fi
|
||||
|
||||
if [ -n "$swpmirror" ]
|
||||
then
|
||||
swap1dev=$(make_links $vmname $tgtmirror $swpmirror swap $localdir)
|
||||
fi
|
||||
|
||||
if [ "$Mflag" == "1" ]
|
||||
then
|
||||
build_mirror $vmname root $root0dev $root1dev
|
||||
if [ "$swap0dev" ]
|
||||
then
|
||||
build_mirror $vmname swap $swap0dev $swap1dev
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@ -1,302 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: mountvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/iscsi/mountvm.sh $
|
||||
# mountvm.sh -- mount image directory from NFS and ISCSI server
|
||||
#
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: [-u | -m ] -h <iscsi-target-host> -r <remote-dir> -t <root disk target-name> -w <swap disk target name> -1 <datadisk target name> -l <local dir> -n <vm-name>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
# check if server is up and running
|
||||
check_iscsi_server() {
|
||||
local pings=1
|
||||
while ! ping -c 1 -n -q $1 > /dev/null && [ $pings -ne $2 ]
|
||||
do
|
||||
let pings=pings+1
|
||||
done
|
||||
|
||||
printf "##check_iscsi_server: number of pings=$pings\n"
|
||||
[ $pings -eq $2 ] && return 1
|
||||
return 0;
|
||||
}
|
||||
|
||||
do_iscsi_login () {
|
||||
local rc=0
|
||||
#create a record in the client database
|
||||
iscsiadm -m node -T $1 -p $2 -o new
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to create ISCSI initiator record for target rc=$rc\n" >&2
|
||||
return 6
|
||||
fi
|
||||
# do not autologin upon restart
|
||||
iscsiadm -m node -T $1 -p $2 -o update -n node.startup -v manual
|
||||
|
||||
#login to the target
|
||||
iscsiadm -m node -T $1 -p $2 -l
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "Failed to login to target, rc=$rc\n" >&2
|
||||
return 7
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
get_device_links() {
|
||||
local n=20
|
||||
local dev=
|
||||
while [ -z "$dev" -a $n -gt 0 ]
|
||||
do
|
||||
sleep 3;
|
||||
let n=n-1;
|
||||
dev=$(ls -l /dev/disk/by-path/ip-$1*$2*| awk '{print $NF}' | awk -F"/" '{print $NF}' | head -1)
|
||||
done
|
||||
|
||||
if [ $n -eq 0 ]
|
||||
then
|
||||
printf "****Timed out waiting for $3 device to register**\n"
|
||||
fi
|
||||
printf "$dev\n"
|
||||
}
|
||||
|
||||
do_iscsi_logout() {
|
||||
local rc=0
|
||||
if [ "$1" == "" ]
|
||||
then
|
||||
return $rc
|
||||
fi
|
||||
iscsiadm -m node -T $1 -u #logout
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to logout of $1 rc=$rc\n"
|
||||
fi
|
||||
iscsiadm -m node -T $1 -o delete #delete record from db
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to delete iscsi record $1 rc=$rc\n"
|
||||
fi
|
||||
return $rc
|
||||
}
|
||||
|
||||
# unmount a local directory and all data disks within
|
||||
unmount_all() {
|
||||
local rc=0
|
||||
local err=0
|
||||
local localdir=$1
|
||||
local vmname=$2
|
||||
local disks=$(ls -l $DISKDIR | grep $vmname | awk '{print $NF}') #/dev/sdb
|
||||
for d in $disks ;
|
||||
do
|
||||
disknum=$(echo $d | awk -F"/" '{print $NF}') #sdb
|
||||
tgt=$(ls -l /dev/disk/by-path | grep -w $disknum | awk '{print $(NF-2)}' | grep -v part | cut -d: -f2- | cut -d- -f3-)
|
||||
softlink=$(ls -l $DISKDIR |grep $vmname| grep $d | awk '{print $(NF-2)}') #vmname-root or vmname-swap or vmname-data
|
||||
rm $DISKDIR/$softlink #delete soft link
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: failed to delete $DISKDIR/$softlink rc=$rc\n"
|
||||
let err=err+1
|
||||
fi
|
||||
do_iscsi_logout $tgt
|
||||
let err=err+$?
|
||||
done
|
||||
|
||||
#unmount the image filesystem from nfs
|
||||
umount $localdir >&2 #ignore errors
|
||||
rc=$?
|
||||
if [ $rc -gt 0 ]
|
||||
then
|
||||
printf "*****Warning: unmount failed rc=$rc\n"
|
||||
let err=err+1
|
||||
fi
|
||||
rm -fr $localdir
|
||||
|
||||
return $err
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
hflag=
|
||||
rflag=
|
||||
lflag=
|
||||
uflag=
|
||||
mflag=
|
||||
nflag=
|
||||
tflag=
|
||||
dflag=
|
||||
tgtname=
|
||||
swpname=
|
||||
datatgtname=
|
||||
DISKDIR="/dev/disk/by-vm/"
|
||||
|
||||
while getopts 'umxw:t:n:h:r:l:1:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
h) hflag=1
|
||||
iscsitgthost="$OPTARG"
|
||||
;;
|
||||
r) rflag=1
|
||||
remotedir="$OPTARG"
|
||||
;;
|
||||
t) tflag=1
|
||||
tgtname="$OPTARG"
|
||||
;;
|
||||
w) wflag=1
|
||||
swpname="$OPTARG"
|
||||
;;
|
||||
l) lflag=1
|
||||
localdir="$OPTARG"
|
||||
;;
|
||||
1) dflag=1
|
||||
datatgtname="$OPTARG"
|
||||
;;
|
||||
n) nflag=1
|
||||
vmname="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
;;
|
||||
m) mflag=1
|
||||
;;
|
||||
x) set -x
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$hflag$rflag$lflag$nflag$tflag" != "11111" ] && [ "$uflag$lflag$nflag" != "111" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ "$uflag$mflag" != "1" ] && [ "$uflag$mflag" != "" ]
|
||||
then
|
||||
printf "***Specify one of -u (unmount) or -m (mount)\n" >&2
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ "$uflag" == "1" ]
|
||||
then
|
||||
unmount_all $localdir $vmname
|
||||
rc=$?
|
||||
do_iscsi_logout $tgtname #ignore error, tgtname could be null
|
||||
do_iscsi_logout $swpname
|
||||
do_iscsi_logout $datatgtname
|
||||
exit $rc
|
||||
fi
|
||||
|
||||
|
||||
#create the local dir if necessary
|
||||
if ! mkdir -p $localdir
|
||||
then
|
||||
printf "***Unable to create local directory, exiting\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#create disk directory if needed
|
||||
if [ ! -d $DISKDIR ];
|
||||
then
|
||||
mkdir $DISKDIR
|
||||
fi
|
||||
|
||||
#check if the iscsi target portal is up and running
|
||||
if ! check_iscsi_server "$iscsitgthost" 4
|
||||
then
|
||||
printf "***Unable to ping the iscsi target host $iscsitgthost, exiting\n" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
#mount the local dir (for kernel, ramdisk, etc)
|
||||
mount -t nfs $iscsitgthost:$remotedir $localdir -o intr,rsize=32768,wsize=32768,hard
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to mount $remotedir at $localdir\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
do_iscsi_login $tgtname $iscsitgthost
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to login to $tgtname at $iscsitgthost\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 5
|
||||
fi
|
||||
sleep 1
|
||||
|
||||
if [ -n "$swpname" ]
|
||||
then
|
||||
do_iscsi_login $swpname $iscsitgthost
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to login to $swapname at $iscsitgthost\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 6
|
||||
fi
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
if [ -n "$datatgtname" ]
|
||||
then
|
||||
do_iscsi_login $datatgtname $iscsitgthost
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to login to $datatgtname at $iscsitgthost\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 7
|
||||
fi
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
#figure out the device number and make a softlink
|
||||
rootdev=$(get_device_links $iscsitgthost $tgtname root)
|
||||
if [ "$rootdev" == "" ]
|
||||
then
|
||||
printf "***Failed to get device links for $tgtname\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 8
|
||||
fi
|
||||
|
||||
ln -s /dev/$rootdev $DISKDIR/$vmname-root
|
||||
|
||||
swapdev=
|
||||
if [ -n "$swpname" ]
|
||||
then
|
||||
swapdev=$(get_device_links $iscsitgthost $swpname swap)
|
||||
if [ "$swapdev" == "" ]
|
||||
then
|
||||
printf "***Failed to get device links for $swapname\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 9
|
||||
fi
|
||||
ln -s /dev/$swapdev $DISKDIR/$vmname-swap
|
||||
fi
|
||||
|
||||
datadev=
|
||||
if [ -n "$datatgtname" ]
|
||||
then
|
||||
datadev=$(get_device_links $iscsitgthost $datatgtname data)
|
||||
if [ "$datadev" == "" ]
|
||||
then
|
||||
printf "***Failed to get device links for $datatgtname\n" >&2
|
||||
unmount_all $localdir $vmname
|
||||
exit 10
|
||||
fi
|
||||
ln -s /dev/$datadev $DISKDIR/$vmname-datadisk-1
|
||||
fi
|
||||
|
||||
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "***Failed to mount $tgtname at $localdir\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
|
||||
exit 0
|
||||
@ -1,142 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# $Id: mountvm.sh 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/storage/nfs/mountvm.sh $
|
||||
# mounvm.sh -- mount a remote nfs directory as the image directory
|
||||
#
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "Usage: %s: [-u | -m ] -h <nfs-host> -r <remote-dir> -l <local dir>\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
# check if server is up and running
|
||||
check_nfs_server() {
|
||||
ping -c 1 -n -q $1 > /dev/null
|
||||
return $?;
|
||||
}
|
||||
|
||||
#check if somebody else has mounted this disk
|
||||
#Only issue a warning since Solaris
|
||||
#sometimes keeps around mounts for a longer time
|
||||
check_in_use() {
|
||||
local warn=0
|
||||
local nfshost=$1
|
||||
local remotedir=$2
|
||||
warn=$(ssh -o StrictHostKeyChecking=no -i ./id_rsa root@$nfshost "showmount -a | grep $remotedir" | wc -l)
|
||||
if [ $warn -gt 1 ]
|
||||
then
|
||||
printf "!!!Warning!!!! $remotedir is already mounted by $warn other hosts: ">&2
|
||||
warn=$(ssh -o StrictHostKeyChecking=no -i ./id_rsa root@$nfshost "showmount -a | grep $remotedir" | cut -d":" -f1)
|
||||
for ips in $warn
|
||||
do
|
||||
printf "$ips, "
|
||||
done
|
||||
printf "\n"
|
||||
fi
|
||||
}
|
||||
|
||||
# unmount a local directory and all data disks within
|
||||
unmount_all() {
|
||||
local localdir=$1
|
||||
|
||||
#unmount all datadisks
|
||||
for diskfs in $(find $localdir -type d | grep datadisk)
|
||||
do
|
||||
umount $diskfs >&2 #ignore errors
|
||||
printf "Unmounting $diskfs result=$?\n"
|
||||
done
|
||||
|
||||
#unmount the root disk
|
||||
umount $localdir >&2 #ignore errors
|
||||
printf "Unmounting $localdir result=$?\n"
|
||||
}
|
||||
|
||||
#set -x
|
||||
|
||||
hflag=
|
||||
rflag=
|
||||
lflag=
|
||||
uflag=
|
||||
mflag=
|
||||
|
||||
while getopts 'umxh:r:l:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
h) hflag=1
|
||||
nfshost="$OPTARG"
|
||||
;;
|
||||
r) rflag=1
|
||||
remotedir="$OPTARG"
|
||||
;;
|
||||
l) lflag=1
|
||||
localdir="$OPTARG"
|
||||
;;
|
||||
u) uflag=1
|
||||
;;
|
||||
m) mflag=1
|
||||
;;
|
||||
x) set -x
|
||||
;;
|
||||
?) usage
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$hflag$rflag$lflag" != "111" ] && [ "$uflag$lflag" != "11" ]
|
||||
then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ "$uflag$mflag" != "1" ] && [ "$uflag$mflag" != "" ]
|
||||
then
|
||||
printf "Specify one of -u (unmount) or -m (mount)\n" >&2
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ "$uflag" == "1" ]
|
||||
then
|
||||
unmount_all $localdir
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#create the local dir if necessary
|
||||
if ! mkdir -p $localdir
|
||||
then
|
||||
printf "Unable to create local directory, exiting\n" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
#check if the nfs server is up and running
|
||||
if ! check_nfs_server $nfshost
|
||||
then
|
||||
printf "Unable to ping the nfs host, exiting\n" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
#warn if the remote disk has already been mounted by someone else
|
||||
#check_in_use $nfshost $remotedir
|
||||
|
||||
#mount the root disk
|
||||
mount -t nfs $nfshost:$remotedir $localdir -o intr,rsize=32768,wsize=32768,hard
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to mount $remotedir at $localdir\n" >&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
#mount all datadisks as well
|
||||
for diskfs in $(find $localdir -type d | grep datadisk)
|
||||
do
|
||||
disk=$(basename $diskfs)
|
||||
mount -t nfs $nfshost:$remotedir/$disk $diskfs
|
||||
if [ $? -gt 0 ]
|
||||
then
|
||||
printf "Failed to mount $remotedir/$disk at $diskfs\n" >&2
|
||||
unmount_all $localdir #undo what we did
|
||||
exit 5
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
Loading…
x
Reference in New Issue
Block a user