Exemplo n.º 1
0
def create_loadbalancer(call=None, kwargs=None):
    """
    Creates a loadbalancer within the datacenter from the provider config.

    CLI Example:

    .. code-block:: bash

        salt-cloud -f create_loadbalancer profitbricks name=mylb
    """
    if call != "function":
        raise SaltCloudSystemExit(
            "The create_address function must be called with -f or --function."
        )

    if kwargs is None:
        kwargs = {}

    conn = get_conn()
    datacenter_id = get_datacenter_id()
    loadbalancer = LoadBalancer(name=kwargs.get("name"),
                                ip=kwargs.get("ip"),
                                dhcp=kwargs.get("dhcp"))

    response = conn.create_loadbalancer(datacenter_id, loadbalancer)
    _wait_for_completion(conn, response, 60, "loadbalancer")

    return response
 def test_create_failure(self):
     try:
         self.client.create_loadbalancer(
             datacenter_id=self.datacenter['id'],
             loadbalancer=LoadBalancer())
     except PBError as e:
         self.assertIn(self.resource['missing_attribute_error'] % 'lan',
                       e.content[0]['message'])
server1 = Server(name='My New Server1',
                 ram=4096,
                 cores=4,
                 nics=nics,
                 create_volumes=[volume1])

servers = [server1]

lan1 = LAN(name='public Lan 4', public=True)

lan2 = LAN(name='public Lan 5', public=True)

lans = [lan1, lan2]

loadbalancer1 = LoadBalancer(name='LB01', ip='10.2.2.5', dhcp=False)

loadbalancers = [loadbalancer1]

d = Datacenter(name='My New Datacenter',
               description='Production environment',
               location='de/fkb',
               servers=servers,
               volumes=volumes,
               lans=lans,
               loadbalancers=loadbalancers)

response = client.create_datacenter(datacenter=d)

del_response = client.delete_datacenter(response['id'])
    def setUpClass(self):
        self.resource = resource()
        self.client = ProfitBricksService(username=configuration.USERNAME,
                                          password=configuration.PASSWORD,
                                          headers=configuration.HEADERS)

        # Create test datacenter.
        self.datacenter = self.client.create_datacenter(datacenter=Datacenter(
            **self.resource['datacenter']))
        self.client.wait_for_completion(self.datacenter)

        # Create test LAN.
        self.lan = self.client.create_lan(datacenter_id=self.datacenter['id'],
                                          lan=LAN(**self.resource['lan']))
        self.client.wait_for_completion(self.lan)

        # Create test server.
        self.server = self.client.create_server(
            datacenter_id=self.datacenter['id'],
            server=Server(**self.resource['server']))
        self.client.wait_for_completion(self.server)

        # Create test NIC1.
        nic1 = NIC(**self.resource['nic'])
        nic1.lan = self.lan['id']
        self.nic1 = self.client.create_nic(datacenter_id=self.datacenter['id'],
                                           server_id=self.server['id'],
                                           nic=nic1)
        self.client.wait_for_completion(self.nic1)

        # Create test NIC2.
        # nic2 = NIC(**self.resource['nic'])
        # nic2.lan = self.lan['id']
        # self.nic2 = self.client.create_nic(
        #     datacenter_id=self.datacenter['id'],
        #     server_id=self.server['id'],
        #     nic=nic2)
        # self.client.wait_for_completion(self.nic2)

        # Create test LoadBalancer
        loadbalancer = LoadBalancer(**self.resource['loadbalancer'])
        loadbalancer.balancednics = [self.nic1['id']]
        self.loadbalancer = self.client.create_loadbalancer(
            datacenter_id=self.datacenter['id'], loadbalancer=loadbalancer)

        self.client.wait_for_completion(self.loadbalancer)

        # Create test LoadBalancer2
        loadbalancer2 = LoadBalancer(**self.resource['loadbalancer'])
        loadbalancer2.name = "Python SDK Test 2"
        self.loadbalancer2 = self.client.create_loadbalancer(
            datacenter_id=self.datacenter['id'], loadbalancer=loadbalancer2)

        self.client.wait_for_completion(self.loadbalancer2)

        # Create test LoadBalancer3
        loadbalancer3 = LoadBalancer(**self.resource['loadbalancer'])
        loadbalancer3.balancednics = [self.nic1['id']]
        loadbalancer3.name = "Python SDK Test 3"
        self.loadbalancer3 = self.client.create_loadbalancer(
            datacenter_id=self.datacenter['id'], loadbalancer=loadbalancer3)

        self.client.wait_for_completion(self.loadbalancer3)