首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SL中自动扩展的网络配置

SL中自动扩展的网络配置
EN

Stack Overflow用户
提问于 2016-08-10 20:03:53
回答 1查看 47关注 0票数 0

当我添加一个带有选项的组时,如何将网络组件设置为“在多个VLAN之间保持平衡”和“在缩容时保持跨VLAN的平衡”。我找不到网络组件的配置字段。

EN

回答 1

Stack Overflow用户

发布于 2016-08-11 00:05:45

第一个选项是:跨多个VLAN的平衡。如果您通过Control Portal启用此选项,它将加载购买的vlans。所以这不是旗帜。我们可以通过API来模拟这一特性,但这取决于许多因素。我会试着为这个建立一个脚本,我会让你知道任何关于它的消息。

关于如何在小规模balancedTerminationFlag,上保持跨的平衡,这是您应该在代码中设置此属性的VLAN,如下所示:

templateObject.setBalancedTerminationFlag(true);

已更新

代码语言:javascript
运行
复制
package com.softlayer.api.ScaleGroup;

import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.Account;
import com.softlayer.api.service.Location;
import com.softlayer.api.service.network.Vlan;
import com.softlayer.api.service.scale.Group;

import java.util.ArrayList;
import java.util.List;

/**
 * This script Get Vlans as Control Portal does
 *
 * Important Manual Pages:
 * http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkVlans
 *
 * @license <http://sldn.softlayer.com/article/License>
 * @authon SoftLayer Technologies, Inc. <sldn@softlayer.com>
 * @version 0.2.2 (master branch)
 */
public class GetVlans {

    List<Vlan> publicVlans = new ArrayList<Vlan>();
    List<Vlan> privateVlans = new ArrayList<Vlan>();
    public GetVlans()
    {
        // Define your SoftLayer's username and apiKey
        String username = "set me";
        String apiKey = "set me";

        /**
         * Define Region as Control Portal and datacenter name
         * e.g. for datacenter: dal05, dal06, dal09, lon02 or First Available (This option get all vlans from datacenter from the region)
         */
        String region = "na-usa-central-1";
        String datacenter = "First Available";

        // Set privateNetworkOnly and preserverBalanceAcrossVLANsOnDownscale flags
        boolean privateNetworkOnly = false;
        boolean preserverBalanceAcrossVLANsOnDownscale = false;

        // Create client and services
        ApiClient client = new RestApiClient().withCredentials(username, apiKey);
        Account.Service accountService = Account.service(client);
        Group.Service groupService = Group.service(client);
        com.softlayer.api.service.location.Group.Service locationService;

        // Define Object Masks to get additional properties
        accountService.withMask().networkVlans().subnets();
        accountService.withMask().networkVlans().billingItem();
        accountService.withMask().networkVlans().networkSpace();
        accountService.withMask().networkVlans().primaryRouter();
        accountService.withMask().networkVlans().primaryRouter().datacenter();
        accountService.withMask().networkVlans().primaryRouter().datacenter().groups();
        accountService.withMask().networkVlans().localDiskStorageCapabilityFlag();
        accountService.withMask().networkVlans().sanStorageCapabilityFlag();

        // Define init parameter for locationService
        locationService = com.softlayer.api.service.location.Group.service(client, getRegionalGroupId(groupService, region));

        try {
            /**
             * Getting Vlans
             */
            if(datacenter == "First Available")
            {
                for(Location location : locationService.getLocations())
                {
                    getVlans(accountService, groupService, region, preserverBalanceAcrossVLANsOnDownscale, location.getName());
                    printVlans(privateNetworkOnly);
                }
            }else{
                getVlans(accountService, groupService, region, preserverBalanceAcrossVLANsOnDownscale, datacenter);
                printVlans(privateNetworkOnly);
            }
        } catch (Exception e) {
            System.out.println("Error: " + e);
        }
    }

    /**
     * Retrieves rion identifier
     * @param region string
     * @return region identifier
     */
    public Long getRegionalGroupId(Group.Service groupService, String region)
    {
        Long regionId = new Long(0);
        for(com.softlayer.api.service.location.Group regionalGroup : groupService.getAvailableRegionalGroups())
        {
            if(regionalGroup.getName().equals(region))
            {
                regionId = regionalGroup.getId();
            }
        }
        return regionId;
    }

    /**
     *
     * @param accountService Account Service
     * @param groupService Group Service
     * @param region Define the region for the vlans
     * @param preserverBalanceAcrossVLANsOnDownscale Flag to get own vlans
     * @param location The location to get vlans
     */
    public void getVlans(Account.Service accountService, Group.Service groupService, String region, boolean preserverBalanceAcrossVLANsOnDownscale, String location)
    {
        publicVlans = new ArrayList<Vlan>();
        privateVlans = new ArrayList<Vlan>();
        System.out.println("Datacenter: " + location);
        for(Vlan vlan : accountService.getObject().getNetworkVlans()) {
            if (vlan.getPrimaryRouter().getDatacenter().getName().equals(location)) {
                for (com.softlayer.api.service.location.Group group : vlan.getPrimaryRouter().getDatacenter().getGroups()) {
                    if (group.getId() == getRegionalGroupId(groupService, region)) {

                        if (vlan.getNetworkSpace().equals("PUBLIC")) {
                            if (preserverBalanceAcrossVLANsOnDownscale) {
                                if (vlan.getBillingItem() != null) {
                                    publicVlans.add(vlan);
                                }
                            } else {
                                publicVlans.add(vlan);
                            }
                        } else {
                            if (vlan.getBillingItem() != null) {
                                privateVlans.add(vlan);
                            } else {
                                privateVlans.add(vlan);

                            }
                        }
                    }
                }
            }
        }
    }

    /**
     * Print Vlans
     * @param privateNetworkOnly PrivateNetworkOnly flag, to get only private vlans
     */
    public void printVlans(boolean privateNetworkOnly)
    {
        if(!privateNetworkOnly)
        {
            System.out.println("PUBLIC");
            for(Vlan vlan : publicVlans)
            {
                System.out.println("Id: " + vlan.getId() + "     Vlan Number: " + vlan.getVlanNumber() + "         Router: " + vlan.getPrimaryRouter().getHostname() +
                        "   SAN: " + vlan.getSanStorageCapabilityFlag() + "  LOCAL: " + vlan.getLocalDiskStorageCapabilityFlag());
            }
        }
        System.out.println("PRIVATE");
        for(Vlan vlan : privateVlans)
        {
            System.out.println("Id: " + vlan.getId() + "     Vlan Number: " + vlan.getVlanNumber() + "         Router: " + vlan.getPrimaryRouter().getHostname() +
                    "    SAN: " + vlan.getSanStorageCapabilityFlag() + "   LOCAL: " + vlan.getLocalDiskStorageCapabilityFlag());
        }
    }

    public static void main(String []args)
    {
        new GetVlans();
    }
}

我附加了一个java脚本来获取Vlans,就像Control Portal所做的那样,因为我认为您正在尝试自动扩展组。我希望它能帮上忙。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38872951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档