def create_Network(self, net_offerring, gateway='10.1.1.1', vpc=None): try: self.debug('Create NetworkOffering') net_offerring["name"] = "NET_OFF-" + str(gateway) nw_off = NetworkOffering.create(self.apiclient, net_offerring, conservemode=False) # Enable Network offering nw_off.update(self.apiclient, state='Enabled') self.cleanup.append(nw_off) self.debug('Created and Enabled NetworkOffering') self.services["network"]["name"] = "NETWORK-" + str(gateway) self.debug('Adding Network=%s' % self.services["network"]) obj_network = Network.create(self.apiclient, self.services["network"], accountid=self.account.name, domainid=self.account.domainid, networkofferingid=nw_off.id, zoneid=self.zone.id, gateway=gateway, vpcid=vpc.id if vpc else self.vpc.id) self.debug("Created network with ID: %s" % obj_network.id) return obj_network except: self.fail('Unable to create a Network with offering=%s' % net_offerring)
def create_network(self, net_offerring, gateway='10.1.1.1',vpc=None): try: self.debug('Create NetworkOffering') net_offerring["name"] = "NET_OFF-" + str(gateway) nw_off = NetworkOffering.create(self.apiclient, net_offerring, conservemode=False ) # Enable Network offering nw_off.update(self.apiclient, state='Enabled') self._cleanup.append(nw_off) self.debug('Created and Enabled NetworkOffering') self.services["network"]["name"] = "NETWORK-" + str(gateway) self.debug('Adding Network=%s' % self.services["network"]) obj_network = Network.create(self.apiclient, self.services["network"], accountid=self.account.name, domainid=self.account.domainid, networkofferingid=nw_off.id, zoneid=self.zone.id, gateway=gateway, vpcid=vpc.id if vpc else self.vpc.id ) self.debug("Created network with ID: %s" % obj_network.id) return obj_network except Exception, e: self.fail('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
def create_vm(self, pfrule=False, egress_policy=True, RR=False): self.create_network_offering(egress_policy, RR) # 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 instance in the account: %s" % self.account.name) project = None try: self.virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.domain.id, serviceofferingid=self.service_offering.id, mode=self.zone.networktype if pfrule else 'basic', networkids=[str(self.network.id)], projectid=project.id if project else None) except Exception as e: self.fail("Virtual machine deployment failed with exception: %s" % e) self.debug("Deployed instance in account: %s" % self.account.name)
def create_vm(self, pfrule=False, egress_policy=True, RR=False): self.create_network_offering(egress_policy, RR) # 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 instance in the account: %s" % self.account.name) project = None try: self.virtual_machine = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.domain.id, serviceofferingid=self.service_offering.id, mode=self.zone.networktype if pfrule else 'basic', networkids=[str(self.network.id)], projectid=project.id if project else None) except Exception as e: self.debug('error=%s' % e) self.debug("Deployed instance in account: %s" % self.account.name)
def createNetwork(self, networkType): """Create a network of given type (isolated/shared/isolated in VPC)""" network = None if networkType == ISOLATED_NETWORK: try: network = Network.create(self.apiclient,self.services["isolated_network"], networkofferingid=self.isolated_network_offering.id, accountid=self.account.name,domainid=self.account.domainid, zoneid=self.zone.id) except Exception as e: self.fail("Isolated network creation failed because: %s" % e) elif networkType == SHARED_NETWORK: physical_network, vlan = get_free_vlan(self.api_client, self.zone.id) #create network using the shared network offering created self.services["shared_network"]["acltype"] = "domain" self.services["shared_network"]["vlan"] = vlan self.services["shared_network"]["networkofferingid"] = self.shared_network_offering.id self.services["shared_network"]["physicalnetworkid"] = physical_network.id self.services["shared_network"] = setSharedNetworkParams(self.services["shared_network"]) try: network = Network.create(self.api_client, self.services["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id) self.cleanup.append(network) except Exception as e: self.fail("Shared Network creation failed because: %s" % e) elif networkType == VPC_NETWORK: self.services["vpc"]["cidr"] = "10.1.1.1/16" self.debug("creating a VPC network in the account: %s" % self.account.name) vpc = VPC.create(self.apiclient, self.services["vpc"], vpcofferingid=self.vpc_off.id, zoneid=self.zone.id, account=self.account.name, domainid=self.account.domainid) vpcs = VPC.list(self.apiclient, id=vpc.id) self.assertEqual(validateList(vpcs)[0], PASS, "VPC list validation failed, vpc list is %s" % vpcs) network = Network.create(self.api_client,self.services["isolated_network"], networkofferingid=self.isolated_network_offering_vpc.id, accountid=self.account.name,domainid=self.account.domainid, zoneid=self.zone.id, vpcid=vpc.id, gateway="10.1.1.1", netmask="255.255.255.0") return network
def create_vm(self, pfrule=False, egress_policy=True, RR=False): self.create_network_offering(egress_policy, RR) # 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.cleanup_networks.append(self.network) self.debug("Created network with ID: %s" % self.network.id) self.debug("Deploying instance in the account: %s" % self.account.name) project = None try: self.virtual_machine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.domain.id, serviceofferingid=self.service_offering.id, mode=self.zone.networktype if pfrule else 'basic', networkids=[str(self.network.id)], projectid=project.id if project else None) self.cleanup_vms.append(self.virtual_machine) except Exception as e: self.fail("Virtual machine deployment failed with exception: %s" % e) self.debug("Deployed instance %s in account: %s" % (self.virtual_machine.id,self.account.name)) # Checking if VM is running or not, in case it is deployed in error state, test case fails self.vm_list = list_virtual_machines(self.apiclient, id=self.virtual_machine.id) self.assertEqual(validateList(self.vm_list)[0], PASS, "vm list validation failed, vm list is %s" % self.vm_list) self.assertEqual(str(self.vm_list[0].state).lower(),'running',"VM state should be running, it is %s" % self.vm_list[0].state) self.public_ip = PublicIPAddress.create( self.apiclient, accountid=self.account.name, zoneid=self.zone.id, domainid=self.account.domainid, networkid=self.network.id ) # Open up firewall port for SSH FireWallRule.create( self.apiclient, ipaddressid=self.public_ip.ipaddress.id, protocol=self.services["natrule"]["protocol"], cidrlist=['0.0.0.0/0'], startport=self.services["natrule"]["publicport"], endport=self.services["natrule"]["publicport"] ) self.debug("Creating NAT rule for VM ID: %s" % self.virtual_machine.id) #Create NAT rule NATRule.create( self.apiclient, self.virtual_machine, self.services["natrule"], self.public_ip.ipaddress.id ) return