当前位置: 首页>>代码示例>>Python>>正文


Python LoadBalancerRule.create方法代码示例

本文整理汇总了Python中marvin.lib.base.LoadBalancerRule.create方法的典型用法代码示例。如果您正苦于以下问题:Python LoadBalancerRule.create方法的具体用法?Python LoadBalancerRule.create怎么用?Python LoadBalancerRule.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marvin.lib.base.LoadBalancerRule的用法示例。


在下文中一共展示了LoadBalancerRule.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_LB_Rule

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def create_LB_Rule(self, public_ip, network, vmarray, services=None):
        """Create and validate the load balancing rule"""

        self.debug("Creating LB rule for IP address: %s" %
                   public_ip.ipaddress.ipaddress)
        objservices = None
        if services:
            objservices = services
        else:
            objservices = self.services["lbrule"]

        self.services["lbrule"]["publicport"] = 22
        self.services["lbrule"]["privateport"] = 22

        lb_rule = LoadBalancerRule.create(
            self.apiclient,
            objservices,
            ipaddressid=public_ip.ipaddress.id,
            accountid=self.account.name,
            networkid=network.id,
            domainid=self.account.domainid
        )
        self.debug("Adding virtual machines %s to LB rule" % str(vmarray))
        lb_rule.assign(self.apiclient, vmarray)
        return lb_rule
开发者ID:K0zka,项目名称:cloudstack,代码行数:27,代码来源:test_haproxy.py

示例2: create_LB_Rule

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def create_LB_Rule(self, public_ip, network, vmarray, services=None):
        self.debug("Creating LB rule for IP address: %s" %
                                        public_ip.ipaddress.ipaddress)
        objservices = None
        if services:
            objservices = services
        else:
            objservices = self.services["lbrule"]

        lb_rule = LoadBalancerRule.create(
                                    self.apiclient,
                                    objservices,
                                    ipaddressid=public_ip.ipaddress.id,
                                    accountid=self.account.name,
                                    networkid=network.id,
                                    vpcid=self.vpc.id,
                                    domainid=self.account.domainid
                                )
        self.debug("Adding virtual machines %s and %s to LB rule" % (vmarray[0], vmarray[1]))
        lb_rule.assign(self.apiclient, vmarray)

        self.debug("Adding NetworkACl rules to make NAT rule accessible")
        nwacl_nat = NetworkACL.create(self.apiclient,
                                    objservices,
                                    networkid=network.id,
                                    traffictype='Ingress'
                                    )
        self.debug('nwacl_nat=%s' % nwacl_nat.__dict__)
        return lb_rule
开发者ID:MANIKANDANVEN,项目名称:cloudstack,代码行数:31,代码来源:test_vpc_network_lbrules.py

示例3: createNetworkRules

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def createNetworkRules(self, rule, ipaddressobj, networkid):
        """ Create specified rule on acquired public IP and
        default network of virtual machine
        """
        # Open up firewall port for SSH
        self.fw_rule = FireWallRule.create(
            self.apiclient,
            ipaddressid=ipaddressobj.ipaddress.id,
            protocol=self.services["fwrule"]["protocol"],
            cidrlist=['0.0.0.0/0'],
            startport=self.services["fwrule"]["startport"],
            endport=self.services["fwrule"]["endport"]
        )

        if rule == STATIC_NAT_RULE:
            StaticNATRule.enable(
                self.apiclient,
                ipaddressobj.ipaddress.id,
                self.virtual_machine.id,
                networkid
            )

        elif rule == LB_RULE:
            self.lb_rule = LoadBalancerRule.create(
                self.apiclient,
                self.services["lbrule"],
                ipaddressid=ipaddressobj.ipaddress.id,
                accountid=self.account.name,
                networkid=self.virtual_machine.nic[0].networkid,
                domainid=self.account.domainid)

            vmidipmap = [{"vmid": str(self.virtual_machine.id),
                          "vmip": str(self.virtual_machine.nic[0].ipaddress)}]

            self.lb_rule.assign(
                self.apiclient,
                vmidipmap=vmidipmap
            )
        else:
            self.nat_rule = NATRule.create(
                self.apiclient,
                self.virtual_machine,
                self.services["natrule"],
                ipaddressobj.ipaddress.id
            )
        return
开发者ID:Tosta-Mixta,项目名称:cloudstack,代码行数:48,代码来源:test_network.py

示例4: create_lbrule

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def create_lbrule(self, public_ip, network, vmarray, services=None):
        self.debug("Creating LB rule for IP address: %s" %
                                                    public_ip.ipaddress.ipaddress)
        objservices = None
        if services:
                objservices = services
        else:
                objservices = self.services["lbrule"]

        lb_rule = LoadBalancerRule.create(
                                                self.apiclient,
                                                objservices,
                                                ipaddressid=public_ip.ipaddress.id,
                                                accountid=self.account.name,
                                                networkid=network.id,
                                                vpcid=self.vpc.id,
                                                domainid=self.account.domainid
                                        )
        self.debug("Adding virtual machines %s and %s to LB rule" % (vmarray))
        lb_rule.assign(self.apiclient, vmarray)
        return lb_rule
