def test_create_composite(self):
        fwrule = FirewallRule(**self.resource['fwrule'])
        nic = NIC(firewall_rules=[fwrule], **self.resource['nic'])
        volume = Volume(image=self.image['id'],
                        image_password='******',
                        ssh_keys=['ssh-rsa AAAAB3NzaC1'],
                        **self.resource['volume'])
        volume.availability_zone = 'ZONE_3'

        server = Server(
            nics=[nic],
            create_volumes=[volume],
            **self.resource['server'])

        composite_server = self.client.create_server(
            datacenter_id=self.datacenter['id'],
            server=server)
        self.client.wait_for_completion(composite_server, timeout=600)

        composite_server = self.client.get_server(
            datacenter_id=self.datacenter['id'],
            server_id=composite_server['id'])

        assertRegex(self, composite_server['id'], self.resource['uuid_match'])
        self.assertEqual(composite_server['properties']['name'], self.resource['server']['name'])
        self.assertEqual(composite_server['properties']['cores'], self.resource['server']['cores'])
        self.assertEqual(composite_server['properties']['ram'], self.resource['server']['ram'])
        self.assertEqual(composite_server['properties']['availabilityZone'], 'ZONE_1')
        self.assertIn(composite_server['properties']['vmState'], self.resource['vm_states'])
        self.assertGreater(len(composite_server['entities']['volumes']['items']), 0)
        self.assertGreater(len(composite_server['entities']['nics']['items']), 0)
示例#2
0
def getFwRuleObject(defdict=None):
    if not defdict or not isinstance(defdict, dict):
        raise ValueError("argument 'defdict' must be non-empty dict")
    # AARGH! some of NIC's fields have different names -> need to convert manually
    # so make a copy and let source as is
    props = dict()
    for k, v in defdict['properties'].items():
        if k == 'sourceMac':
            props['source_mac'] = v
            continue
        if k == 'sourceIp':
            props['source_ip'] = v
            continue
        if k == 'targetIp':
            props['target_ip'] = v
            continue
        if k == 'portRangeStart':
            props['port_range_start'] = v
            continue
        if k == 'portRangeEnd':
            props['port_range_end'] = v
            continue
        if k == 'icmpType':
            props['icmp_type'] = v
            continue
        if k == 'icmpCode':
            props['icmp_code'] = v
            continue
        props[k] = v
    # end for(defdict)
    apiobj = FirewallRule(**props)
    return apiobj
 def test_create_failure(self):
     try:
         fwrule = FirewallRule(name=self.resource['fwrule']['name'])
         self.client.create_firewall_rule(
             datacenter_id=self.datacenter['id'],
             server_id=self.server['id'],
             nic_id=self.nic1['id'],
             firewall_rule=fwrule)
     except ICError as e:
         self.assertIn(self.resource['missing_attribute_error'] % 'protocol',
                       e.content[0]['message'])
    def setUpClass(cls):
        warnings.filterwarnings("ignore", category=ResourceWarning,
                                message="unclosed.*<ssl.SSLSocket.*>")
        cls.resource = resource()
        cls.client = IonosEnterpriseService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

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

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

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

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

        # Create test Firewall Rule
        fwrule = FirewallRule(**cls.resource['fwrule'])
        cls.fwrule = cls.client.create_firewall_rule(
            datacenter_id=cls.datacenter['id'],
            server_id=cls.server['id'],
            nic_id=cls.nic1['id'],
            firewall_rule=fwrule)
        cls.client.wait_for_completion(cls.fwrule)

        # Create test Firewall Rule 2
        fwrule2 = FirewallRule(**cls.resource['fwrule'])
        fwrule2.port_range_start = 8080
        fwrule2.port_range_end = 8080
        fwrule2.name = "8080"
        cls.fwrule2 = cls.client.create_firewall_rule(
            datacenter_id=cls.datacenter['id'],
            server_id=cls.server['id'],
            nic_id=cls.nic1['id'],
            firewall_rule=fwrule2)
        cls.client.wait_for_completion(cls.fwrule2)
示例#5
0
from ionosenterprise.client import Datacenter, Volume, Server  # noqa

i = Datacenter(name='dc1', description='My New Datacenter', location='de/fkb')

response = client.create_datacenter(datacenter=i)
"""Create Complex Datacenter
"""

from ionosenterprise.client import IonosEnterpriseService  # noqa
from ionosenterprise.client import Datacenter, LAN, NIC, LoadBalancer, FirewallRule  # noqa

image_id = 'df8382a1-0f40-11e6-ab6b-52540005ab80'

fwrule1 = FirewallRule(name='Open SSH port',
                       protocol='TCP',
                       source_mac='01:23:45:67:89:00',
                       port_range_start=22,
                       port_range_end=22)

fwrule2 = FirewallRule(name='Allow PING',
                       protocol='ICMP',
                       icmp_type=8,
                       icmp_code=0)

fw_rules = [fwrule1, fwrule2]

nic1 = NIC(name='nic1',
           ips=['10.2.2.3'],
           dhcp='true',
           lan=1,
           firewall_active=True,