예제 #1
0
func getVpnUsers(client *cloudstack.CloudStackClient, domainid string, account string) []*cloudstack.VpnUser {
	vpnService := cloudstack.NewVPNService(client)
	params := vpnService.NewListVpnUsersParams()
	params.SetAccount(account)
	params.SetDomainid(domainid)
	params.SetListall(true)
	users, _ := vpnService.ListVpnUsers(params)
	return users.VpnUsers
}
예제 #2
0
func addVpnUser(client *cloudstack.CloudStackClient, username string, password string, domainid string, accountName string) {

	vpnService := cloudstack.NewVPNService(client)

	params := vpnService.NewAddVpnUserParams(password, username)
	params.SetAccount(accountName)
	params.SetDomainid(domainid)
	if _, err := vpnService.AddVpnUser(params); err != nil {
		fmt.Printf("Failed to create new remote access VPN: %s\n", err.Error())
	} else {
		fmt.Printf("Added user %s to VPN (account: %s, domainid: %s)\n", username, accountName, domainid)
	}

}
예제 #3
0
func findRemoteAccessVPN(client *cloudstack.CloudStackClient, ipAddressId string) (*cloudstack.RemoteAccessVpn, error) {

	service := cloudstack.NewVPNService(client)
	params := service.NewListRemoteAccessVpnsParams()
	params.SetPublicipid(ipAddressId)

	if vpns, err := service.ListRemoteAccessVpns(params); err != nil {
		return nil, err
	} else if vpns.Count == 1 {
		return vpns.RemoteAccessVpns[0], nil
	} else {
		return nil, nil
	}

}
예제 #4
0
func createRemoteAccessVPN(client *cloudstack.CloudStackClient, ipAddressId string, addressRange string) (*cloudstack.RemoteAccessVpn, error) {

	service := cloudstack.NewVPNService(client)
	params := service.NewCreateRemoteAccessVpnParams(ipAddressId)
	params.SetFordisplay(true)
	params.SetOpenfirewall(true)
	params.SetIprange(addressRange)

	if vpn, err := service.CreateRemoteAccessVpn(params); err != nil {
		return nil, err
	} else {
		// Keeping this at a minimum
		return &cloudstack.RemoteAccessVpn{Publicip: vpn.Publicip, Presharedkey: vpn.Presharedkey}, nil
	}

}
예제 #5
0
func removeAllVpnUsers(client *cloudstack.CloudStackClient, domainid string, accountName string) {
	fmt.Printf("--------------------------------------------------------------------------\n")
	fmt.Printf("Removing remote access VPN users for account: %s\n", accountName)
	fmt.Printf("--------------------------------------------------------------------------\n")
	vpnService := cloudstack.NewVPNService(client)
	vpnUsers := getVpnUsers(client, domainid, accountName)
	for _, vpnUser := range vpnUsers {
		params := vpnService.NewRemoveVpnUserParams(vpnUser.Username)
		params.SetAccount(accountName)
		params.SetDomainid(domainid)
		if _, err := vpnService.RemoveVpnUser(params); err != nil {
			fmt.Printf("Failed to remove remote access VPN for user %s: %s\n", vpnUser.Username, err.Error())
		} else {
			fmt.Printf("Removed remote access VPN for user %s (account: %s, domainid: %s)\n", vpnUser.Username, accountName, domainid)
		}
	}
}