Пример #1
0
func (b *Brick) Destroy() error {
	godbc.Require(b.NodeId != "")
	godbc.Require(b.Path != "")
	godbc.Require(b.db != nil)

	// Just for now, it will work wih https://github.com/lpabon/vagrant-gfsm
	sshexec := ssh.NewSshExecWithKeyFile("vagrant", "insecure_private_key")
	godbc.Check(sshexec != nil)

	// Get node name
	var nodename string
	err := b.db.Reader(func() error {
		nodename = b.db.nodes[b.NodeId].Info.Name
		return nil
	})

	// Delete brick storage
	commands := []string{
		fmt.Sprintf("sudo umount /gluster/brick_%v", b.Id),
		fmt.Sprintf("sudo lvremove -f vg_%v/tp_%v", b.DeviceId, b.Id),
		fmt.Sprintf("sudo rmdir /gluster/brick_%v", b.Id),
	}

	_, err = sshexec.ConnectAndExec(nodename+":22", commands, nil)
	if err != nil {
		return err
	}

	err = b.FreeStorage()

	return err
}
Пример #2
0
func (v *VolumeEntry) CreateGlusterVolume() error {

	// Get node name
	var nodename string
	var cmd string

	err := v.db.Reader(func() error {
		nodename = v.db.nodes[v.State.Bricks[0].NodeId].Info.Name

		cmd = fmt.Sprintf("sudo gluster volume create %v replica %v ",
			v.Info.Name, v.State.Replica)
		for brick := range v.State.Bricks {
			cmd += fmt.Sprintf("%v:/gluster/brick_%v/brick ",
				v.db.nodes[v.State.Bricks[brick].NodeId].Info.Name, v.State.Bricks[brick].Id)
		}

		return nil
	})
	if err != nil {
		return err
	}

	// Create gluster volume command

	// :TODO: Add force for now.  It will allow silly bricks on the same systems
	// to work.  Please remove once we add the intelligent ring
	cmd += " force"

	// Just for now, it will work wih https://github.com/lpabon/vagrant-gfsm
	sshexec := ssh.NewSshExecWithKeyFile("vagrant", "insecure_private_key")
	godbc.Check(sshexec != nil)

	// Create volume
	commands := []string{
		cmd,
		fmt.Sprintf("sudo gluster volume start %v", v.Info.Name),
	}

	_, err = sshexec.ConnectAndExec(nodename+":22", commands, nil)
	if err != nil {
		return err
	}

	// Setup mount point
	v.Info.Mount = fmt.Sprintf("%v:%v", nodename, v.Info.Name)

	// State
	v.State.Created = true
	v.State.Started = true

	return nil
}
Пример #3
0
func (b *Brick) Create() error {
	godbc.Require(b.db != nil)
	godbc.Require(b.DeviceId != "")

	// Just for now, it will work wih https://github.com/lpabon/vagrant-gfsm
	sshexec := ssh.NewSshExecWithKeyFile("vagrant", "insecure_private_key")
	godbc.Check(sshexec != nil)

	var nodename string
	err := b.db.Reader(func() error {
		nodename = b.db.nodes[b.NodeId].Info.Name
		return nil
	})

	commands := []string{
		fmt.Sprintf("sudo lvcreate -L %vKiB -T vg_%v/tp_%v -V %vKiB -n brick_%v",
			//Thin Pool Size
			uint64(float64(b.Size)*THINP_SNAPSHOT_FACTOR),

			// volume group
			b.DeviceId,

			// ThinP name
			b.Id,

			// Volume size
			b.Size,

			// Logical Vol name
			b.Id),
		fmt.Sprintf("sudo mkfs.xfs -i size=512 /dev/vg_%v/brick_%v", b.DeviceId, b.Id),
		fmt.Sprintf("sudo mkdir /gluster/brick_%v", b.Id),
		fmt.Sprintf("sudo mount /dev/vg_%v/brick_%v /gluster/brick_%v",
			b.DeviceId, b.Id, b.Id),
		fmt.Sprintf("sudo mkdir /gluster/brick_%v/brick", b.Id),
	}

	_, err = sshexec.ConnectAndExec(nodename+":22", commands, nil)
	if err != nil {
		return err
	}

	// SSH into node and create brick
	b.Path = fmt.Sprintf("/gluster/brick_%v", b.Id)
	return nil
}
Пример #4
0
func (m *GlusterFSPlugin) peerProbe(name string) error {

	// Just for now, it will work wih https://github.com/lpabon/vagrant-gfsm
	sshexec := ssh.NewSshExecWithKeyFile("vagrant", "insecure_private_key")
	godbc.Check(sshexec != nil)

	// create the commands
	commands := []string{
		fmt.Sprintf("sudo gluster peer probe %v", name),
	}

	_, err := sshexec.ConnectAndExec(m.peerHost+":22", commands, nil)
	if err != nil {
		return err
	}

	return nil
}
Пример #5
0
func (v *VolumeEntry) Destroy() error {
	godbc.Require(v.db != nil)

	sshexec := ssh.NewSshExecWithKeyFile("vagrant", "insecure_private_key")
	godbc.Check(sshexec != nil)

	// Get node name
	var nodename string
	err := v.db.Reader(func() error {
		nodename = v.db.nodes[v.State.Bricks[0].NodeId].Info.Name
		return nil
	})
	if err != nil {
		return err
	}

	// Shutdown volume
	commands := []string{
		// stop gluster volume
		fmt.Sprintf("yes | sudo gluster volume stop %v force", v.Info.Name),
		fmt.Sprintf("yes | sudo gluster volume delete %v", v.Info.Name),
	}

	_, err = sshexec.ConnectAndExec(nodename+":22", commands, nil)
	if err != nil {
		return errors.New("Unable to shutdown volume")
	}

	// Destroy bricks
	var wg sync.WaitGroup
	for brick := range v.State.Bricks {
		wg.Add(1)
		go func(b int) {
			defer wg.Done()
			v.State.Bricks[b].Destroy()
		}(brick)
	}
	wg.Wait()

	return nil
}
Пример #6
0
func NewSshExecutor(config *SshConfig) *SshExecutor {
	godbc.Require(config != nil)
	godbc.Require(DEFAULT_MAX_CONNECTIONS > 1)

	s := &SshExecutor{}
	s.throttlemap = make(map[string]chan bool)

	// Set configuration
	if config.PrivateKeyFile == "" {
		s.private_keyfile = os.Getenv("HOME") + "/.ssh/id_rsa"
	} else {
		s.private_keyfile = config.PrivateKeyFile
	}

	if config.User == "" {
		s.user = "******"
	} else {
		s.user = config.User
	}
	s.config = config

	// Show experimental settings
	if s.config.RebalanceOnExpansion {
		logger.Warning("Rebalance on volume expansion has been enabled.  This is an EXPERIMENTAL feature")
	}

	// Setup key
	s.exec = ssh.NewSshExecWithKeyFile(logger, s.user, s.private_keyfile)
	if s.exec == nil {
		logger.LogError("Unable to load ssh user and private keyfile")
		return nil
	}

	godbc.Ensure(s != nil)
	godbc.Ensure(s.config == config)
	godbc.Ensure(s.user != "")
	godbc.Ensure(s.private_keyfile != "")

	return s
}