开发者ID:abnercosta,项目名称:cloudstack,代码行数:23,代码来源:test_vpc_network_pfrules.py

示例5: test_02_create_lb_rule_non_nat

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def test_02_create_lb_rule_non_nat(self):
        """Test to create Load balancing rule with non source NAT"""

        # Validate the Following:
        # 1. listLoadBalancerRules should return the added rule
        # 2. attempt to ssh twice on the load balanced IP
        # 3. verify using the UNAME of the VM that
        #   round robin is indeed happening as expected

        # Create Load Balancer rule and assign VMs to rule
        lb_rule = LoadBalancerRule.create(
            self.apiclient,
            self.services["lbrule"],
            self.non_src_nat_ip.ipaddress.id,
            accountid=self.account.name,
            vpcid=self.vpc1.id,
            networkid=self.network1.id
        )
        self.cleanup.append(lb_rule)
        lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2])
        lb_rules = list_lb_rules(
            self.apiclient,
            id=lb_rule.id
        )
        self.assertEqual(
            isinstance(lb_rules, list),
            True,
            "Check list response returns a valid list"
        )
        # verify listLoadBalancerRules lists the added load balancing rule
        self.assertNotEqual(
            len(lb_rules),
            0,
            "Check Load Balancer Rule in its List"
        )
        self.assertEqual(
            lb_rules[0].id,
            lb_rule.id,
            "Check List Load Balancer Rules returns valid Rule"
        )
        # listLoadBalancerRuleInstances should list
        # all instances associated with that LB rule
        lb_instance_rules = list_lb_instances(
            self.apiclient,
            id=lb_rule.id
        )
        self.assertEqual(
            isinstance(lb_instance_rules, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            len(lb_instance_rules),
            0,
            "Check Load Balancer instances Rule in its List"
        )

        self.assertIn(
            lb_instance_rules[0].id,
            [self.vm_1.id, self.vm_2.id],
            "Check List Load Balancer instances Rules returns valid VM ID"
        )

        self.assertIn(
            lb_instance_rules[1].id,
            [self.vm_1.id, self.vm_2.id],
            "Check List Load Balancer instances Rules returns valid VM ID"
        )
        try:
            unameResults = []
            self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults)
            self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults)
            self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults)
            self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults)
            self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults)

            self.logger.debug("UNAME: %s" % str(unameResults))
            self.assertIn(
                "Linux",
                unameResults,
                "Check if ssh succeeded for server1"
            )
            self.assertIn(
                "Linux",
                unameResults,
                "Check if ssh succeeded for server2"
            )

            # SSH should pass till there is a last VM associated with LB rule
            lb_rule.remove(self.apiclient, [self.vm_2])
            self.logger.debug("SSHing into IP address: %s after removing VM (ID: %s) from LB rule" %
                       (
                           self.non_src_nat_ip.ipaddress.ipaddress,
                           self.vm_2.id
                       ))
            # Making host list empty
            unameResults[:] = []

            self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, unameResults)
            self.assertIn(
#.........这里部分代码省略.........
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:103,代码来源:test_loadbalance.py

示例6: test_01_create_lb_rule_src_nat

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def test_01_create_lb_rule_src_nat(self):
        """Test to create Load balancing rule with source NAT"""

        # Validate the Following:
        # 1. listLoadBalancerRules should return the added rule
        # 2. attempt to ssh twice on the load balanced IP
        # 3. verify using the UNAME of the VM
        #   that round robin is indeed happening as expected
        src_nat_ip_addrs = PublicIPAddress.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid
        )
        self.assertEqual(
            isinstance(src_nat_ip_addrs, list),
            True,
            "Check list response returns a valid list"
        )
        src_nat_ip_addr = src_nat_ip_addrs[0]

        # Check if VM is in Running state before creating LB rule
        vm_response = VirtualMachine.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid
        )

        self.assertEqual(
            isinstance(vm_response, list),
            True,
            "Check list VM returns a valid list"
        )

        self.assertNotEqual(
            len(vm_response),
            0,
            "Check Port Forwarding Rule is created"
        )
        for vm in vm_response:
            self.assertEqual(
                vm.state,
                'Running',
                "VM state should be Running before creating a NAT rule."
            )

        # Create Load Balancer rule and assign VMs to rule
        lb_rule = LoadBalancerRule.create(
            self.apiclient,
            self.services["lbrule"],
            src_nat_ip_addr.id,
            accountid=self.account.name,
            vpcid=self.vpc1.id,
            networkid=self.network1.id
        )
        self.cleanup.append(lb_rule)
        lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2])
        lb_rules = list_lb_rules(
            self.apiclient,
            id=lb_rule.id
        )
        self.assertEqual(
            isinstance(lb_rules, list),
            True,
            "Check list response returns a valid list"
        )
        # verify listLoadBalancerRules lists the added load balancing rule
        self.assertNotEqual(
            len(lb_rules),
            0,
            "Check Load Balancer Rule in its List"
        )
        self.assertEqual(
            lb_rules[0].id,
            lb_rule.id,
            "Check List Load Balancer Rules returns valid Rule"
        )

        # listLoadBalancerRuleInstances should list all
        # instances associated with that LB rule
        lb_instance_rules = list_lb_instances(
            self.apiclient,
            id=lb_rule.id
        )
        self.assertEqual(
            isinstance(lb_instance_rules, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            len(lb_instance_rules),
            0,
            "Check Load Balancer instances Rule in its List"
        )
        self.logger.debug("lb_instance_rules Ids: %s, %s" % (
            lb_instance_rules[0].id,
            lb_instance_rules[1].id
        ))
        self.logger.debug("VM ids: %s, %s" % (self.vm_1.id, self.vm_2.id))

        self.assertIn(
#.........这里部分代码省略.........
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:103,代码来源:test_loadbalance.py

示例7: test_02_host_maintenance_mode_with_activities

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def test_02_host_maintenance_mode_with_activities(self):
        """Test host maintenance mode with activities
        """

        # Validate the following
        # 1. Create Vms. Acquire IP. Create port forwarding & load balancing
        #    rules for Vms.
        # 2. While activities are ongoing: Create snapshots, recurring
        #    snapshots, create templates, download volumes, Host 1: put to
        #    maintenance mode. All Vms should failover to Host 2 in cluster
        #    Vms should be in running state. All port forwarding rules and
        #    load balancing Rules should work.
        # 3. After failover to Host 2 succeeds, deploy Vms. Deploy Vms on host
        #    2 should succeed. All ongoing activities in step 3 should succeed
        # 4. Host 1: cancel maintenance mode.
        # 5. While activities are ongoing: Create snapshots, recurring
        #    snapshots, create templates, download volumes, Host 2: put to
        #    maintenance mode. All Vms should failover to Host 1 in cluster.
        # 6. After failover to Host 1 succeeds, deploy VMs. Deploy Vms on
        #    host 1 should succeed. All ongoing activities in step 6 should
        #    succeed.

        hosts = Host.list(
            self.apiclient,
            zoneid=self.zone.id,
            resourcestate='Enabled',
            type='Routing'
        )
        self.assertEqual(
            isinstance(hosts, list),
            True,
            "List hosts should return valid host response"
        )
        if len(hosts) < 2:
            self.skipTest("There must be at least 2 hosts present in cluster")

        self.debug("Checking HA with hosts: %s, %s" % (
            hosts[0].name,
            hosts[1].name
        ))
        self.debug("Deploying VM in account: %s" % self.account.name)
        # Spawn an instance in that network
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id
        )
        vms = VirtualMachine.list(
            self.apiclient,
            id=virtual_machine.id,
            listall=True
        )
        self.assertEqual(
            isinstance(vms, list),
            True,
            "List VMs should return valid response for deployed VM"
        )
        self.assertNotEqual(
            len(vms),
            0,
            "List VMs should return valid response for deployed VM"
        )
        vm = vms[0]
        self.debug("Deployed VM on host: %s" % vm.hostid)
        self.assertEqual(
            vm.state,
            "Running",
            "Deployed VM should be in RUnning state"
        )
        networks = Network.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            listall=True
        )
        self.assertEqual(
            isinstance(networks, list),
            True,
            "List networks should return valid list for the account"
        )
        network = networks[0]

        self.debug("Associating public IP for account: %s" %
                   self.account.name)
        public_ip = PublicIPAddress.create(
            self.apiclient,
            accountid=self.account.name,
            zoneid=self.zone.id,
            domainid=self.account.domainid,
            networkid=network.id
        )

        self.debug("Associated %s with network %s" % (
            public_ip.ipaddress.ipaddress,
            network.id
        ))
        self.debug("Creating PF rule for IP address: %s" %
                   public_ip.ipaddress.ipaddress)
