class FakeFacility:

    plumbery = FakePlumbery()

    settings = fakeParameters
    blueprints = fakeBlueprints

    DimensionDataNodeDriver.connectionCls.conn_classes = (
        None, DimensionDataMockHttp)
    DimensionDataBackupDriver.connectionCls.conn_classes = (
        None, DimensionDataMockHttp)
    DimensionDataMockHttp.type = None
    region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)
    backup = DimensionDataBackupDriver(*DIMENSIONDATA_PARAMS)
    location = FakeLocation()

    _cache_network_domains = []
    _cache_vlans = []

    def get_location_id(self):
        return 'EU6'

    def get_setting(self, label):
        if label in self.settings:
            return self.settings[label]

        return None
    def test_as_library(self):

        engine = PlumberyEngine(myEuropeanPlan, myAmericanBinding)
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        engine.set_shared_secret('fake_secret')
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')

        facilities = engine.list_facility('NA9')
        self.assertEqual(len(facilities), 1)

        facility = facilities[0]
        self.assertEqual(facility.get_setting('regionId'), 'dd-na')
        self.assertEqual(facility.get_setting('locationId'), 'NA9')

        self.assertTrue(facility.get_blueprint('fake') is None)

        blueprint = facility.get_blueprint('myBlueprint')

        node = blueprint['nodes'][0]
        self.assertEqual(list(node)[0], 'toto')

        config = node['toto']['cloud-config']
        self.assertEqual(config['hostname'], 'toto')
        self.assertEqual(config['write_files'][0]['content'].count('toto'), 6)

        engine.do('deploy')
        engine.do('dispose')
Exemple #3
0
def main():
    module = AnsibleModule(argument_spec=dict(
        region=dict(default='na', choices=dd_regions),
        state=dict(default='present', choices=['present', 'absent']),
        node_ids=dict(required=True,
                      type='list',
                      aliases=['server_id', 'server_ids', 'node_id']),
        scsi_id=dict(required=True, type='int'),
        speed=dict(default='STANDARD',
                   choices=['STANDARD', 'ECONOMY', 'HIGHPERFORMANCE']),
        size=dict(type='int'),
        verify_ssl_cert=dict(required=False, default=True, type='bool'),
        wait=dict(required=False, default=False, type='bool'),
        wait_timeout=dict(required=False, default=300, type='int'),
        wait_poll_interval=dict(required=False, default=2, type='int')))
    if not HAS_LIBCLOUD:
        module.fail_json(msg='libcloud is required for this module.')

    # set short vars for readability
    credentials = get_credentials()
    if credentials is False:
        module.fail_json("User credentials not found")
    user_id = credentials['user_id']
    key = credentials['key']
    region = 'dd-%s' % module.params['region']
    verify_ssl_cert = module.params['verify_ssl_cert']

    # Instantiate driver
    libcloud.security.VERIFY_SSL_CERT = verify_ssl_cert
    client = DimensionDataNodeDriver(user_id, key, region=region)

    handle_disk(module, client)
Exemple #4
0
    def test_lifecycle(self):

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        engine.set_shared_secret('fake_secret')
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')

        engine.do('build')
        engine.build_all_blueprints()
        engine.do('build', 'myBlueprint')
        engine.build_blueprint('myBlueprint')

        engine.do('deploy')
        engine.do('deploy', 'myBlueprint')

        engine.do('destroy')
        engine.destroy_all_blueprints()
        engine.do('destroy', 'myBlueprint')
        engine.destroy_blueprint('myBlueprint')

        engine.do('dispose')
        engine.do('dispose', 'myBlueprint')

        engine.do('polish')
        engine.polish_all_blueprints()
        engine.do('polish', 'myBlueprint')
        engine.polish_blueprint('myBlueprint')

        engine.do('refresh')
        engine.do('refresh', 'myBlueprint')

        engine.do('secrets')

        engine.do('start')
        engine.start_all_blueprints()
        engine.do('start', 'myBlueprint')
        engine.start_blueprint('myBlueprint')

        engine.do('stop')
        engine.stop_all_blueprints()
        engine.do('stop', 'myBlueprint')
        engine.stop_blueprint('myBlueprint')

        engine.do('wipe')
        engine.wipe_all_blueprints()
        engine.do('wipe', 'myBlueprint')
        engine.wipe_blueprint('myBlueprint')

        banner = engine.document_elapsed()
        self.assertEqual('Worked for you' in banner, True)
 def setUp(self):
     self.plumbery = PlumberyEngine()
     self.plumbery.set_user_name('fake_user')
     self.plumbery.set_user_password('fake_password')
     DimensionDataNodeDriver.connectionCls.conn_classes = (
         None, DimensionDataMockHttp)
     DimensionDataMockHttp.type = None
     self.plumbery.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)
     self.facility = PlumberyFacility(
         plumbery=self.plumbery, fittings=fakeFittings)
     self.facility.power_on()
Exemple #6
0
class FakeFacility:

    plumbery = FakePlumbery()

    DimensionDataNodeDriver.connectionCls.conn_classes = (None, DimensionDataMockHttp)
    DimensionDataMockHttp.type = None
    region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

    location = FakeLocation()

    _cache_network_domains = []
    _cache_vlans = []
    def test_process_blueprint(self):

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        engine.set_shared_secret('fake_secret')
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')
        engine.set_fittings(myPrivatePlan)

        engine.process_blueprint(action='dummy', names='fake')

        action = FakeAction({})
        engine.process_blueprint(action, names='fake')
        self.assertEqual(action.count, 205)
def do_polish(polisher):

    engine = PlumberyEngine(myInformation)
    engine.set_shared_secret('fake_secret')
    engine.set_user_name('fake_name')
    engine.set_user_password('fake_password')

    polisher.go(engine)

    facility = engine.list_facility('NA9')[0]
    DimensionDataNodeDriver.connectionCls.conn_classes = (
        None, DimensionDataMockHttp)
    DimensionDataMockHttp.type = None
    facility.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

    polisher.move_to(facility)

    blueprint = facility.get_blueprint('test')
    infrastructure = PlumberyInfrastructure(facility)
    container = infrastructure.get_container(blueprint)

    polisher.shine_container(container)

    nodes = PlumberyNodes(facility)

    node = nodes.get_node('stackstorm')
    polisher.shine_node(node=node,
                        settings=fakeNodeSettings,
                        container=container)

    node = nodes.get_node('node1')
    polisher.shine_node(node=node,
                        settings=fakeNodeSettings,
                        container=container)

    polisher.move_to(FakeFacility())

    polisher.shine_container(FakeContainer())

    polisher.shine_node(node=FakeNode(),
                        settings=fakeNodeSettings,
                        container=FakeContainer())

    polisher.reap()
    def test_set(self):

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        settings = {
            'safeMode': False,
            'polishers': [
                {
                    'ansible': {}
                },
                {
                    'configure': {}
                },
            ]
        }

        engine.set_settings(settings)
        self.assertEqual(engine.safeMode, False)

        engine.add_facility(myFacility)
        self.assertEqual(len(engine.facilities), 1)

        self.assertEqual(engine.get_shared_user(), 'root')
        engine.set_shared_user('ubuntu')
        self.assertEqual(engine.get_shared_user(), 'ubuntu')

        engine.set_shared_secret('fake_secret')
        self.assertEqual(engine.get_shared_secret(), 'fake_secret')

        random = engine.get_secret('random')
        self.assertEqual(len(random), 9)
        self.assertEqual(engine.get_secret('random'), random)

        engine.set_user_name('fake_name')
        self.assertEqual(engine.get_user_name(), 'fake_name')

        engine.set_user_password('fake_password')
        self.assertEqual(engine.get_user_password(), 'fake_password')
Exemple #10
0
class FakeFacility:

    _cache_network_domains = []
    _cache_vlans = []

    plumbery = FakePlumbery()
    DimensionDataNodeDriver.connectionCls.conn_classes = (
        None, DimensionDataMockHttp)
    DimensionDataMockHttp.type = None
    region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

    location = 1

    def get_image(self, name):
        return FakeImage()

    def power_on(self):
        pass

    def get_location_id(self):
        return 'EU6'
 def test_invalid_region(self):
     try:
         self.driver = DimensionData(*DIMENSIONDATA_PARAMS, region='blah')
     except ValueError:
         pass
Exemple #12
0
class DimensionDataTests(unittest.TestCase, TestCaseMixin):
    def setUp(self):
        DimensionData.connectionCls.conn_classes = (None,
                                                    DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.driver = DimensionData(*DIMENSIONDATA_PARAMS)

    def test_invalid_region(self):
        try:
            self.driver = DimensionData(*DIMENSIONDATA_PARAMS, region='blah')
        except ValueError:
            pass

    def test_invalid_creds(self):
        DimensionDataMockHttp.type = 'UNAUTHORIZED'
        try:
            self.driver.list_nodes()
            self.assertTrue(
                False
            )  # Above command should have thrown an InvalidCredsException
        except InvalidCredsError:
            pass

    def test_list_locations_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_locations()
        self.assertEqual(len(ret), 1)
        first_node = ret[0]
        self.assertEqual(first_node.id, 'NA10')
        self.assertEqual(first_node.name, 'US - West')
        self.assertEqual(first_node.country, 'US')

    def test_list_nodes_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_nodes()
        self.assertEqual(len(ret), 3)

    def test_list_sizes_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_sizes()
        self.assertEqual(len(ret), 1)
        size = ret[0]
        self.assertEqual(size.name, 'default')

    def test_reboot_node_response(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = node.reboot()
        self.assertTrue(ret is True)

    def test_reboot_node_response_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            node.reboot()
            self.assertTrue(
                False
            )  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_destroy_node_response(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = node.destroy()
        self.assertTrue(ret is True)

    def test_destroy_node_response_RESOURCE_BUSY(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            node.destroy()
            self.assertTrue(
                False
            )  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_create_node_response(self):
        rootPw = NodeAuthPassword('pass123')
        image = self.driver.list_images()[0]
        network = self.driver.ex_list_networks()[0]
        node = self.driver.create_node(name='test2',
                                       image=image,
                                       auth=rootPw,
                                       ex_description='test2 node',
                                       ex_network=network,
                                       ex_isStarted=False)
        self.assertEqual(node.id, 'e75ead52-692f-4314-8725-c8a4f4d13a87')
        self.assertEqual(node.extra['status'].action, 'DEPLOY_SERVER')

    def test_create_node_no_network(self):
        rootPw = NodeAuthPassword('pass123')
        image = self.driver.list_images()[0]
        try:
            self.driver.create_node(name='test2',
                                    image=image,
                                    auth=rootPw,
                                    ex_description='test2 node',
                                    ex_network=None,
                                    ex_isStarted=False)
        except ValueError:
            pass

    def test_ex_shutdown_graceful(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = self.driver.ex_shutdown_graceful(node)
        self.assertTrue(ret is True)

    def test_ex_shutdown_graceful_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            self.driver.ex_shutdown_graceful(node)
            self.assertTrue(
                False
            )  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_start_node(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = self.driver.ex_start_node(node)
        self.assertTrue(ret is True)

    def test_ex_start_node_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            self.driver.ex_start_node(node)
            self.assertTrue(
                False
            )  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_power_off(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = self.driver.ex_power_off(node)
        self.assertTrue(ret is True)

    def test_ex_power_off_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            self.driver.ex_power_off(node)
            self.assertTrue(
                False
            )  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_reset(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = self.driver.ex_reset(node)
        self.assertTrue(ret is True)

    def test_list_networks(self):
        nets = self.driver.list_networks()
        self.assertEqual(nets[0].name, 'test-net1')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_list_networks(self):
        nets = self.driver.ex_list_networks()
        self.assertEqual(nets[0].name, 'test-net1')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_list_network_domains(self):
        nets = self.driver.ex_list_network_domains()
        self.assertEqual(nets[0].name, 'Production Network Domain')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_list_vlans(self):
        vlans = self.driver.ex_list_vlans()
        self.assertEqual(vlans[0].name, "Production VLAN")
Exemple #13
0
 def setUp(self):
     DimensionData.connectionCls.conn_classes = (None, DimensionDataMockHttp)
     DimensionDataMockHttp.type = None
     self.driver = DimensionData(*DIMENSIONDATA_PARAMS)
Exemple #14
0
    def test_set(self):

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        file = os.path.abspath(
            os.path.dirname(__file__)) + '/fixtures/dummy_rsa.pub'

        settings = {
            'keys': ["*hello-there*"],
        }

        with self.assertRaises(ValueError):
            engine.set_settings(settings)

        settings = {
            'keys': [file],
        }

        engine.set_settings(settings)
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertTrue(file in engine.get_shared_key_files())

        settings = {
            'safeMode': False,
            'polishers': [
                {
                    'ansible': {}
                },
                {
                    'configure': {}
                },
            ],
            'keys': [file, file],
        }

        engine.set_settings(settings)
        self.assertEqual(engine.safeMode, False)
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertTrue(file in engine.get_shared_key_files())

        engine.add_facility(myFacility)
        self.assertEqual(len(engine.facilities), 1)

        self.assertEqual(engine.get_shared_user(), 'root')
        engine.set_shared_user('ubuntu')
        self.assertEqual(engine.get_shared_user(), 'ubuntu')

        engine.set_shared_secret('fake_secret')
        self.assertEqual(engine.get_shared_secret(), 'fake_secret')

        random = engine.get_secret('random')
        self.assertEqual(len(random), 9)
        self.assertEqual(engine.get_secret('random'), random)

        engine.set_user_name('fake_name')
        self.assertEqual(engine.get_user_name(), 'fake_name')

        engine.set_user_password('fake_password')
        self.assertEqual(engine.get_user_password(), 'fake_password')
#!/usr/bin/env python

from libcloud.compute.drivers.dimensiondata import DimensionDataNodeDriver
from libcloud.common.dimensiondata import DEFAULT_REGION
import argparse
import json

parser = argparse.ArgumentParser(description='Dumppppp')
parser.add_argument('--user')
parser.add_argument('--password')
parser.add_argument('--region', default=DEFAULT_REGION)
args = parser.parse_args()

client = DimensionDataNodeDriver(args.user, args.password, args.region)

network_domains = client.ex_list_network_domains()

all_data = {}
for network_domain in network_domains:
    firewall_rules = client.ex_list_firewall_rules(network_domain)
    all_rules = []
    for firewall_rule in firewall_rules:
        temp_dict = {}
        temp_dict['id'] = firewall_rule.id
        temp_dict['name'] = firewall_rule.name
        temp_dict['action'] = firewall_rule.action
        temp_dict['ip_version'] = firewall_rule.ip_version
        temp_dict['protocol'] = firewall_rule.protocol
        temp_dict['enabled'] = firewall_rule.enabled
        temp_dict['source'] = {
            'any_ip': firewall_rule.source.any_ip,
Exemple #16
0
class DimensionDataTests(unittest.TestCase, TestCaseMixin):

    def setUp(self):
        DimensionData.connectionCls.conn_classes = (None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.driver = DimensionData(*DIMENSIONDATA_PARAMS)

    def test_invalid_creds(self):
        DimensionDataMockHttp.type = 'UNAUTHORIZED'
        try:
            self.driver.list_nodes()
            self.assertTrue(
                False)  # Above command should have thrown an InvalidCredsException
        except InvalidCredsError:
            pass

    def test_list_sizes_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_sizes()
        self.assertEqual(len(ret), 1)
        size = ret[0]
        self.assertEqual(size.name, 'default')

    def test_reboot_node_response(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = node.reboot()
        self.assertTrue(ret is True)

    def test_reboot_node_response_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            node.reboot()
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_destroy_node_response(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = node.destroy()
        self.assertTrue(ret is True)

    def test_destroy_node_response_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            node.destroy()
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_create_node_response(self):
        rootPw = NodeAuthPassword('pass123')
        image = self.driver.list_images()[0]
        network = self.driver.ex_list_networks()[0]
        node = self.driver.create_node(name='test2', image=image, auth=rootPw,
                                       ex_description='test2 node', ex_network=network,
                                       ex_isStarted=False)
        self.assertEqual(node.id, 'e75ead52-692f-4314-8725-c8a4f4d13a87')
        self.assertEqual(node.extra['status'].action, 'DEPLOY_SERVER')

    def test_ex_shutdown_graceful(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_shutdown_graceful(node)
        self.assertTrue(ret is True)

    def test_ex_shutdown_graceful_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_shutdown_graceful(node)
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_start_node(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_start_node(node)
        self.assertTrue(ret is True)

    def test_ex_start_node_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_start_node(node)
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_power_off(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_power_off(node)
        self.assertTrue(ret is True)

    def test_ex_power_off_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_power_off(node)
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_list_networks(self):
        nets = self.driver.ex_list_networks()
        self.assertEqual(nets[0].name, 'test-net1')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_node_public_ip(self):
        nodes = self.driver.list_nodes()
        node = [n for n in nodes if n.id ==
                'abadbc7e-9e10-46ca-9d4a-194bcc6b6c16'][0]
        self.assertEqual(node.public_ips[0], '200.16.132.7')
#!/usr/bin/env python

from libcloud.compute.drivers.dimensiondata import DimensionDataNodeDriver
from libcloud.common.dimensiondata import DEFAULT_REGION
import argparse
import json

parser = argparse.ArgumentParser(description='Dumppppp')
parser.add_argument('--user')
parser.add_argument('--password')
parser.add_argument('--region', default=DEFAULT_REGION)
args = parser.parse_args()

client = DimensionDataNodeDriver(args.user, args.password, args.region)

nodes = client.list_nodes()


node_list = []
#We need to convert a List of Nodes to a list of dictionarys.  Silly I know,
#The other option is to add .to_json methods or write a json parser for node objects
for node in nodes:
    temp_dict = {}
    temp_dict['id'] = node.id
    temp_dict['name'] = node.name
    temp_dict['public_ips'] = node.public_ips
    temp_dict['private_ips'] = node.private_ips
    temp_dict['memoryMb'] = node.extra['memoryMb']
    temp_dict['cpu'] = {'cpuCount': node.extra['cpu'].cpu_count,
                        'cores_per_socket': node.extra['cpu'].cores_per_socket,
                        'performace': node.extra['cpu'].performance
Exemple #18
0
class DimensionDataTests(unittest.TestCase, TestCaseMixin):
    def setUp(self):
        DimensionData.connectionCls.conn_classes = (None,
                                                    DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.driver = DimensionData(*DIMENSIONDATA_PARAMS)

    def test_invalid_region(self):
        try:
            self.driver = DimensionData(*DIMENSIONDATA_PARAMS, region='blah')
        except ValueError:
            pass

    def test_invalid_creds(self):
        DimensionDataMockHttp.type = 'UNAUTHORIZED'
        try:
            self.driver.list_nodes()
            self.assertTrue(
                False
            )  # Above command should have thrown an InvalidCredsException
        except InvalidCredsError:
            pass

    def test_list_locations_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_locations()
        self.assertEqual(len(ret), 5)
        first_node = ret[0]
        self.assertEqual(first_node.id, 'NA3')
        self.assertEqual(first_node.name, 'US - West')
        self.assertEqual(first_node.country, 'US')

    def test_list_nodes_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_nodes()
        self.assertEqual(len(ret), 3)

    def test_list_sizes_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_sizes()
        self.assertEqual(len(ret), 1)
        size = ret[0]
        self.assertEqual(size.name, 'default')

    def test_reboot_node_response(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = node.reboot()
        self.assertTrue(ret is True)

    def test_reboot_node_response_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            node.reboot()
            self.assertTrue(
                False
            )  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_destroy_node_response(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = node.destroy()
        self.assertTrue(ret is True)

    def test_destroy_node_response_RESOURCE_BUSY(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            node.destroy()
            self.assertTrue(
                False
            )  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_create_node_response(self):
        rootPw = NodeAuthPassword('pass123')
        image = self.driver.list_images()[0]
        network = self.driver.ex_list_networks()[0]
        node = self.driver.create_node(name='test2',
                                       image=image,
                                       auth=rootPw,
                                       ex_description='test2 node',
                                       ex_network=network,
                                       ex_is_started=False)
        self.assertEqual(node.id, 'e75ead52-692f-4314-8725-c8a4f4d13a87')
        self.assertEqual(node.extra['status'].action, 'DEPLOY_SERVER')

    def test_create_node_response_network_domain(self):
        rootPw = NodeAuthPassword('pass123')
        location = self.driver.ex_get_location_by_id('NA9')
        image = self.driver.list_images(location=location)[0]
        network_domain = self.driver.ex_list_network_domains(
            location=location)[0]
        vlan = self.driver.ex_list_vlans(location=location)[0]
        node = self.driver.create_node(name='test2',
                                       image=image,
                                       auth=rootPw,
                                       ex_description='test2 node',
                                       ex_network_domain=network_domain,
                                       ex_vlan=vlan,
                                       ex_is_started=False)
        self.assertEqual(node.id, 'e75ead52-692f-4314-8725-c8a4f4d13a87')
        self.assertEqual(node.extra['status'].action, 'DEPLOY_SERVER')

    def test_create_node_no_network(self):
        rootPw = NodeAuthPassword('pass123')
        image = self.driver.list_images()[0]
        try:
            self.driver.create_node(name='test2',
                                    image=image,
                                    auth=rootPw,
                                    ex_description='test2 node',
                                    ex_network=None,
                                    ex_isStarted=False)
        except ValueError:
            pass

    def test_ex_shutdown_graceful(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = self.driver.ex_shutdown_graceful(node)
        self.assertTrue(ret is True)

    def test_ex_shutdown_graceful_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            self.driver.ex_shutdown_graceful(node)
            self.assertTrue(
                False
            )  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_start_node(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = self.driver.ex_start_node(node)
        self.assertTrue(ret is True)

    def test_ex_start_node_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            self.driver.ex_start_node(node)
            self.assertTrue(
                False
            )  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_power_off(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = self.driver.ex_power_off(node)
        self.assertTrue(ret is True)

    def test_ex_power_off_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            self.driver.ex_power_off(node)
            self.assertTrue(
                False
            )  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_reset(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = self.driver.ex_reset(node)
        self.assertTrue(ret is True)

    def test_ex_attach_node_to_vlan(self):
        node = self.driver.ex_get_node_by_id(
            'e75ead52-692f-4314-8725-c8a4f4d13a87')
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        ret = self.driver.ex_attach_node_to_vlan(node, vlan)
        self.assertTrue(ret)

    def test_ex_destroy_nic(self):
        node = self.driver.ex_destroy_nic(
            'a202e51b-41c0-4cfc-add0-b1c62fc0ecf6')
        self.assertTrue(node)

    def test_list_networks(self):
        nets = self.driver.list_networks()
        self.assertEqual(nets[0].name, 'test-net1')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_create_network(self):
        location = self.driver.ex_get_location_by_id('NA9')
        net = self.driver.ex_create_network(location, "Test Network", "test")
        self.assertEqual(net.id, "208e3a8e-9d2f-11e2-b29c-001517c4643e")
        self.assertEqual(net.name, "Test Network")

    def test_ex_delete_network(self):
        net = self.driver.ex_list_networks()[0]
        result = self.driver.ex_delete_network(net)
        self.assertTrue(result)

    def test_ex_rename_network(self):
        net = self.driver.ex_list_networks()[0]
        result = self.driver.ex_rename_network(net, "barry")
        self.assertTrue(result)

    def test_ex_create_network_domain(self):
        location = self.driver.ex_get_location_by_id('NA9')
        plan = NetworkDomainServicePlan.ADVANCED
        net = self.driver.ex_create_network_domain(location=location,
                                                   name='test',
                                                   description='test',
                                                   service_plan=plan)
        self.assertEqual(net.name, 'test')
        self.assertTrue(net.id, 'f14a871f-9a25-470c-aef8-51e13202e1aa')

    def test_ex_get_network_domain(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        self.assertEqual(net.id, '8cdfd607-f429-4df6-9352-162cfc0891be')
        self.assertEqual(net.description, 'test2')
        self.assertEqual(net.name, 'test')

    def test_ex_update_network_domain(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        net.name = 'new name'
        net2 = self.driver.ex_update_network_domain(net)
        self.assertEqual(net2.name, 'new name')

    def test_ex_delete_network_domain(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        result = self.driver.ex_delete_network_domain(net)
        self.assertTrue(result)

    def test_ex_list_networks(self):
        nets = self.driver.ex_list_networks()
        self.assertEqual(nets[0].name, 'test-net1')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_list_network_domains(self):
        nets = self.driver.ex_list_network_domains()
        self.assertEqual(nets[0].name, 'Aurora')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_list_vlans(self):
        vlans = self.driver.ex_list_vlans()
        self.assertEqual(vlans[0].name, "Primary")

    def test_ex_create_vlan(self, ):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        vlan = self.driver.ex_create_vlan(network_domain=net,
                                          name='test',
                                          private_ipv4_base_address='10.3.4.0',
                                          private_ipv4_prefix_size='24')
        self.assertEqual(vlan.id, 'cee8df03-9117-44cc-baaa-631ffa099683')

    def test_ex_get_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        self.assertEqual(vlan.id, '0e56433f-d808-4669-821d-812769517ff8')
        self.assertEqual(vlan.description, 'test2')
        self.assertEqual(vlan.status, 'NORMAL')
        self.assertEqual(vlan.name, 'Production VLAN')
        self.assertEqual(vlan.private_ipv4_range_address, '10.0.3.0')
        self.assertEqual(vlan.private_ipv4_range_size, '24')

    def test_ex_wait_for_state(self):
        self.driver.ex_wait_for_state(
            'NORMAL',
            self.driver.ex_get_vlan,
            vlan_id='0e56433f-d808-4669-821d-812769517ff8')

    def test_ex_update_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        vlan.name = 'new name'
        vlan2 = self.driver.ex_update_vlan(vlan)
        self.assertEqual(vlan2.name, 'new name')

    def test_ex_delete_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        result = self.driver.ex_delete_vlan(vlan)
        self.assertTrue(result)

    def test_ex_expand_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        vlan.private_ipv4_range_size = '23'
        vlan = self.driver.ex_expand_vlan(vlan)
        self.assertEqual(vlan.private_ipv4_range_size, '23')

    def test_ex_add_public_ip_block_to_network_domain(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        block = self.driver.ex_add_public_ip_block_to_network_domain(net)
        self.assertEqual(block.id, '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')

    def test_ex_list_public_ip_blocks(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        blocks = self.driver.ex_list_public_ip_blocks(net)
        self.assertEqual(blocks[0].base_ip, '168.128.4.18')
        self.assertEqual(blocks[0].size, '2')
        self.assertEqual(blocks[0].id, '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        self.assertEqual(blocks[0].location.id, 'NA9')
        self.assertEqual(blocks[0].network_domain.id, net.id)

    def test_ex_get_public_ip_block(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        block = self.driver.ex_get_public_ip_block(
            '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        self.assertEqual(block.base_ip, '168.128.4.18')
        self.assertEqual(block.size, '2')
        self.assertEqual(block.id, '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        self.assertEqual(block.location.id, 'NA9')
        self.assertEqual(block.network_domain.id, net.id)

    def test_ex_delete_public_ip_block(self):
        block = self.driver.ex_get_public_ip_block(
            '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        result = self.driver.ex_delete_public_ip_block(block)
        self.assertTrue(result)

    def test_ex_list_firewall_rules(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        rules = self.driver.ex_list_firewall_rules(net)
        self.assertEqual(rules[0].id, '756cba02-b0bc-48f4-aea5-9445870b6148')
        self.assertEqual(rules[0].network_domain.id,
                         '8cdfd607-f429-4df6-9352-162cfc0891be')
        self.assertEqual(rules[0].name, 'CCDEFAULT.BlockOutboundMailIPv4')
        self.assertEqual(rules[0].action, 'DROP')
        self.assertEqual(rules[0].ip_version, 'IPV4')
        self.assertEqual(rules[0].protocol, 'TCP')
        self.assertEqual(rules[0].source.ip_address, 'ANY')
        self.assertTrue(rules[0].source.any_ip)
        self.assertTrue(rules[0].destination.any_ip)

    def test_ex_create_firewall_rule(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        rules = self.driver.ex_list_firewall_rules(net)
        rule = self.driver.ex_create_firewall_rule(net, rules[0], 'FIRST')
        self.assertEqual(rule.id, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')

    def test_ex_get_firewall_rule(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_firewall_rule(
            net, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')
        self.assertEqual(rule.id, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')

    def test_ex_set_firewall_rule_state(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_firewall_rule(
            net, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')
        result = self.driver.ex_set_firewall_rule_state(rule, False)
        self.assertTrue(result)

    def test_ex_delete_firewall_rule(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_firewall_rule(
            net, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')
        result = self.driver.ex_delete_firewall_rule(rule)
        self.assertTrue(result)

    def test_ex_create_nat_rule(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_create_nat_rule(net, '1.2.3.4', '4.3.2.1')
        self.assertEqual(rule.id, 'd31c2db0-be6b-4d50-8744-9a7a534b5fba')

    def test_ex_list_nat_rules(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        rules = self.driver.ex_list_nat_rules(net)
        self.assertEqual(rules[0].id, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        self.assertEqual(rules[0].internal_ip, '10.0.0.15')
        self.assertEqual(rules[0].external_ip, '165.180.12.18')

    def test_ex_get_nat_rule(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_nat_rule(
            net, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        self.assertEqual(rule.id, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        self.assertEqual(rule.internal_ip, '10.0.0.16')
        self.assertEqual(rule.external_ip, '165.180.12.19')

    def test_ex_delete_nat_rule(self):
        net = self.driver.ex_get_network_domain(
            '8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_nat_rule(
            net, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        result = self.driver.ex_delete_nat_rule(rule)
        self.assertTrue(result)

    def test_ex_enable_monitoring(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_enable_monitoring(node, "ADVANCED")
        self.assertTrue(result)

    def test_ex_disable_monitoring(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_disable_monitoring(node)
        self.assertTrue(result)

    def test_ex_change_monitoring_plan(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_update_monitoring_plan(node, "ESSENTIALS")
        self.assertTrue(result)
Exemple #19
0
 def test_invalid_region(self):
     try:
         self.driver = DimensionData(*DIMENSIONDATA_PARAMS, region='blah')
     except ValueError:
         pass
class DimensionDataTests(unittest.TestCase, TestCaseMixin):

    def setUp(self):
        DimensionData.connectionCls.conn_classes = (None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.driver = DimensionData(*DIMENSIONDATA_PARAMS)

    def test_invalid_region(self):
        try:
            self.driver = DimensionData(*DIMENSIONDATA_PARAMS, region='blah')
        except ValueError:
            pass

    def test_invalid_creds(self):
        DimensionDataMockHttp.type = 'UNAUTHORIZED'
        try:
            self.driver.list_nodes()
            self.assertTrue(
                False)  # Above command should have thrown an InvalidCredsException
        except InvalidCredsError:
            pass

    def test_list_locations_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_locations()
        self.assertEqual(len(ret), 5)
        first_node = ret[0]
        self.assertEqual(first_node.id, 'NA3')
        self.assertEqual(first_node.name, 'US - West')
        self.assertEqual(first_node.country, 'US')

    def test_list_nodes_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_nodes()
        self.assertEqual(len(ret), 2)

    def test_list_sizes_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_sizes()
        self.assertEqual(len(ret), 1)
        size = ret[0]
        self.assertEqual(size.name, 'default')

    def test_reboot_node_response(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = node.reboot()
        self.assertTrue(ret is True)

    def test_reboot_node_response_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            node.reboot()
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_destroy_node_response(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = node.destroy()
        self.assertTrue(ret is True)

    def test_destroy_node_response_RESOURCE_BUSY(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            node.destroy()
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_list_images(self):
        images = self.driver.list_images()
        self.assertEqual(len(images), 3)
        self.assertEqual(images[0].name, 'RedHat 6 64-bit 2 CPU')
        self.assertEqual(images[0].id, 'c14b1a46-2428-44c1-9c1a-b20e6418d08c')
        self.assertEqual(images[0].extra['location'].id, 'NA9')
        self.assertEqual(images[0].extra['cpu'].cpu_count, 2)
        self.assertEqual(images[0].extra['OS_displayName'], 'REDHAT6/64')

    def test_ex_list_customer_images(self):
        images = self.driver.ex_list_customer_images()
        self.assertEqual(len(images), 3)
        self.assertEqual(images[0].name, 'ImportedCustomerImage')
        self.assertEqual(images[0].id, '5234e5c7-01de-4411-8b6e-baeb8d91cf5d')
        self.assertEqual(images[0].extra['location'].id, 'NA9')
        self.assertEqual(images[0].extra['cpu'].cpu_count, 4)
        self.assertEqual(images[0].extra['OS_displayName'], 'REDHAT6/64')

    def test_create_node_response(self):
        rootPw = NodeAuthPassword('pass123')
        image = self.driver.list_images()[0]
        network = self.driver.ex_list_networks()[0]
        node = self.driver.create_node(name='test2', image=image, auth=rootPw,
                                       ex_description='test2 node', ex_network=network,
                                       ex_is_started=False)
        self.assertEqual(node.id, 'e75ead52-692f-4314-8725-c8a4f4d13a87')
        self.assertEqual(node.extra['status'].action, 'DEPLOY_SERVER')

    def test_create_node_response_network_domain(self):
        rootPw = NodeAuthPassword('pass123')
        location = self.driver.ex_get_location_by_id('NA9')
        image = self.driver.list_images(location=location)[0]
        network_domain = self.driver.ex_list_network_domains(location=location)[0]
        vlan = self.driver.ex_list_vlans(location=location)[0]
        cpu = DimensionDataServerCpuSpecification(
            cpu_count=4,
            cores_per_socket=1,
            performance='HIGHPERFORMANCE'
        )
        node = self.driver.create_node(name='test2', image=image, auth=rootPw,
                                       ex_description='test2 node',
                                       ex_network_domain=network_domain,
                                       ex_vlan=vlan,
                                       ex_is_started=False, ex_cpu_specification=cpu,
                                       ex_memory_gb=4)
        self.assertEqual(node.id, 'e75ead52-692f-4314-8725-c8a4f4d13a87')
        self.assertEqual(node.extra['status'].action, 'DEPLOY_SERVER')

    def test_create_node_no_network(self):
        rootPw = NodeAuthPassword('pass123')
        image = self.driver.list_images()[0]
        try:
            self.driver.create_node(name='test2', image=image, auth=rootPw,
                                    ex_description='test2 node', ex_network=None,
                                    ex_isStarted=False)
        except ValueError:
            pass

    def test_ex_shutdown_graceful(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_shutdown_graceful(node)
        self.assertTrue(ret is True)

    def test_ex_shutdown_graceful_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_shutdown_graceful(node)
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_start_node(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_start_node(node)
        self.assertTrue(ret is True)

    def test_ex_start_node_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_start_node(node)
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_power_off(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_power_off(node)
        self.assertTrue(ret is True)

    def test_ex_update_vm_tools(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_update_vm_tools(node)
        self.assertTrue(ret is True)

    def test_ex_power_off_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_power_off(node)
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_reset(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_reset(node)
        self.assertTrue(ret is True)

    def test_ex_attach_node_to_vlan(self):
        node = self.driver.ex_get_node_by_id('e75ead52-692f-4314-8725-c8a4f4d13a87')
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        ret = self.driver.ex_attach_node_to_vlan(node, vlan)
        self.assertTrue(ret)

    def test_ex_destroy_nic(self):
        node = self.driver.ex_destroy_nic('a202e51b-41c0-4cfc-add0-b1c62fc0ecf6')
        self.assertTrue(node)

    def test_list_networks(self):
        nets = self.driver.list_networks()
        self.assertEqual(nets[0].name, 'test-net1')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_create_network(self):
        location = self.driver.ex_get_location_by_id('NA9')
        net = self.driver.ex_create_network(location, "Test Network", "test")
        self.assertEqual(net.id, "208e3a8e-9d2f-11e2-b29c-001517c4643e")
        self.assertEqual(net.name, "Test Network")

    def test_ex_delete_network(self):
        net = self.driver.ex_list_networks()[0]
        result = self.driver.ex_delete_network(net)
        self.assertTrue(result)

    def test_ex_rename_network(self):
        net = self.driver.ex_list_networks()[0]
        result = self.driver.ex_rename_network(net, "barry")
        self.assertTrue(result)

    def test_ex_create_network_domain(self):
        location = self.driver.ex_get_location_by_id('NA9')
        plan = NetworkDomainServicePlan.ADVANCED
        net = self.driver.ex_create_network_domain(location=location,
                                                   name='test',
                                                   description='test',
                                                   service_plan=plan)
        self.assertEqual(net.name, 'test')
        self.assertTrue(net.id, 'f14a871f-9a25-470c-aef8-51e13202e1aa')

    def test_ex_get_network_domain(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        self.assertEqual(net.id, '8cdfd607-f429-4df6-9352-162cfc0891be')
        self.assertEqual(net.description, 'test2')
        self.assertEqual(net.name, 'test')

    def test_ex_update_network_domain(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        net.name = 'new name'
        net2 = self.driver.ex_update_network_domain(net)
        self.assertEqual(net2.name, 'new name')

    def test_ex_delete_network_domain(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        result = self.driver.ex_delete_network_domain(net)
        self.assertTrue(result)

    def test_ex_list_networks(self):
        nets = self.driver.ex_list_networks()
        self.assertEqual(nets[0].name, 'test-net1')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_list_network_domains(self):
        nets = self.driver.ex_list_network_domains()
        self.assertEqual(nets[0].name, 'Aurora')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_list_vlans(self):
        vlans = self.driver.ex_list_vlans()
        self.assertEqual(vlans[0].name, "Primary")

    def test_ex_create_vlan(self,):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        vlan = self.driver.ex_create_vlan(network_domain=net,
                                          name='test',
                                          private_ipv4_base_address='10.3.4.0',
                                          private_ipv4_prefix_size='24')
        self.assertEqual(vlan.id, '0e56433f-d808-4669-821d-812769517ff8')

    def test_ex_get_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        self.assertEqual(vlan.id, '0e56433f-d808-4669-821d-812769517ff8')
        self.assertEqual(vlan.description, 'test2')
        self.assertEqual(vlan.status, 'NORMAL')
        self.assertEqual(vlan.name, 'Production VLAN')
        self.assertEqual(vlan.private_ipv4_range_address, '10.0.3.0')
        self.assertEqual(vlan.private_ipv4_range_size, 24)
        self.assertEqual(vlan.ipv6_range_size, 64)
        self.assertEqual(vlan.ipv6_range_address, '2607:f480:1111:1153:0:0:0:0')
        self.assertEqual(vlan.ipv4_gateway, '10.0.3.1')
        self.assertEqual(vlan.ipv6_gateway, '2607:f480:1111:1153:0:0:0:1')

    def test_ex_wait_for_state(self):
        self.driver.ex_wait_for_state('NORMAL',
                                      self.driver.ex_get_vlan,
                                      vlan_id='0e56433f-d808-4669-821d-812769517ff8')

    def test_ex_update_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        vlan.name = 'new name'
        vlan2 = self.driver.ex_update_vlan(vlan)
        self.assertEqual(vlan2.name, 'new name')

    def test_ex_delete_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        result = self.driver.ex_delete_vlan(vlan)
        self.assertTrue(result)

    def test_ex_expand_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        vlan.private_ipv4_range_size = '23'
        vlan = self.driver.ex_expand_vlan(vlan)
        self.assertEqual(vlan.private_ipv4_range_size, '23')

    def test_ex_add_public_ip_block_to_network_domain(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        block = self.driver.ex_add_public_ip_block_to_network_domain(net)
        self.assertEqual(block.id, '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')

    def test_ex_list_public_ip_blocks(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        blocks = self.driver.ex_list_public_ip_blocks(net)
        self.assertEqual(blocks[0].base_ip, '168.128.4.18')
        self.assertEqual(blocks[0].size, '2')
        self.assertEqual(blocks[0].id, '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        self.assertEqual(blocks[0].location.id, 'NA9')
        self.assertEqual(blocks[0].network_domain.id, net.id)

    def test_ex_get_public_ip_block(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        block = self.driver.ex_get_public_ip_block('9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        self.assertEqual(block.base_ip, '168.128.4.18')
        self.assertEqual(block.size, '2')
        self.assertEqual(block.id, '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        self.assertEqual(block.location.id, 'NA9')
        self.assertEqual(block.network_domain.id, net.id)

    def test_ex_delete_public_ip_block(self):
        block = self.driver.ex_get_public_ip_block('9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        result = self.driver.ex_delete_public_ip_block(block)
        self.assertTrue(result)

    def test_ex_list_firewall_rules(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rules = self.driver.ex_list_firewall_rules(net)
        self.assertEqual(rules[0].id, '756cba02-b0bc-48f4-aea5-9445870b6148')
        self.assertEqual(rules[0].network_domain.id, '8cdfd607-f429-4df6-9352-162cfc0891be')
        self.assertEqual(rules[0].name, 'CCDEFAULT.BlockOutboundMailIPv4')
        self.assertEqual(rules[0].action, 'DROP')
        self.assertEqual(rules[0].ip_version, 'IPV4')
        self.assertEqual(rules[0].protocol, 'TCP')
        self.assertEqual(rules[0].source.ip_address, 'ANY')
        self.assertTrue(rules[0].source.any_ip)
        self.assertTrue(rules[0].destination.any_ip)

    def test_ex_create_firewall_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rules = self.driver.ex_list_firewall_rules(net)
        rule = self.driver.ex_create_firewall_rule(net, rules[0], 'FIRST')
        self.assertEqual(rule.id, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')

    def test_ex_get_firewall_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_firewall_rule(net, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')
        self.assertEqual(rule.id, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')

    def test_ex_set_firewall_rule_state(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_firewall_rule(net, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')
        result = self.driver.ex_set_firewall_rule_state(rule, False)
        self.assertTrue(result)

    def test_ex_delete_firewall_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_firewall_rule(net, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')
        result = self.driver.ex_delete_firewall_rule(rule)
        self.assertTrue(result)

    def test_ex_create_nat_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_create_nat_rule(net, '1.2.3.4', '4.3.2.1')
        self.assertEqual(rule.id, 'd31c2db0-be6b-4d50-8744-9a7a534b5fba')

    def test_ex_list_nat_rules(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rules = self.driver.ex_list_nat_rules(net)
        self.assertEqual(rules[0].id, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        self.assertEqual(rules[0].internal_ip, '10.0.0.15')
        self.assertEqual(rules[0].external_ip, '165.180.12.18')

    def test_ex_get_nat_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_nat_rule(net, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        self.assertEqual(rule.id, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        self.assertEqual(rule.internal_ip, '10.0.0.16')
        self.assertEqual(rule.external_ip, '165.180.12.19')

    def test_ex_delete_nat_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_nat_rule(net, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        result = self.driver.ex_delete_nat_rule(rule)
        self.assertTrue(result)

    def test_ex_enable_monitoring(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_enable_monitoring(node, "ADVANCED")
        self.assertTrue(result)

    def test_ex_disable_monitoring(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_disable_monitoring(node)
        self.assertTrue(result)

    def test_ex_change_monitoring_plan(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_update_monitoring_plan(node, "ESSENTIALS")
        self.assertTrue(result)

    def test_ex_add_storage_to_node(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_add_storage_to_node(node, 30, 'PERFORMANCE')
        self.assertTrue(result)

    def test_ex_remove_storage_from_node(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_remove_storage_from_node(node, 1)
        self.assertTrue(result)

    def test_ex_change_storage_speed(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_change_storage_speed(node, 1, 'PERFORMANCE')
        self.assertTrue(result)

    def test_ex_change_storage_size(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_change_storage_size(node, 1, 100)
        self.assertTrue(result)

    def test_ex_clone_node_to_image(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_clone_node_to_image(node, 'my image', 'a description')
        self.assertTrue(result)

    def test_ex_update_node(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_update_node(node, 'my new name', 'a description', 2, 4048)
        self.assertTrue(result)

    def test_ex_reconfigure_node(self):
        node = self.driver.list_nodes()[0]
        result = self.driver.ex_reconfigure_node(node, 4, 4, 1, 'HIGHPERFORMANCE')
        self.assertTrue(result)
Exemple #21
0
 def _get_compute_driver(self, region):
     api_user = self.config['api_user']
     api_pass = self.config['api_password']
     driver = DimensionDataNodeDriver(api_user, api_pass, region=region)
     return driver
Exemple #22
0
 def init_client(self, user, password, region=DEFAULT_REGION):
     self.node = DimensionDataNodeDriver(user, password, region)
     self.backup = DimensionDataBackupDriver(user, password, region)
Exemple #23
0
class DimensionDataTests(unittest.TestCase, TestCaseMixin):

    def setUp(self):
        DimensionData.connectionCls.conn_classes = (None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.driver = DimensionData(*DIMENSIONDATA_PARAMS)

    def test_invalid_region(self):
        try:
            self.driver = DimensionData(*DIMENSIONDATA_PARAMS, region='blah')
        except ValueError:
            pass

    def test_invalid_creds(self):
        DimensionDataMockHttp.type = 'UNAUTHORIZED'
        try:
            self.driver.list_nodes()
            self.assertTrue(
                False)  # Above command should have thrown an InvalidCredsException
        except InvalidCredsError:
            pass

    def test_list_locations_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_locations()
        self.assertEqual(len(ret), 5)
        first_node = ret[0]
        self.assertEqual(first_node.id, 'NA3')
        self.assertEqual(first_node.name, 'US - West')
        self.assertEqual(first_node.country, 'US')

    def test_list_nodes_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_nodes()
        self.assertEqual(len(ret), 3)

    def test_list_sizes_response(self):
        DimensionDataMockHttp.type = None
        ret = self.driver.list_sizes()
        self.assertEqual(len(ret), 1)
        size = ret[0]
        self.assertEqual(size.name, 'default')

    def test_reboot_node_response(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = node.reboot()
        self.assertTrue(ret is True)

    def test_reboot_node_response_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            node.reboot()
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_destroy_node_response(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = node.destroy()
        self.assertTrue(ret is True)

    def test_destroy_node_response_RESOURCE_BUSY(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            node.destroy()
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_create_node_response(self):
        rootPw = NodeAuthPassword('pass123')
        image = self.driver.list_images()[0]
        network = self.driver.ex_list_networks()[0]
        node = self.driver.create_node(name='test2', image=image, auth=rootPw,
                                       ex_description='test2 node', ex_network=network,
                                       ex_is_started=False)
        self.assertEqual(node.id, 'e75ead52-692f-4314-8725-c8a4f4d13a87')
        self.assertEqual(node.extra['status'].action, 'DEPLOY_SERVER')

    def test_create_node_response_network_domain(self):
        rootPw = NodeAuthPassword('pass123')
        location = self.driver.ex_get_location_by_id('NA9')
        image = self.driver.list_images(location=location)[0]
        network_domain = self.driver.ex_list_network_domains(location=location)[0]
        vlan = self.driver.ex_list_vlans(location=location)[0]
        node = self.driver.create_node(name='test2', image=image, auth=rootPw,
                                       ex_description='test2 node',
                                       ex_network_domain=network_domain,
                                       ex_vlan=vlan,
                                       ex_is_started=False)
        self.assertEqual(node.id, 'e75ead52-692f-4314-8725-c8a4f4d13a87')
        self.assertEqual(node.extra['status'].action, 'DEPLOY_SERVER')

    def test_create_node_no_network(self):
        rootPw = NodeAuthPassword('pass123')
        image = self.driver.list_images()[0]
        try:
            self.driver.create_node(name='test2', image=image, auth=rootPw,
                                    ex_description='test2 node', ex_network=None,
                                    ex_isStarted=False)
        except ValueError:
            pass

    def test_ex_shutdown_graceful(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_shutdown_graceful(node)
        self.assertTrue(ret is True)

    def test_ex_shutdown_graceful_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_shutdown_graceful(node)
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_start_node(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_start_node(node)
        self.assertTrue(ret is True)

    def test_ex_start_node_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_start_node(node)
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_power_off(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_power_off(node)
        self.assertTrue(ret is True)

    def test_ex_power_off_INPROGRESS(self):
        DimensionDataMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_power_off(node)
            self.assertTrue(
                False)  # above command should have thrown DimensionDataAPIException
        except DimensionDataAPIException:
            pass

    def test_ex_reset(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_reset(node)
        self.assertTrue(ret is True)

    def test_ex_attach_node_to_vlan(self):
        node = self.driver.ex_get_node_by_id('e75ead52-692f-4314-8725-c8a4f4d13a87')
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        ret = self.driver.ex_attach_node_to_vlan(node, vlan)
        self.assertTrue(ret)

    def test_ex_destroy_nic(self):
        node = self.driver.ex_destroy_nic('a202e51b-41c0-4cfc-add0-b1c62fc0ecf6')
        self.assertTrue(node)

    def test_list_networks(self):
        nets = self.driver.list_networks()
        self.assertEqual(nets[0].name, 'test-net1')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_create_network_domain(self):
        location = self.driver.ex_get_location_by_id('NA9')
        plan = NetworkDomainServicePlan.ADVANCED
        net = self.driver.ex_create_network_domain(location=location,
                                                   name='test',
                                                   description='test',
                                                   service_plan=plan)
        self.assertEqual(net.name, 'test')
        self.assertTrue(net.id, 'f14a871f-9a25-470c-aef8-51e13202e1aa')

    def test_ex_get_network_domain(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        self.assertEqual(net.id, '8cdfd607-f429-4df6-9352-162cfc0891be')
        self.assertEqual(net.description, 'test2')
        self.assertEqual(net.name, 'test')

    def test_ex_update_network_domain(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        net.name = 'new name'
        net2 = self.driver.ex_update_network_domain(net)
        self.assertEqual(net2.name, 'new name')

    def test_ex_delete_network_domain(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        result = self.driver.ex_delete_network_domain(net)
        self.assertTrue(result)

    def test_ex_list_networks(self):
        nets = self.driver.ex_list_networks()
        self.assertEqual(nets[0].name, 'test-net1')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_list_network_domains(self):
        nets = self.driver.ex_list_network_domains()
        self.assertEqual(nets[0].name, 'Aurora')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_ex_list_vlans(self):
        vlans = self.driver.ex_list_vlans()
        self.assertEqual(vlans[0].name, "Primary")

    def test_ex_create_vlan(self,):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        vlan = self.driver.ex_create_vlan(network_domain=net,
                                          name='test',
                                          private_ipv4_base_address='10.3.4.0',
                                          private_ipv4_prefix_size='24')
        self.assertEqual(vlan.id, 'cee8df03-9117-44cc-baaa-631ffa099683')

    def test_ex_get_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        self.assertEqual(vlan.id, '0e56433f-d808-4669-821d-812769517ff8')
        self.assertEqual(vlan.description, 'test2')
        self.assertEqual(vlan.name, 'Production VLAN')
        self.assertEqual(vlan.private_ipv4_range_address, '10.0.3.0')
        self.assertEqual(vlan.private_ipv4_range_size, '24')

    def test_ex_update_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        vlan.name = 'new name'
        vlan2 = self.driver.ex_update_vlan(vlan)
        self.assertEqual(vlan2.name, 'new name')

    def test_ex_delete_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        result = self.driver.ex_delete_vlan(vlan)
        self.assertTrue(result)

    def test_ex_expand_vlan(self):
        vlan = self.driver.ex_get_vlan('0e56433f-d808-4669-821d-812769517ff8')
        vlan.private_ipv4_range_size = '23'
        vlan = self.driver.ex_expand_vlan(vlan)
        self.assertEqual(vlan.private_ipv4_range_size, '23')

    def test_ex_add_public_ip_block_to_network_domain(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        block = self.driver.ex_add_public_ip_block_to_network_domain(net)
        self.assertEqual(block.id, '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')

    def test_ex_list_public_ip_blocks(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        blocks = self.driver.ex_list_public_ip_blocks(net)
        self.assertEqual(blocks[0].base_ip, '168.128.4.18')
        self.assertEqual(blocks[0].size, '2')
        self.assertEqual(blocks[0].id, '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        self.assertEqual(blocks[0].location.id, 'NA9')
        self.assertEqual(blocks[0].network_domain.id, net.id)

    def test_ex_get_public_ip_block(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        block = self.driver.ex_get_public_ip_block('9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        self.assertEqual(block.base_ip, '168.128.4.18')
        self.assertEqual(block.size, '2')
        self.assertEqual(block.id, '9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        self.assertEqual(block.location.id, 'NA9')
        self.assertEqual(block.network_domain.id, net.id)

    def test_ex_delete_public_ip_block(self):
        block = self.driver.ex_get_public_ip_block('9945dc4a-bdce-11e4-8c14-b8ca3a5d9ef8')
        result = self.driver.ex_delete_public_ip_block(block)
        self.assertTrue(result)

    def test_ex_list_firewall_rules(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rules = self.driver.ex_list_firewall_rules(net)
        self.assertEqual(rules[0].id, '756cba02-b0bc-48f4-aea5-9445870b6148')
        self.assertEqual(rules[0].network_domain.id, '8cdfd607-f429-4df6-9352-162cfc0891be')
        self.assertEqual(rules[0].name, 'CCDEFAULT.BlockOutboundMailIPv4')
        self.assertEqual(rules[0].action, 'DROP')
        self.assertEqual(rules[0].ip_version, 'IPV4')
        self.assertEqual(rules[0].protocol, 'TCP')
        self.assertEqual(rules[0].source.ip_address, 'ANY')
        self.assertTrue(rules[0].source.any_ip)
        self.assertTrue(rules[0].destination.any_ip)

    def test_ex_create_firewall_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rules = self.driver.ex_list_firewall_rules(net)
        rule = self.driver.ex_create_firewall_rule(net, rules[0], 'FIRST')
        self.assertEqual(rule.id, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')

    def test_ex_get_firewall_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_firewall_rule(net, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')
        self.assertEqual(rule.id, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')

    def test_ex_set_firewall_rule_state(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_firewall_rule(net, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')
        result = self.driver.ex_set_firewall_rule_state(rule, False)
        self.assertTrue(result)

    def test_ex_delete_firewall_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_firewall_rule(net, 'd0a20f59-77b9-4f28-a63b-e58496b73a6c')
        result = self.driver.ex_delete_firewall_rule(rule)
        self.assertTrue(result)

    def test_ex_create_nat_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_create_nat_rule(net, '1.2.3.4', '4.3.2.1')
        self.assertEqual(rule.id, 'd31c2db0-be6b-4d50-8744-9a7a534b5fba')

    def test_ex_list_nat_rules(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rules = self.driver.ex_list_nat_rules(net)
        self.assertEqual(rules[0].id, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        self.assertEqual(rules[0].internal_ip, '10.0.0.15')
        self.assertEqual(rules[0].external_ip, '165.180.12.18')

    def test_ex_get_nat_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_nat_rule(net, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        self.assertEqual(rule.id, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        self.assertEqual(rule.internal_ip, '10.0.0.16')
        self.assertEqual(rule.external_ip, '165.180.12.19')

    def test_ex_delete_nat_rule(self):
        net = self.driver.ex_get_network_domain('8cdfd607-f429-4df6-9352-162cfc0891be')
        rule = self.driver.ex_get_nat_rule(net, '2187a636-7ebb-49a1-a2ff-5d617f496dce')
        result = self.driver.ex_delete_nat_rule(rule)
        self.assertTrue(result)