#.........这里部分代码省略.........
开发者ID:CIETstudents,项目名称:cloudstack,代码行数:103,代码来源:test_high_availability.py

示例8: test_01_host_maintenance_mode

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def test_01_host_maintenance_mode(self):
        """Test host maintenance mode
        """

        # Validate the following
        # 1. Create Vms. Acquire IP. Create port forwarding & load balancing
        #    rules for Vms.
        # 2. Host 1: put to maintenance mode. All Vms should failover to Host
        #    2 in cluster. Vms should be in running state. All port forwarding
        #    rules and load balancing Rules should work.
        # 3. After failover to Host 2 succeeds, deploy Vms. Deploy Vms on host
        #    2 should succeed.
        # 4. Host 1: cancel maintenance mode.
        # 5. Host 2 : put to maintenance mode. All Vms should failover to
        #    Host 1 in cluster.
        # 6. After failover to Host 1 succeeds, deploy VMs. Deploy Vms on
        #    host 1 should succeed.

        hosts = Host.list(
            self.apiclient,
            zoneid=self.zone.id,
            resourcestate='Enabled',
            type='Routing'
        )
        self.assertEqual(
            isinstance(hosts, list),
            True,
            "List hosts should return valid host response"
        )
        if len(hosts) < 2:
            self.skipTest("There must be at least 2 hosts present in cluster")

        self.debug("Checking HA with hosts: %s, %s" % (
            hosts[0].name,
            hosts[1].name
        ))
        self.debug("Deploying VM in account: %s" % self.account.name)
        # Spawn an instance in that network
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id
        )
        vms = VirtualMachine.list(
            self.apiclient,
            id=virtual_machine.id,
            listall=True
        )
        self.assertEqual(
            isinstance(vms, list),
            True,
            "List VMs should return valid response for deployed VM"
        )
        self.assertNotEqual(
            len(vms),
            0,
            "List VMs should return valid response for deployed VM"
        )
        vm = vms[0]
        self.debug("Deployed VM on host: %s" % vm.hostid)
        self.assertEqual(
            vm.state,
            "Running",
            "Deployed VM should be in RUnning state"
        )
        networks = Network.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            listall=True
        )
        self.assertEqual(
            isinstance(networks, list),
            True,
            "List networks should return valid list for the account"
        )
        network = networks[0]

        self.debug("Associating public IP for account: %s" %
                   self.account.name)
        public_ip = PublicIPAddress.create(
            self.apiclient,
            accountid=self.account.name,
            zoneid=self.zone.id,
            domainid=self.account.domainid,
            networkid=network.id
        )

        self.debug("Associated %s with network %s" % (
            public_ip.ipaddress.ipaddress,
            network.id
        ))
        self.debug("Creating PF rule for IP address: %s" %
                   public_ip.ipaddress.ipaddress)
        NATRule.create(
            self.apiclient,
            virtual_machine,
            self.services["natrule"],
#.........这里部分代码省略.........
开发者ID:CIETstudents,项目名称:cloudstack,代码行数:103,代码来源:test_high_availability.py

示例9: test_01_source_based_roundrobin

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def test_01_source_based_roundrobin(self):
        """Test Create a "SourceBased" stick policy for a Lb rule with
           "RoundRobin" algorithm
        """

        # Validate the following
        # 1. Configure Netscaler for load balancing.
        # 2. Create a Network offering with LB services provided by Netscaler
        #    and all other services by VR.
        # 3. Create a new account/user.
        # 4. Deploy few VMs using a network from the above created Network
        #    offering.
        # 5. Create a "SourceBased" stick policy for a Lb rule with
        #    "RoundRobin" algorithm

        self.debug(
            "Creating LB rule for IP address: %s with round robin algo" %
            self.public_ip.ipaddress.ipaddress)

        lb_rule = LoadBalancerRule.create(
            self.apiclient,
            self.testdata["lbrule"],
            ipaddressid=self.public_ip.ipaddress.id,
            accountid=self.account.name,
            networkid=self.network.id
        )
        self.cleanup.append(lb_rule)
        self.debug("Created the load balancing rule for public IP: %s" %
                   self.public_ip.ipaddress.ipaddress)

        self.debug("Assigning VM instance: %s to LB rule: %s" % (
            self.virtual_machine.name,
            lb_rule.name
        ))
        lb_rule.assign(self.apiclient, [self.virtual_machine])
        self.debug("Assigned VM instance: %s to lb rule: %s" % (
            self.virtual_machine.name,
            lb_rule.name
        ))
        self.debug(
            "Configuring 'SourceBased' Sticky policy on lb rule: %s" %
            lb_rule.name)
        try:
            result = lb_rule.createSticky(
                self.apiclient,
                methodname='SourceBased',
                name='SourceBasedRR',
                param={"holdtime": 20}
            )
            self.debug("Response: %s" % result)
        except Exception as e:
            self.fail("Configure sticky policy failed with exception: %s" % e)

        self.debug(
            "SSH into Netscaler to check whether sticky policy configured\
                    properly or not?")
        self.debug("SSH into netscaler: %s" %
                   self.testdata["configurableData"]["netscaler"]["ipaddress"])
        try:
            ssh_client = SshClient(
                self.testdata["configurableData"]["netscaler"]["ipaddress"],
                self.testdata["configurableData"]["netscaler"]["port"],
                self.testdata["configurableData"]["netscaler"]["username"],
                self.testdata["configurableData"]["netscaler"]["password"],
            )
            cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % (
                self.public_ip.ipaddress.ipaddress,
                lb_rule.publicport)
            self.debug("command: %s" % cmd)
            res = ssh_client.execute(cmd)
            result = str(res)
            self.debug("Output: %s" % result)

            self.assertEqual(
                result.count("Persistence: SOURCEIP"),
                1,
                "'SourceBased' sticky policy should be configured on NS"
            )

            self.assertEqual(
                result.count("Configured Method: ROUNDROBIN"),
                1,
                "'ROUNDROBIN' algorithm should be configured on NS"
            )

        except Exception as e:
            self.fail("SSH Access failed for %s: %s" %
                      (self.testdata["configurableData"]["netscaler"]["ipaddress"], e))
        return
开发者ID:Accelerite,项目名称:cloudstack,代码行数:91,代码来源:test_netscaler_lb_sticky.py

示例10: test_07_associate_public_ip

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def test_07_associate_public_ip(self):
        """Test associate public IP within the project
        """
        # Validate the following
        # 1. Create a project
        # 2. Add some public Ips to the project
        # 3. Verify public IP assigned can only used to create PF/LB rules
        #    inside project

        networks = Network.list(self.apiclient, projectid=self.project.id, listall=True)
        self.assertEqual(isinstance(networks, list), True, "Check list networks response returns a valid response")
        self.assertNotEqual(len(networks), 0, "Check list networks response returns a valid network")
        network = networks[0]
        self.debug("Associating public IP for project: %s" % self.project.id)
        public_ip = PublicIPAddress.create(
            self.apiclient,
            zoneid=self.virtual_machine.zoneid,
            services=self.services["server"],
            networkid=network.id,
            projectid=self.project.id,
        )
        self.cleanup.append(public_ip)

        # Create NAT rule
        self.debug("Creating a NAT rule within project, VM ID: %s" % self.virtual_machine.id)
        nat_rule = NATRule.create(
            self.apiclient,
            self.virtual_machine,
            self.services["natrule"],
            public_ip.ipaddress.id,
            projectid=self.project.id,
        )
        self.debug("created a NAT rule with ID: %s" % nat_rule.id)
        nat_rule_response = NATRule.list(self.apiclient, id=nat_rule.id)
        self.assertEqual(isinstance(nat_rule_response, list), True, "Check list response returns a valid list")
        self.assertNotEqual(len(nat_rule_response), 0, "Check Port Forwarding Rule is created")
        self.assertEqual(nat_rule_response[0].id, nat_rule.id, "Check Correct Port forwarding Rule is returned")

        # Create Load Balancer rule and assign VMs to rule
        self.debug("Created LB rule for public IP: %s" % public_ip.ipaddress)
        lb_rule = LoadBalancerRule.create(
            self.apiclient, self.services["lbrule"], public_ip.ipaddress.id, projectid=self.project.id
        )
        self.debug("Assigning VM: %s to LB rule: %s" % (self.virtual_machine.name, lb_rule.id))
        lb_rule.assign(self.apiclient, [self.virtual_machine])

        lb_rules = list_lb_rules(self.apiclient, id=lb_rule.id)
        self.assertEqual(isinstance(lb_rules, list), True, "Check list response returns a valid list")
        # verify listLoadBalancerRules lists the added load balancing rule
        self.assertNotEqual(len(lb_rules), 0, "Check Load Balancer Rule in its List")
        self.assertEqual(lb_rules[0].id, lb_rule.id, "Check List Load Balancer Rules returns valid Rule")

        # Create Firewall rule with configurations from settings file
        fw_rule = FireWallRule.create(
            self.apiclient,
            ipaddressid=public_ip.ipaddress.id,
            protocol="TCP",
            cidrlist=[self.services["fw_rule"]["cidr"]],
            startport=self.services["fw_rule"]["startport"],
            endport=self.services["fw_rule"]["endport"],
            projectid=self.project.id,
        )
        self.debug("Created firewall rule: %s" % fw_rule.id)

        # After Router start, FW rule should be in Active state
        fw_rules = FireWallRule.list(self.apiclient, id=fw_rule.id)
        self.assertEqual(isinstance(fw_rules, list), True, "Check for list FW rules response return valid data")

        self.assertEqual(fw_rules[0].state, "Active", "Check list load balancing rules")
        self.assertEqual(
            fw_rules[0].startport, str(self.services["fw_rule"]["startport"]), "Check start port of firewall rule"
        )

        self.assertEqual(
            fw_rules[0].endport, str(self.services["fw_rule"]["endport"]), "Check end port of firewall rule"
        )

        self.debug("Deploying VM for account: %s" % self.account.name)
        virtual_machine_1 = VirtualMachine.create(
            self.apiclient,
            self.services["server"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.cleanup.append(virtual_machine_1)

        self.debug("VM state after deploy: %s" % virtual_machine_1.state)
        # Verify VM state
        self.assertEqual(virtual_machine_1.state, "Running", "Check VM state is Running or not")

        self.debug("Creating NAT rule for VM (ID: %s) outside project" % virtual_machine_1.id)
        with self.assertRaises(Exception):
            NATRule.create(self.apiclient, virtual_machine_1, self.services["natrule"], public_ip.ipaddress.id)

        self.debug("Creating LB rule for public IP: %s outside project" % public_ip.ipaddress)
        with self.assertRaises(Exception):
            LoadBalancerRule.create(
                self.apiclient, self.services["lbrule"], public_ip.ipaddress.id, accountid=self.account.name
#.........这里部分代码省略.........
开发者ID:maksimov,项目名称:cloudstack,代码行数:103,代码来源:test_project_resources.py

示例11: test_02_shared_another_network

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def test_02_shared_another_network(self):
        # Create network
        self.debug("Creating network with network offering: %s" % self.network_offering.id)
        self.network = Network.create(
            self.apiclient,
            self.services["network"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkofferingid=self.network_offering.id,
            zoneid=self.zone.id
        )
        self.debug("Created network: %s" % self.network.id)

        self.debug("Trying VM deploy with network created on account: %s" % self.account.name)

        self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["small"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkids=self.network.id,
            zoneid=self.zone.id,
            serviceofferingid=self.service_offering_shared.id
        )
        self.debug("Deployed VM in network: %s" % self.network.id)
        list_vm_response = VirtualMachine.list(
            self.apiclient,
            id=self.virtual_machine.id
        )
        self.debug(
            "Verify listVirtualMachines response for virtual machine: %s"
            % self.virtual_machine.id
        )

        self.assertEqual(
            isinstance(list_vm_response, list),
            True,
            "Check list response returns a valid list")
        vm_response = list_vm_response[0]

        self.assertEqual(
            vm_response.state,
            "Running",
            "VM state should be running after deployment"
        )

        self.debug("Aquiring public IP for network: %s" % self.network.id)

        ip_with_lb_rule = PublicIPAddress.create(
            self.apiclient,
            accountid=self.account.name,
            zoneid=self.zone.id,
            domainid=self.account.domainid,
            networkid=self.network.id)

        self.debug(
            "Creating LB rule for IP address: %s with round robin algo" %
            ip_with_lb_rule.ipaddress.ipaddress)

        self.services["lbrule"]["alg"] = 'roundrobin'
        lb_rule = LoadBalancerRule.create(
            self.apiclient,
            self.services["lbrule"],
            ipaddressid=ip_with_lb_rule.ipaddress.id,
            accountid=self.account.name,
            networkid=self.network.id
        )

        lb_rules = LoadBalancerRule.list(
            self.apiclient,
            id=lb_rule.id,
            listall=True
        )
        self.assertEqual(
            isinstance(lb_rules, list),
            True,
            "List LB rules should return a newly created LB rule"
        )
        self.debug("Adding %s to the LB rule %s" % (
            self.virtual_machine.name,
            lb_rule.name
        ))
        lb_rule.assign(self.apiclient, [self.virtual_machine])
        return
开发者ID:Accelerite,项目名称:cloudstack,代码行数:86,代码来源:test_ncc_integration_shared.py

示例12: setUp

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def setUp(self):
        self.logger = MarvinLog(MarvinLog.LOGGER_TEST).get_logger()

        self.apiclient = self.testClient.getApiClient()
        self.services = self.testClient.getParsedTestDataConfig()

        # Get Zone, Domain and templates
        self.domain = get_domain(self.apiclient)
        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
        template = get_template(
            self.apiclient,
            self.zone.id
        )
        self.services["virtual_machine"]["zoneid"] = self.zone.id

        # Create an account, network, VM and IP addresses
        self.account = Account.create(
            self.apiclient,
            self.services["account"],
            admin=True,
            domainid=self.domain.id
        )

        self.vpc_offering = get_default_vpc_offering(self.apiclient)
        self.logger.debug("VPC Offering '%s' selected", self.vpc_offering.name)

        self.network_offering = get_default_network_offering(self.apiclient)
        self.logger.debug("Network Offering '%s' selected", self.network_offering.name)

        self.virtual_machine_offering = get_default_virtual_machine_offering(self.apiclient)
        self.logger.debug("Virtual Machine Offering '%s' selected", self.virtual_machine_offering.name)

        self.default_allow_acl = get_network_acl(self.apiclient, 'default_allow')
        self.logger.debug("ACL '%s' selected", self.default_allow_acl.name)

        self.template = get_template(self.apiclient, self.zone.id)
        self.logger.debug("Template '%s' selected" % self.template.name)

        self.vpc1 = VPC.create(self.apiclient,
                              self.services['vpcs']['vpc1'],
                              vpcofferingid=self.vpc_offering.id,
                              zoneid=self.zone.id,
                              domainid=self.domain.id,
                              account=self.account.name)
        self.logger.debug("VPC '%s' created, CIDR: %s", self.vpc1.name, self.vpc1.cidr)

        self.network1 = Network.create(self.apiclient,
                                      self.services['networks']['network1'],
                                      networkofferingid=self.network_offering.id,
                                      aclid=self.default_allow_acl.id,
                                      vpcid=self.vpc1.id,
                                      zoneid=self.zone.id,
                                      domainid=self.domain.id,
                                      accountid=self.account.name)
        self.logger.debug("Network '%s' created, CIDR: %s, Gateway: %s", self.network1.name, self.network1.cidr, self.network1.gateway)

        self.vm1 = VirtualMachine.create(self.apiclient,
                                        self.services['vms']['vm1'],
                                        templateid=self.template.id,
                                        serviceofferingid=self.virtual_machine_offering.id,
                                        networkids=[self.network1.id],
                                        zoneid=self.zone.id,
                                        domainid=self.domain.id,
                                        accountid=self.account.name)
        self.logger.debug("VM '%s' created, Network: %s, IP %s", self.vm1.name, self.network1.name, self.vm1.nic[0].ipaddress)

        src_nat_ip_addrs = list_public_ip(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid
        )

        try:
            src_nat_ip_addr = src_nat_ip_addrs[0]
        except Exception as e:
            self.fail("SSH failed for VM with IP: %s %s" %
                      (src_nat_ip_addr.ipaddress, e))

        self.lb_rule = LoadBalancerRule.create(
            self.apiclient,
            self.services["lbrule"],
            src_nat_ip_addr.id,
            self.account.name,
            self.network1.id,
            self.vpc1.id
        )
        self.lb_rule.assign(self.apiclient, [self.vm1])

        self.nat_rule = NATRule.create(
            self.apiclient,
            self.vm1,
            self.services["natrule"],
            src_nat_ip_addr.id
        )
        self.cleanup = []
        return
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:98,代码来源:test_delete_account.py

示例13: setUpClass

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def setUpClass(cls):
        cls._cleanup = []
        cls.testClient = super(TestVPCRouterOneNetwork, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        cls.vpcSupported = True
        cls._cleanup = []
        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.template = get_template(
            cls.api_client,
            cls.zone.id,
            cls.services["ostype"]
        )
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
            cls.api_client,
            cls.services["service_offering"]
        )
        cls._cleanup.append(cls.service_offering)
        cls.vpc_off = VpcOffering.create(
            cls.api_client,
            cls.services["vpc_offering"]
        )
        cls.vpc_off.update(cls.api_client, state='Enabled')
        cls._cleanup.append(cls.vpc_off)

        cls.account = Account.create(
            cls.api_client,
            cls.services["account"],
            admin=True,
            domainid=cls.domain.id
        )
        cls._cleanup.insert(0, cls.account)

        cls.services["vpc"]["cidr"] = '10.1.1.1/16'
        cls.vpc = VPC.create(
            cls.api_client,
            cls.services["vpc"],
            vpcofferingid=cls.vpc_off.id,
            zoneid=cls.zone.id,
            account=cls.account.name,
            domainid=cls.account.domainid
        )

        private_gateway = PrivateGateway.create(
            cls.api_client,
            gateway='10.1.3.1',
            ipaddress='10.1.3.100',
            netmask='255.255.255.0',
            vlan=678,
            vpcid=cls.vpc.id
        )
        cls.gateways = PrivateGateway.list(
            cls.api_client,
            id=private_gateway.id,
            listall=True
        )

        static_route = StaticRoute.create(
            cls.api_client,
            cidr='11.1.1.1/24',
            gatewayid=private_gateway.id
        )
        cls.static_routes = StaticRoute.list(
            cls.api_client,
            id=static_route.id,
            listall=True
        )

        cls.nw_off = NetworkOffering.create(
            cls.api_client,
            cls.services["network_offering"],
            conservemode=False
        )
        # Enable Network offering
        cls.nw_off.update(cls.api_client, state='Enabled')
        cls._cleanup.append(cls.nw_off)

        # Creating network using the network offering created
        cls.network_1 = Network.create(
            cls.api_client,
            cls.services["network"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            networkofferingid=cls.nw_off.id,
            zoneid=cls.zone.id,
            gateway='10.1.1.1',
            vpcid=cls.vpc.id
        )

        # Spawn an instance in that network
        vm_1 = VirtualMachine.create(
            cls.api_client,
            cls.services["virtual_machine"],
            accountid=cls.account.name,
#.........这里部分代码省略.........
开发者ID:EdwardBetts,项目名称:blackhole,代码行数:103,代码来源:test_vpc_routers.py

示例14: test_09_appcookie_leastconn

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def test_09_appcookie_leastconn(self):
        """Test Create a "AppCookie" stick policy for a Lb rule with leastconn
        """

        # Validate the following
        # 1. Configure Netscaler for load balancing.
        # 2. Create a Network offering with LB services provided by Netscaler
        #    and all other services by VR.
        # 3. Create a new account/user.
        # 4. Deploy few VMs using a network from the above created Network
        #    offering.
        # 5. Create a "AppCookie" stick policy for a Lb rule with
        #    "leastconn" algorithm

        self.debug(
            "Creating LB rule for IP address: %s with leastconn algo" %
            self.public_ip.ipaddress.ipaddress)

        self.services["lbrule"]["alg"] = 'leastconn'
        self.services["lbrule"]["publicport"] = 80
        self.services["lbrule"]["privateport"] = 80
        lb_rule = LoadBalancerRule.create(
            self.apiclient,
            self.services["lbrule"],
            ipaddressid=self.public_ip.ipaddress.id,
            accountid=self.account.name,
            networkid=self.network.id
        )
        self.cleanup.append(lb_rule)
        self.debug("Created the load balancing rule for public IP: %s" %
                   self.public_ip.ipaddress.ipaddress)

        self.debug("Assigning VM instance: %s to LB rule: %s" % (
            self.virtual_machine.name,
            lb_rule.name
        ))
        lb_rule.assign(self.apiclient, [self.virtual_machine])
        self.debug("Assigned VM instance: %s to lb rule: %s" % (
            self.virtual_machine.name,
            lb_rule.name
        ))
        self.debug(
            "Configuring 'SourceBased' Sticky policy on lb rule: %s" %
            lb_rule.name)
        try:
            result = lb_rule.createSticky(
                self.apiclient,
                methodname='AppCookie',
                name='AppCookieLeastConn',
                param={"name": 20}
            )
            self.debug("Response: %s" % result)
        except Exception as e:
            self.fail("Configure sticky policy failed with exception: %s" % e)

        self.debug(
            "SSH into Netscaler to check whether sticky policy\
                    configured properly or not?")
        self.debug("SSH into netscaler: %s" %
                   self.services["netscaler"]["ipaddress"])
        try:
            ssh_client = SshClient(
                self.services["netscaler"]["ipaddress"],
                self.services["netscaler"]["port"],
                self.services["netscaler"]["username"],
                self.services["netscaler"]["password"],
            )
            cmd = "show lb vserver Cloud-VirtualServer-%s-%s" % (
                self.public_ip.ipaddress.ipaddress,
                lb_rule.publicport)
            self.debug("command: %s" % cmd)
            res = ssh_client.execute(cmd)
            result = str(res)
            self.debug("Output: %s" % result)

            self.assertEqual(
                result.count("Persistence: RULE"),
                1,
                "'AppCookie' sticky policy should be configured on NS"
            )

            self.assertEqual(
                result.count("Configured Method: LEASTCONNECTION"),
                1,
                "'leastconn' algorithm should be configured on NS"
            )

        except Exception as e:
            self.fail("SSH Access failed for %s: %s" %
                      (self.services["netscaler"]["ipaddress"], e))
        return
开发者ID:mefarazath,项目名称:cloudstack,代码行数:93,代码来源:test_netscaler_lb_sticky.py

示例15: test_02_network_off_with_conserve_mode

# 需要导入模块: from marvin.lib.base import LoadBalancerRule [as 别名]
# 或者: from marvin.lib.base.LoadBalancerRule import create [as 别名]
    def test_02_network_off_with_conserve_mode(self):
        """Test Network offering with Conserve mode ON and VR - All services
        """


        # Validate the following
        # 1. Create a Network from the above network offering and deploy a VM.
        # 2. On source NAT ipaddress, we should be allowed to add a LB rules
        # 3. On source NAT ipaddress, we should be allowed to add a PF rules
        # 4. On source NAT ipaddress, we should be allowed to add a Firewall
        #    rules
        # 5. On an ipaddress that has Lb rules, we should be allowed to
        #    program PF rules.
        # 6. We should be allowed to program multiple PF rules on the same Ip
        #    address on different public ports.
        # 7. We should be allowed to program multiple LB rules on the same Ip
        #    address for different public port ranges.
        # 8. On source NAT ipaddress, we should be allowed to Enable VPN
        #    access.

        # Create a network offering with all virtual router services enabled
        self.debug(
            "Creating n/w offering with all services in VR & conserve mode:off"
            )
        self.network_offering = NetworkOffering.create(
                                            self.api_client,
                                            self.services["network_offering"],
                                            conservemode=True
                                            )
        self.cleanup.append(self.network_offering)

        self.debug("Created n/w offering with ID: %s" %
                                                    self.network_offering.id)
    # Enable Network offering
        self.network_offering.update(self.apiclient, state='Enabled')

        # Creating network using the network offering created
        self.debug("Creating network with network offering: %s" %
                                                    self.network_offering.id)
        self.network = Network.create(
                                    self.apiclient,
                                    self.services["network"],
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    networkofferingid=self.network_offering.id,
                                    zoneid=self.zone.id
                                    )
        self.debug("Created network with ID: %s" % self.network.id)

        self.debug("Deploying VM in account: %s" % self.account.name)

        # Spawn an instance in that network
        virtual_machine = VirtualMachine.create(
                                  self.apiclient,
                                  self.services["virtual_machine"],
                                  accountid=self.account.name,
                                  domainid=self.account.domainid,
                                  serviceofferingid=self.service_offering.id,
                                  networkids=[str(self.network.id)]
                                  )
        self.debug("Deployed VM in network: %s" % self.network.id)

        src_nat_list = PublicIPAddress.list(
                                        self.apiclient,
                                        associatednetworkid=self.network.id,
                                        account=self.account.name,
                                        domainid=self.account.domainid,
                                        listall=True,
                                        issourcenat=True,
                                        )
        self.assertEqual(
                         isinstance(src_nat_list, list),
                         True,
                         "List Public IP should return a valid source NAT"
                         )
        self.assertNotEqual(
                    len(src_nat_list),
                    0,
                    "Length of response from listPublicIp should not be 0"
                    )

        src_nat = src_nat_list[0]

        self.debug("Trying to create LB rule on source NAT IP: %s" %
                                                        src_nat.ipaddress)
        # Create Load Balancer rule with source NAT
        lb_rule = LoadBalancerRule.create(
                                    self.apiclient,
                                    self.services["lbrule"],
                                    ipaddressid=src_nat.id,
                                    accountid=self.account.name
                                )
        self.debug("Created LB rule on source NAT: %s" % src_nat.ipaddress)

        lb_rules = LoadBalancerRule.list(
                                         self.apiclient,
                                         id=lb_rule.id
                                         )
        self.assertEqual(
                         isinstance(lb_rules, list),
#.........这里部分代码省略.........
开发者ID:miguelaferreira,项目名称:cosmic-core,代码行数:103,代码来源:test_network_offering.py


注:本文中的marvin.lib.base.LoadBalancerRule.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。