예제 #1
0
 def test_timeout(self):
     with self.assertRaises(ApiConnectionError) as context:
         ElementFactory.create("10.194.99.0",
                               self.user,
                               self.password,
                               timeout=5)
     self.assertTrue('ConnectTimeout' in str(context.exception))
예제 #2
0
def get_solid_fire():
    auth = AuthStack()
    sf = ElementFactory.create(auth.solid_fire_ip,
                               auth.solid_fire_user,
                               auth.solid_fire_password,
                               print_ascii_art=False)
    return sf
예제 #3
0
    def test_change_frequency_dow_to_dom(self):
        sf = ElementFactory.create(self.cluster, self.user, self.pwd)

        vols = self.sf.list_volumes().volumes
        vol_ids = []
        for vol in vols:
            vol_ids.append(vol.volume_id)

        sched = Schedule(schedule_info=ScheduleInfo(volume_ids=vol_ids),
                         name=self.scheduleName,
                         frequency=DaysOfWeekFrequency(
                             hours=4,
                             minutes=30,
                             weekdays=[Weekday.from_id(1),
                                       Weekday.from_id(4)]))

        result = self.sf.create_schedule(sched)

        new_sched_id = result.schedule_id

        new_sched = self.sf.get_schedule(new_sched_id).schedule

        new_sched.frequency = DaysOfMonthFrequency(hours=5, monthdays=[4, 5])

        modified_sched = self.sf.modify_schedule(new_sched).schedule
    def test_create_but_missing_frequency(self):
        sf = ElementFactory.create("192.168.139.165", "admin", "admin")

        sched = Schedule()
        sched.name = "mySchedule"

        result = sf.create_schedule(sched)
예제 #5
0
def create_sf_connection(module,
                         port=None,
                         raise_on_connection_error=False,
                         timeout=None):
    hostname = module.params['hostname']
    username = module.params['username']
    password = module.params['password']
    options = dict()
    if port is not None:
        options['port'] = port
    if timeout is not None:
        options['timeout'] = timeout

    if HAS_SF_SDK:
        try:
            return_val = ElementFactory.create(hostname, username, password,
                                               **options)
            return return_val
        except (solidfire.common.ApiConnectionError,
                solidfire.common.ApiServerError) as exc:
            if raise_on_connection_error:
                raise exc
            module.fail_json(msg=repr(exc))
        except Exception as exc:
            raise Exception("Unable to create SF connection: %s" % repr(exc))

    module.fail_json(msg="the python SolidFire SDK module is required")
    def test_change_frequency_ti_to_dom(self):
        sf = ElementFactory.create("172.26.64.48", "admin", "admin")

        vols = sf.list_volumes().volumes
        vol_ids = []
        for vol in vols:
            vol_ids.append(vol.volume_id)

        sched = Schedule()
        sched.name = "mySchedule"
        sched.frequency = TimeIntervalFrequency(hours=5, days=1)

        sched.schedule_info = ScheduleInfo()
        sched.schedule_info.volume_ids = vol_ids

        result = sf.create_schedule(sched)

        new_sched_id = result.schedule_id

        new_sched = sf.get_schedule(new_sched_id).schedule

        new_sched.frequency = DaysOfWeekFrequency(hours=4, minutes=30,
                                               weekdays=[
                                                   Weekday.from_id(1),
                                                   Weekday.from_id(4)])

        sf.modify_schedule(new_sched)

        modified_sched = sf.get_schedule(new_sched_id).schedule
    def test_get_schedule(self):
        sf = ElementFactory.create("172.26.64.48", "admin", "admin")

        results = sf.get_schedule(786)

        for sched in results.schedules:
            assert_that(sched.frequency is None, equal_to(True))
예제 #8
0
    def test_change_frequency_ti_to_dom(self):
        sf = ElementFactory.create(self.cluster, self.user, self.pwd)

        vols = sf.list_volumes().volumes
        vol_ids = []
        for vol in vols:
            vol_ids.append(vol.volume_id)

        sched = Schedule()
        sched.name = "mySchedule"
        sched.frequency = TimeIntervalFrequency(hours=5, days=1)

        sched.schedule_info = ScheduleInfo()
        sched.schedule_info.volume_ids = vol_ids

        result = sf.create_schedule(sched)

        new_sched_id = result.schedule_id

        new_sched = sf.get_schedule(new_sched_id).schedule

        new_sched.frequency = DaysOfWeekFrequency(hours=4, minutes=30,
                                               weekdays=[
                                                   Weekday.from_id(1),
                                                   Weekday.from_id(4)])

        sf.modify_schedule(new_sched)

        modified_sched = sf.get_schedule(new_sched_id).schedule
예제 #9
0
    def test_lest_schedules(self):
        sf = ElementFactory.create(self.cluster, self.user, self.pwd)

        results = sf.list_schedules()

        for sched in results.schedules:
            freq = sched._properties['frequency']
            assert_that(freq is not None)
    def test_lest_schedules(self):
        sf = ElementFactory.create(self.cluster, self.user, self.password)

        results = self.sf.list_schedules()

        for sched in results.schedules:
            freq = sched.frequency
            self.assertNotEqual(freq, None)
    def test_create_but_missing_schedule_info(self):
        sf = ElementFactory.create(self.cluster, self.user, self.password)

        with self.assertRaises(TypeError) as context:
            sched = Schedule(name=self.scheduleName,
                             frequency=TimeIntervalFrequency(hours=4,
                                                             minutes=None,
                                                             days=None))
예제 #12
0
    def setUpClass(cls):
        # Set up API client
        testclient = super(TestAddRemoveHosts, cls).getClsTestClient()

        cls.apiClient = testclient.getApiClient()
        cls.configData = testclient.getParsedTestDataConfig()
        cls.dbConnection = testclient.getDbConnection()

        cls.testdata = TestData().testdata

        if TestData.hypervisor_type == TestData.xenServer:
            cls.xs_pool_master_ip = list_hosts(cls.apiClient, clusterid=cls.testdata[TestData.clusterId], name=TestData.xen_server_master_hostname)[0].ipaddress

        cls._connect_to_hypervisor()

        # Set up SolidFire connection
        solidfire = cls.testdata[TestData.solidFire]

        cls.sfe = ElementFactory.create(solidfire[TestData.mvip], solidfire[TestData.username], solidfire[TestData.password])

        # Get Resources from Cloud Infrastructure
        cls.zone = get_zone(cls.apiClient, zone_id=cls.testdata[TestData.zoneId])
        cls.cluster = list_clusters(cls.apiClient)[0]
        cls.template = get_template(cls.apiClient, cls.zone.id, cls.configData["ostype"])
        cls.domain = get_domain(cls.apiClient, cls.testdata[TestData.domainId])

        # Create test account
        cls.account = Account.create(
            cls.apiClient,
            cls.testdata[TestData.account],
            admin=1
        )

        # Set up connection to make customized API calls
        user = User.create(
            cls.apiClient,
            cls.testdata[TestData.user],
            account=cls.account.name,
            domainid=cls.domain.id
        )

        url = cls.testdata[TestData.url]

        api_url = "http://" + url + ":8080/client/api"
        userkeys = User.registerUserKeys(cls.apiClient, user.id)

        cls.cs_api = SignedAPICall.CloudStack(api_url, userkeys.apikey, userkeys.secretkey)

        cls.compute_offering = ServiceOffering.create(
            cls.apiClient,
            cls.testdata[TestData.computeOffering]
        )

        cls._cleanup = [
            cls.compute_offering,
            user,
            cls.account
        ]
예제 #13
0
    def test_should_map_API_errors(self):
        sf = ElementFactory.create(self.cluster, self.user, self.password)
        try:
            sf.get_account_by_name("hfeiruhguireshgruieshiurehsiuvhreush"
                                   )  #impossible name, intended API error
        except ApiServerError as error:
            err_tmp = json.loads(error._err_json)
            err_tmp.pop('id', None)
            dct_tmp = json.loads(
                '{"error": {"code": 500, "message": "xUnknownAccount", "name": "xUnknownAccount"}}'
            )
            self.assertEqual(
                sorted(err_tmp.items()) == sorted(dct_tmp.items()), True)
            self.assertEqual(error.method_name, "GetAccountByName")
            self.assertEqual(error.error_name, "xUnknownAccount")
            self.assertEqual(error.message, "xUnknownAccount")
            self.assertEqual(error.error_code, 500)

        try:
            sf.get_async_result(
                "999999999")  #impossible async handle, intended API error
        except ApiServerError as error:
            err_tmp = json.loads(error._err_json)
            err_tmp.pop('id', None)
            dct_tmp = json.loads(
                '{"error": {"code": 500, "message": "Async handle 999999999 does not exist.", "name": "xAsyncHandleDoesNotExist"}}'
            )
            self.assertEqual(
                sorted(err_tmp.items()) == sorted(dct_tmp.items()), True)
            self.assertEqual(error.method_name, "GetAsyncResult")
            self.assertEqual(error.error_name, "xAsyncHandleDoesNotExist")
            self.assertEqual(error.message,
                             "Async handle 999999999 does not exist.")
            self.assertEqual(error.error_code, 500)

        snap_mirror_enabled = sf.get_feature_status(
            feature="SnapMirror").features[0].enabled

        if not snap_mirror_enabled:
            try:
                sf.create_snap_mirror_endpoint(
                    "8.8.8.8", "admin", "admin")  #bad ID, intended API error
            except ApiServerError as error:
                err_tmp = json.loads(error._err_json)
                err_tmp.pop('id', None)
                dct_tmp = json.loads(
                    '{"error": {"code": 500, "message": "SnapMirror feature not enabled, use the EnableFeature API method to enable it", "name": "xFeatureNotEnabled"}}'
                )
                self.assertEqual(
                    sorted(err_tmp.items()) == sorted(dct_tmp.items()), True)
                self.assertEqual(error.method_name, "CreateSnapMirrorEndpoint")
                self.assertEqual(error.error_name, "xFeatureNotEnabled")  #
                self.assertEqual(
                    error.message,
                    "SnapMirror feature not enabled, use the EnableFeature API method to enable it"
                )  #
                self.assertEqual(error.error_code, 500)
    def setUpClass(cls):
        # Set up API client
        testclient = super(TestAddRemoveHosts, cls).getClsTestClient()

        cls.apiClient = testclient.getApiClient()
        cls.configData = testclient.getParsedTestDataConfig()
        cls.dbConnection = testclient.getDbConnection()

        cls.testdata = TestData().testdata

        if TestData.hypervisor_type == TestData.xenServer:
            cls.xs_pool_master_ip = list_hosts(
                cls.apiClient,
                clusterid=cls.testdata[TestData.clusterId],
                name=TestData.xen_server_master_hostname)[0].ipaddress

        cls._connect_to_hypervisor()

        # Set up SolidFire connection
        solidfire = cls.testdata[TestData.solidFire]

        cls.sfe = ElementFactory.create(solidfire[TestData.mvip],
                                        solidfire[TestData.username],
                                        solidfire[TestData.password])

        # Get Resources from Cloud Infrastructure
        cls.zone = get_zone(cls.apiClient,
                            zone_id=cls.testdata[TestData.zoneId])
        cls.cluster = list_clusters(cls.apiClient)[0]
        cls.template = get_template(cls.apiClient,
                                    cls.zone.id,
                                    hypervisor=TestData.hypervisor_type)
        cls.domain = get_domain(cls.apiClient, cls.testdata[TestData.domainId])

        # Create test account
        cls.account = Account.create(cls.apiClient,
                                     cls.testdata[TestData.account],
                                     admin=1)

        # Set up connection to make customized API calls
        user = User.create(cls.apiClient,
                           cls.testdata[TestData.user],
                           account=cls.account.name,
                           domainid=cls.domain.id)

        url = cls.testdata[TestData.url]

        api_url = "http://" + url + ":8080/client/api"
        userkeys = User.registerUserKeys(cls.apiClient, user.id)

        cls.cs_api = SignedAPICall.CloudStack(api_url, userkeys.apikey,
                                              userkeys.secretkey)

        cls.compute_offering = ServiceOffering.create(
            cls.apiClient, cls.testdata[TestData.computeOffering])

        cls._cleanup = [cls.compute_offering, user, cls.account]
예제 #15
0
    def test_create_but_time_interval_days_minutes_is_None(self):
        sf = ElementFactory.create(self.cluster, self.user, self.pwd)
        sched = Schedule()
        sched.name = "mySchedule"
        sched.frequency = TimeIntervalFrequency(hours=4)
        sched.schedule_info = ScheduleInfo()
        sched.schedule_info.volume_ids = [1]

        result = sf.create_schedule(sched)
예제 #16
0
    def test_create_but_missing_frequency(self):
        sf = ElementFactory.create(self.cluster, self.user, self.pwd)

        with self.assertRaises(TypeError) as context:
            sched = Schedule(name=self.scheduleName)

        self.assertTrue(
            "missing 2 required positional arguments: 'schedule_info' and 'frequency'"
            in str(context.exception))
    def test_create_but_time_interval_days_minutes_is_None(self):
        sf = ElementFactory.create("192.168.139.165", "admin", "admin")

        sched = Schedule()
        sched.name = "mySchedule"
        sched.frequency = TimeIntervalFrequency(hours=4)
        sched.schedule_info = ScheduleInfo()
        sched.schedule_info.volume_ids = [1]

        result = sf.create_schedule(sched)
    def test_lest_schedules(self):
        sf = ElementFactory.create("172.26.64.48", "admin", "admin")

        results = sf.list_schedules()

        for sched in results.schedules:
            assert_that(type(sched.frequency) is TimeIntervalFrequency or
                            type(sched.frequency) is DaysOfMonthFrequency or
                            type(sched.frequency) is DaysOfWeekFrequency,
                        equal_to(True))
예제 #19
0
    def test_create_but_missing_frequency(self):
        sf = ElementFactory.create(self.cluster, self.user, self.pwd)

        sched = Schedule()
        sched.name = "mySchedule"

        with self.assertRaises(AttributeError) as context:
            result = sf.create_schedule(sched)

        self.assertTrue('Frequency is not present' in str(context.exception))
    def test_create_but_missing_schedule_info(self):
        sf = ElementFactory.create("192.168.139.165", "admin", "admin")

        sched = Schedule()
        sched.name = "mySchedule"
        sched.frequency = TimeIntervalFrequency(hours=4, minutes=30, days=2)
        sched.frequency.hours = 4
        sched.frequency.minutes = 30
        sched.frequency.days = 2

        result = sf.create_schedule(sched)
예제 #21
0
파일: netapp.py 프로젝트: Stienvdh/statrick
def create_sf_connection(module, port=None):
    hostname = module.params['hostname']
    username = module.params['username']
    password = module.params['password']

    if HAS_SF_SDK and hostname and username and password:
        try:
            return_val = ElementFactory.create(hostname, username, password, port=port)
            return return_val
        except Exception:
            raise Exception("Unable to create SF connection")
    module.fail_json(msg="the python SolidFire SDK module is required")
예제 #22
0
    def test_create_but_missing_schedule_info(self):
        sf = ElementFactory.create(self.cluster, self.user, self.pwd)

        with self.assertRaises(TypeError) as context:
            sched = Schedule(name=self.scheduleName,
                             frequency=TimeIntervalFrequency(hours=4,
                                                             minutes=None,
                                                             days=None))

        self.assertTrue(
            "missing 1 required positional argument: 'schedule_info'" in str(
                context.exception))
    def test_create_but_schedule_info_volumes_empty(self):
        sf = ElementFactory.create("192.168.139.165", "admin", "admin")

        sched = Schedule()
        sched.name = "mySchedule"
        sched.frequency = TimeIntervalFrequency(hours=4, minutes=30, days=2)
        sched.frequency.hours = 4
        sched.frequency.minutes = 30
        sched.frequency.days = 2
        sched.schedule_info = ScheduleInfo()
        sched.schedule_info.volume_ids = []
        result = sf.create_schedule(sched)
    def test_create_but_volume_does_not_exist(self):
        sf = ElementFactory.create(self.cluster, self.user, self.password)

        sched = Schedule(schedule_info=ScheduleInfo(volume_ids=[0]),
                         name=self.scheduleName,
                         frequency=TimeIntervalFrequency(hours=4,
                                                         minutes=None,
                                                         days=None))
        with self.assertRaises(ApiServerError) as context:
            result = self.sf.create_schedule(sched)

        self.assertTrue("xVolumeIDDoesNotExist" in str(context.exception))
예제 #25
0
    def test_create_but_missing_schedule_info_volumes(self):
        sf = ElementFactory.create(self.cluster, self.user, self.pwd)

        sched = Schedule()
        sched.name = "mySchedule"
        sched.frequency = TimeIntervalFrequency(hours=4, minutes=30, days=2)
        sched.frequency.hours = 4
        sched.frequency.minutes = 30
        sched.frequency.days = 2
        sched.schedule_info = ScheduleInfo()
        sched.schedule_info.volume_ids = "1111"

        result = sf.create_schedule(sched)
예제 #26
0
파일: netapp.py 프로젝트: ernstp/ansible
def create_sf_connection(module, port=None):
    hostname = module.params['hostname']
    username = module.params['username']
    password = module.params['password']

    if HAS_SF_SDK and hostname and username and password:
        try:
            return_val = ElementFactory.create(hostname, username, password, port=port)
            return return_val
        except:
            raise Exception("Unable to create SF connection")
    else:
        module.fail_json(msg="the python SolidFire SDK module is required")
def connect_cluster():
    """
    Actually connect to the cluster
    """
    sfmvip, sfuser, sfpass = get_inputs()
    try:
        sfe = ElementFactory.create(sfmvip,sfuser,sfpass, print_ascii_art=False)
        return sfe
    except Exception as ex:
        if "Bad Credentials" in str(ex):
            print("Incorrect user or password entered, please re-enter:\n")
            sfuser = input("Enter user name: ")
            sfpass = getpass("Enter password for user {} on cluster {}: ".format(sfuser, sfmvip))
            sfe = ElementFactory.create(sfmvip,sfuser,sfpass, print_ascii_art=False)
            return sfe
        elif "host has failed to respond" in str(ex):
            sfmvip = input("Please re-enter MVIP: ")
            sfe = ElementFactory.create(sfmvip,sfuser,sfpass, print_ascii_art=False)
            return sfe
        else:
            print("Script will exit due to an unhandled exception: \n{}".format(str(ex)))
            exit()
    def test_create_but_schedule_info_volumes_empty(self):
        sf = ElementFactory.create(self.cluster, self.user, self.password)

        sched = Schedule(schedule_info=ScheduleInfo(),
                         name=self.scheduleName,
                         frequency=TimeIntervalFrequency(hours=4,
                                                         minutes=30,
                                                         days=2))

        with self.assertRaises(AttributeError) as context:
            self.sf.create_schedule(sched)

        self.assertTrue(
            'ScheduleInfo.VolumeIDs are missing.' in str(context.exception))
예제 #29
0
    def test_create_but_missing_schedule_info(self):
        sf = ElementFactory.create(self.cluster, self.user, self.pwd)

        sched = Schedule()
        sched.name = "mySchedule"
        sched.frequency = TimeIntervalFrequency(hours=4, minutes=30, days=2)
        sched.frequency.hours = 4
        sched.frequency.minutes = 30
        sched.frequency.days = 2

        with self.assertRaises(AttributeError) as context:
            sf.create_schedule(sched)

        self.assertTrue('Schedule_info is not present' in str(context.exception))
예제 #30
0
def prune(ctx):
    connections = cli_utils.get_connections(ctx)
    goodConnections = []
    for connection in connections:
        if not all(
                k in connection.keys() for k in
            ["mvip", "username", "password", "version", "port", "name"]):
            print("Removing connection, ")
            cli_utils.print_result(connection,
                                   ctx.logger,
                                   as_json=ctx.json,
                                   as_pickle=ctx.pickle,
                                   depth=ctx.depth,
                                   filter_tree=ctx.filter_tree)
            print(
                "Connection info did not contain the following fields: mvip, username, password, version, port, and url"
            )
            print()
            continue
        try:
            ElementFactory.create(connection["mvip"],
                                  cli_utils.decrypt(connection["username"]),
                                  cli_utils.decrypt(connection["password"]),
                                  version=connection["version"],
                                  port=connection["port"])
            goodConnections += [connection]
        except Exception as e:
            print("Removing connection, ")
            cli_utils.print_result(connection,
                                   ctx.logger,
                                   as_json=ctx.json,
                                   as_pickle=ctx.pickle,
                                   depth=ctx.depth,
                                   filter_tree=ctx.filter_tree)
            print(e.__str__())
            print()
    cli_utils.write_connections(ctx, goodConnections)
예제 #31
0
    def test_create_but_schedule_info_volumes_empty(self):
        sf = ElementFactory.create(self.cluster, self.user, self.pwd)

        sched = Schedule()
        sched.name = "mySchedule"
        sched.frequency = TimeIntervalFrequency(hours=4, minutes=30, days=2)
        sched.frequency.hours = 4
        sched.frequency.minutes = 30
        sched.frequency.days = 2
        sched.schedule_info = ScheduleInfo()
        sched.schedule_info.volume_ids = []
        with self.assertRaises(AttributeError) as context:
            sf.create_schedule(sched)

        self.assertTrue('ScheduleInfo.VolumeIDs are missing.' in str(context.exception))
예제 #32
0
    def test_create_and_delete_schedule(self):
        sf = ElementFactory.create(self.cluster, self.user, self.pwd)

        vols = sf.list_volumes().volumes
        vol_ids = []
        for vol in vols:
            vol_ids.append(vol.volume_id)

        sched = Schedule()
        sched.name = "mySchedule"
        sched.frequency = TimeIntervalFrequency(hours=4, minutes=30, days=2)
        sched.frequency.hours = 4
        sched.frequency.minutes = 30
        sched.frequency.days = 2
        sched.schedule_info = ScheduleInfo()
        sched.schedule_info.volume_ids = vol_ids

        result = sf.create_schedule(sched)

        new_sched_id = result.schedule_id

        print(new_sched_id)

        new_sched = sf.get_schedule(new_sched_id).schedule

        assert_that(new_sched.name, equal_to("mySchedule"))
        assert_that(type(new_sched.frequency) is (TimeIntervalFrequency),
                    equal_to(True))
        if type(new_sched.frequency) is TimeIntervalFrequency:
            assert_that(new_sched.frequency.hours, equal_to(4))
            assert_that(new_sched.frequency.days, equal_to(2))
            assert_that(new_sched.frequency.minutes, equal_to(30))
        assert_that(new_sched.last_run_time_started, equal_to(None))
        assert_that(new_sched.schedule_info.volume_ids, equal_to(vol_ids))
        assert_that(new_sched.schedule_id, greater_than(0))
        assert_that(new_sched.recurring, equal_to(False))
        assert_that(new_sched.paused, equal_to(False))
        assert_that(new_sched.to_be_deleted, equal_to(False))
        assert_that(new_sched.starting_date, equal_to(None))
        assert_that(new_sched.has_error, equal_to(False))
        assert_that(new_sched.run_next_interval, equal_to(False))
        assert_that(new_sched.schedule_info.snapshot_name, equal_to(None))

        new_sched.to_be_deleted = True
        sf.modify_schedule(new_sched)

        deleted_sched = sf.get_schedule(new_sched_id).schedule
        assert_that(deleted_sched.to_be_deleted, equal_to(True))
예제 #33
0
    def test_create_and_delete_schedule(self):
        sf = ElementFactory.create("172.26.64.48", "admin", "admin")

        vlans = sf.list_virtual_networks().virtual_networks

        for vlan in vlans:
            print(vlan)
            the_vlan = vlan

        sf.modify_virtual_network(
            virtual_network_id=the_vlan.virtual_network_id, name="VLAN-3332")

        vlans = sf.list_virtual_networks().virtual_networks

        for vlan in vlans:
            print(vlan)
    def test_create_and_delete_schedule(self):
        sf = ElementFactory.create("192.168.139.165", "admin", "admin")

        vols = sf.list_volumes().volumes
        vol_ids = []
        for vol in vols:
            vol_ids.append(vol.volume_id)

        sched = Schedule()
        sched.name = "mySchedule"
        sched.frequency = TimeIntervalFrequency(hours=4, minutes=30, days=2)
        sched.frequency.hours = 4
        sched.frequency.minutes = 30
        sched.frequency.days = 2
        sched.schedule_info = ScheduleInfo()
        sched.schedule_info.volume_ids = vol_ids

        result = sf.create_schedule(sched)

        new_sched_id = result.schedule_id

        print(new_sched_id)

        new_sched = sf.get_schedule(new_sched_id).schedule

        assert_that(new_sched.name, equal_to("mySchedule"))
        assert_that(type(new_sched.frequency) is (TimeIntervalFrequency),
                    equal_to(True))
        if type(new_sched.frequency) is TimeIntervalFrequency:
            assert_that(new_sched.frequency.hours, equal_to(4))
            assert_that(new_sched.frequency.days, equal_to(2))
            assert_that(new_sched.frequency.minutes, equal_to(30))
        assert_that(new_sched.schedule_info.volume_ids, equal_to(vol_ids))
        assert_that(new_sched.schedule_id, greater_than(0))
        assert_that(new_sched.recurring, equal_to(True))
        assert_that(new_sched.paused, equal_to(False))
        assert_that(new_sched.to_be_deleted, equal_to(False))
        assert_that(new_sched.starting_date, equal_to(None))
        assert_that(new_sched.has_error, equal_to(False))
        assert_that(new_sched.run_next_interval, equal_to(False))
        assert_that(new_sched.schedule_info.snapshot_name, equal_to(None))

        new_sched.to_be_deleted = True
        sf.modify_schedule(new_sched)

        deleted_sched = sf.get_schedule(new_sched_id).schedule
        assert_that(deleted_sched.to_be_deleted, equal_to(True))
예제 #35
0
    def test_create_and_delete_schedule(self):
        sf = ElementFactory.create("172.26.64.48", "admin", "admin")

        vlans = sf.list_virtual_networks().virtual_networks

        for vlan in vlans:
            print(vlan)
            the_vlan = vlan

        sf.modify_virtual_network(
            virtual_network_id=the_vlan.virtual_network_id, name="VLAN-3332")


        vlans = sf.list_virtual_networks().virtual_networks

        for vlan in vlans:
            print(vlan)
예제 #36
0
def create_sf_connection(module, port=None, raise_on_connection_error=False):
    hostname = module.params['hostname']
    username = module.params['username']
    password = module.params['password']

    if HAS_SF_SDK and hostname and username and password:
        try:
            return_val = ElementFactory.create(hostname, username, password, port=port)
            return return_val
        except solidfire.common.ApiConnectionError as exc:
            if raise_on_connection_error:
                raise exc
            module.fail_json(msg=repr(exc))
        except Exception as exc:
            raise Exception("Unable to create SF connection: %s" % repr(exc))
    else:
        module.fail_json(msg="the python SolidFire SDK module is required")
예제 #37
0
    def test_create_and_delete_schedule(self):
        sf = ElementFactory.create(self.cluster, self.user, self.password)

        vlans = sf.list_virtual_networks().virtual_networks

        for vlan in vlans:
            print(vlan)
            the_vlan = vlan

        sf.modify_virtual_network(
            virtual_network_id=the_vlan.virtual_network_id, name="VLAN-3332")


        vlans = sf.list_virtual_networks().virtual_networks

        for vlan in vlans:
            print(vlan)
    def test_change_frequency_dom_to_dow(self):
        sf = ElementFactory.create(self.cluster, self.user, self.password)

        sched = Schedule(
            schedule_info=ScheduleInfo(volume_ids=self.get_existing_vol_ids()),
            name=self.scheduleName,
            frequency=DaysOfMonthFrequency(hours=4, minutes=30, monthdays=[2]))

        result = self.sf.create_schedule(sched)

        new_sched_id = result.schedule_id

        new_sched = self.sf.get_schedule(new_sched_id).schedule

        new_sched.frequency = DaysOfWeekFrequency(
            hours=5, weekdays=[Weekday.from_id(1),
                               Weekday.from_id(4)])

        modified_sched = self.sf.modify_schedule(new_sched).schedule
    def setUpClass(cls):
        # Set up API client
        testclient = super(TestManagedClusteredFilesystems,
                           cls).getClsTestClient()

        cls.apiClient = testclient.getApiClient()
        cls.configData = testclient.getParsedTestDataConfig()
        cls.dbConnection = testclient.getDbConnection()

        cls.testdata = TestData().testdata

        sf_util.set_supports_resign(True, cls.dbConnection)

        cls._connect_to_hypervisor()

        # Set up SolidFire connection
        solidfire = cls.testdata[TestData.solidFire]

        cls.sfe = ElementFactory.create(solidfire[TestData.mvip],
                                        solidfire[TestData.username],
                                        solidfire[TestData.password])

        # Get Resources from Cloud Infrastructure
        cls.zone = get_zone(cls.apiClient,
                            zone_id=cls.testdata[TestData.zoneId])
        cls.template = get_template(cls.apiClient,
                                    cls.zone.id,
                                    hypervisor=TestData.hypervisor_type)
        cls.domain = get_domain(cls.apiClient, cls.testdata[TestData.domainId])

        # Create test account
        cls.account = Account.create(cls.apiClient,
                                     cls.testdata["account"],
                                     admin=1)

        # Set up connection to make customized API calls
        cls.user = User.create(cls.apiClient,
                               cls.testdata["user"],
                               account=cls.account.name,
                               domainid=cls.domain.id)

        url = cls.testdata[TestData.url]

        api_url = "http://" + url + ":8080/client/api"
        userkeys = User.registerUserKeys(cls.apiClient, cls.user.id)

        cls.cs_api = SignedAPICall.CloudStack(api_url, userkeys.apikey,
                                              userkeys.secretkey)

        primarystorage = cls.testdata[TestData.primaryStorage]

        cls.primary_storage = StoragePool.create(
            cls.apiClient,
            primarystorage,
            scope=primarystorage[TestData.scope],
            zoneid=cls.zone.id,
            provider=primarystorage[TestData.provider],
            tags=primarystorage[TestData.tags],
            capacityiops=primarystorage[TestData.capacityIops],
            capacitybytes=primarystorage[TestData.capacityBytes],
            hypervisor=primarystorage[TestData.hypervisor])

        cls.compute_offering = ServiceOffering.create(
            cls.apiClient, cls.testdata[TestData.computeOffering])

        # Resources that are to be destroyed
        cls._cleanup = [cls.compute_offering, cls.user, cls.account]
        i = 0
        wrapped = textwrap.wrap(value, 18)
        for loop in wrapped:
            print("| ".ljust(int_width + 2) + " | " + loop +
                  "|".rjust(int_width - (len(loop))))
            i = i + 1
    else:
        print("| " + description.ljust(int_width) + " | " + value +
              "|".rjust(int_width - (len(value))))


#Check to see if we were provided a name, and check that we can resolve it.

sfe = ElementFactory.create(mvip_ip,
                            user_name,
                            user_pass,
                            print_ascii_art=False,
                            timeout=300)
cluster_info = sfe.get_cluster_info()
cluster_name = cluster_info.cluster_info.name
mvip_ip = cluster_info.cluster_info.mvip
mvip_node = cluster_info.cluster_info.mvip_node_id
mvip_bond = cluster_info.cluster_info.mvip_interface
svip_ip = cluster_info.cluster_info.svip
svip_bond = cluster_info.cluster_info.svip_interface
svip_node = cluster_info.cluster_info.svip_node_id
encrypt_state = cluster_info.cluster_info.encryption_at_rest_state
ensemble_member = cluster_info.cluster_info.ensemble
iqn_id = cluster_info.cluster_info.unique_id
if cluster_info.cluster_info.rep_count == 2:
    helix_protection = 'double'
    def setUpClass(cls):
        # Set up API client
        testclient = super(TestVMMigrationWithStorage, cls).getClsTestClient()

        cls.apiClient = testclient.getApiClient()
        cls.configData = testclient.getParsedTestDataConfig()
        cls.dbConnection = testclient.getDbConnection()

        cls.testdata = TestData().testdata

        xenserver = cls.testdata[TestData.xenServer]

        # Set up xenAPI connection
        host_ip = "https://" + \
                  list_hosts(cls.apiClient, clusterid=cls.testdata[TestData.clusterId1], name="XenServer-6.5-1")[0].ipaddress

        # Set up XenAPI connection
        cls.xen_session_1 = XenAPI.Session(host_ip)

        cls.xen_session_1.xenapi.login_with_password(xenserver[TestData.username], xenserver[TestData.password])

        # Set up xenAPI connection
        host_ip = "https://" + \
                  list_hosts(cls.apiClient, clusterid=cls.testdata[TestData.clusterId2], name="XenServer-6.5-3")[0].ipaddress

        # Set up XenAPI connection
        cls.xen_session_2 = XenAPI.Session(host_ip)

        cls.xen_session_2.xenapi.login_with_password(xenserver[TestData.username], xenserver[TestData.password])

        # Set up SolidFire connection
        solidfire = cls.testdata[TestData.solidFire]

        cls.sfe = ElementFactory.create(solidfire[TestData.mvip], solidfire[TestData.username], solidfire[TestData.password])

        # Get Resources from Cloud Infrastructure
        cls.zone = get_zone(cls.apiClient, zone_id=cls.testdata[TestData.zoneId])
        cls.cluster_1 = list_clusters(cls.apiClient, id=cls.testdata[TestData.clusterId1])[0]
        cls.cluster_2 = list_clusters(cls.apiClient, id=cls.testdata[TestData.clusterId2])[0]
        cls.template = get_template(cls.apiClient, cls.zone.id, cls.configData["ostype"])
        cls.domain = get_domain(cls.apiClient, cls.testdata[TestData.domainId])

        # Create test account
        cls.account = Account.create(
            cls.apiClient,
            cls.testdata["account"],
            admin=1
        )

        # Set up connection to make customized API calls
        cls.user = User.create(
            cls.apiClient,
            cls.testdata["user"],
            account=cls.account.name,
            domainid=cls.domain.id
        )

        url = cls.testdata[TestData.url]

        api_url = "http://" + url + ":8080/client/api"
        userkeys = User.registerUserKeys(cls.apiClient, cls.user.id)

        cls.cs_api = SignedAPICall.CloudStack(api_url, userkeys.apikey, userkeys.secretkey)

        primarystorage = cls.testdata[TestData.primaryStorage]

        cls.primary_storage = StoragePool.create(
            cls.apiClient,
            primarystorage
        )

        cls.compute_offering_1 = ServiceOffering.create(
            cls.apiClient,
            cls.testdata[TestData.computeOffering1]
        )

        cls.compute_offering_2 = ServiceOffering.create(
            cls.apiClient,
            cls.testdata[TestData.computeOffering2]
        )

        cls.compute_offering_3 = ServiceOffering.create(
            cls.apiClient,
            cls.testdata[TestData.computeOffering3]
        )

        cls.disk_offering_1 = DiskOffering.create(
            cls.apiClient,
            cls.testdata[TestData.diskOffering1]
        )

        cls.disk_offering_2 = DiskOffering.create(
            cls.apiClient,
            cls.testdata[TestData.diskOffering2]
        )

        # Resources that are to be destroyed
        cls._cleanup = [
            cls.compute_offering_1,
            cls.compute_offering_2,
            cls.compute_offering_3,
            cls.disk_offering_1,
            cls.disk_offering_2,
            cls.user,
            cls.account
        ]
# Logger module configuration
if args.logfile:
    LOG = logging.getLogger('solidfire_graphite_collector.py')
    logging.basicConfig(filename=args.logfile, level=logging.DEBUG, format='%(asctime)s %(message)s')
    LOG.warning("Starting Collector script as a daemon.  No console output possible.")

# Initialize graphyte sender
if args.graphite == "debug":
    LOG.warning("Starting collector in debug mode. All the metrics will be shipped to logfile")
    to_graphite = False
else:
    graphyte.init(args.graphite, port=args.port, prefix=args.metricroot)

LOG.info("Metrics Collection for array: {0}".format(args.solidfire))
try:
    sfe = ElementFactory.create(args.solidfire, args.username, args.password)
    sfe.timeout(15)
    cluster_name = sfe.get_cluster_info().to_json()['clusterInfo']['name']
    send_cluster_stats(sfe, cluster_name)
    send_cluster_faults(sfe, cluster_name)
    send_cluster_capacity(sfe, cluster_name)
    send_node_stats(sfe, cluster_name + '.node')
    send_volume_stats(sfe, cluster_name)
    send_drive_stats(sfe, cluster_name)
except solidfire.common.ApiServerError as e:
    LOG.warning("ApiServerError: {0}".format(str(e)))
except Exception as e:
    LOG.warning("General Exception: {0}".format(str(e)))

sfe = None
예제 #43
0
    def setUpClass(cls):
        # Set up API client
        testclient = super(TestCapacityManagement, cls).getClsTestClient()

        cls.apiClient = testclient.getApiClient()
        cls.configData = testclient.getParsedTestDataConfig()
        cls.dbConnection = testclient.getDbConnection()

        cls.testdata = TestData().testdata

        sf_util.set_supports_resign(True, cls.dbConnection)

        cls._connect_to_hypervisor()

        # Set up SolidFire connection
        solidfire = cls.testdata[TestData.solidFire]

        cls.sfe = ElementFactory.create(solidfire[TestData.mvip], solidfire[TestData.username], solidfire[TestData.password])

        # Get Resources from Cloud Infrastructure
        cls.zone = get_zone(cls.apiClient, zone_id=cls.testdata[TestData.zoneId])
        cls.template = get_template(cls.apiClient, cls.zone.id, hypervisor=TestData.hypervisor_type)
        cls.domain = get_domain(cls.apiClient, cls.testdata[TestData.domainId])

        # Create test account
        cls.account = Account.create(
            cls.apiClient,
            cls.testdata["account"],
            admin=1
        )

        # Set up connection to make customized API calls
        cls.user = User.create(
            cls.apiClient,
            cls.testdata["user"],
            account=cls.account.name,
            domainid=cls.domain.id
        )

        url = cls.testdata[TestData.url]

        api_url = "http://" + url + ":8080/client/api"
        userkeys = User.registerUserKeys(cls.apiClient, cls.user.id)

        cls.cs_api = SignedAPICall.CloudStack(api_url, userkeys.apikey, userkeys.secretkey)

        primarystorage = cls.testdata[TestData.primaryStorage]

        cls.primary_storage = StoragePool.create(
            cls.apiClient,
            primarystorage,
            scope=primarystorage[TestData.scope],
            zoneid=cls.zone.id,
            provider=primarystorage[TestData.provider],
            tags=primarystorage[TestData.tags],
            capacityiops=primarystorage[TestData.capacityIops],
            capacitybytes=primarystorage[TestData.capacityBytes],
            hypervisor=primarystorage[TestData.hypervisor]
        )

        primarystorage2 = cls.testdata[TestData.primaryStorage2]

        cls.primary_storage_2 = StoragePool.create(
            cls.apiClient,
            primarystorage2,
            scope=primarystorage2[TestData.scope],
            zoneid=cls.zone.id,
            provider=primarystorage2[TestData.provider],
            tags=primarystorage2[TestData.tags],
            capacityiops=primarystorage2[TestData.capacityIops],
            capacitybytes=primarystorage2[TestData.capacityBytes],
            hypervisor=primarystorage2[TestData.hypervisor]
        )

        cls.compute_offering = ServiceOffering.create(
            cls.apiClient,
            cls.testdata[TestData.computeOffering]
        )

        cls.compute_offering_2 = ServiceOffering.create(
            cls.apiClient,
            cls.testdata[TestData.computeOffering2]
        )

        # Resources that are to be destroyed
        cls._cleanup = [
            cls.compute_offering,
            cls.compute_offering_2,
            cls.user,
            cls.account
        ]
    def setUpClass(cls):
        # Set up API client
        testclient = super(TestManagedSystemVMs, cls).getClsTestClient()

        cls.apiClient = testclient.getApiClient()
        cls.configData = testclient.getParsedTestDataConfig()
        cls.dbConnection = testclient.getDbConnection()

        cls.testdata = TestData().testdata

        cls._connect_to_hypervisor()

        # Set up SolidFire connection
        solidfire = cls.testdata[TestData.solidFire]

        cls.sfe = ElementFactory.create(solidfire[TestData.mvip], solidfire[TestData.username], solidfire[TestData.password])

        # Get Resources from Cloud Infrastructure
        cls.zone = Zone(get_zone(cls.apiClient, zone_id=cls.testdata[TestData.zoneId]).__dict__)
        cls.cluster = list_clusters(cls.apiClient)[0]
        cls.template = get_template(cls.apiClient, cls.zone.id, cls.configData["ostype"])
        cls.domain = get_domain(cls.apiClient, cls.testdata[TestData.domainId])

        # Create test account
        cls.account = Account.create(
            cls.apiClient,
            cls.testdata["account"],
            admin=1
        )

        # Set up connection to make customized API calls
        cls.user = User.create(
            cls.apiClient,
            cls.testdata["user"],
            account=cls.account.name,
            domainid=cls.domain.id
        )

        url = cls.testdata[TestData.url]

        api_url = "http://" + url + ":8080/client/api"
        userkeys = User.registerUserKeys(cls.apiClient, cls.user.id)

        cls.cs_api = SignedAPICall.CloudStack(api_url, userkeys.apikey, userkeys.secretkey)

        cls.compute_offering = ServiceOffering.create(
            cls.apiClient,
            cls.testdata[TestData.computeOffering]
        )

        systemoffering = cls.testdata[TestData.systemOffering]

        systemoffering[TestData.name] = "Managed SSVM"
        systemoffering['systemvmtype'] = "secondarystoragevm"

        cls.secondary_storage_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        systemoffering[TestData.name] = "Managed CPVM"
        systemoffering['systemvmtype'] = "consoleproxy"

        cls.console_proxy_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        systemoffering[TestData.name] = "Managed VR"
        systemoffering['systemvmtype'] = "domainrouter"

        cls.virtual_router_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        # Resources that are to be destroyed
        cls._cleanup = [
            cls.secondary_storage_offering,
            cls.console_proxy_offering,
            cls.virtual_router_offering,
            cls.compute_offering,
            cls.user,
            cls.account
        ]
예제 #45
0
    def setUpClass(cls):
        # Set up API client
        testclient = super(TestVMSnapshots, cls).getClsTestClient()

        cls.apiClient = testclient.getApiClient()
        cls.configData = testclient.getParsedTestDataConfig()

        cls.testdata = TestData().testdata

        # Set up XenAPI connection
        host_ip = "https://" + \
                  list_hosts(cls.apiClient, clusterid=cls.testdata[TestData.clusterId], name="XenServer-6.5-1")[0].ipaddress

        cls.xen_session = XenAPI.Session(host_ip)

        xenserver = cls.testdata[TestData.xenServer]

        cls.xen_session.xenapi.login_with_password(xenserver[TestData.username], xenserver[TestData.password])

        # Set up SolidFire connection
        solidfire = cls.testdata[TestData.solidFire]

        cls.sfe = ElementFactory.create(solidfire[TestData.mvip], solidfire[TestData.username], solidfire[TestData.password])

        # Get Resources from Cloud Infrastructure
        cls.zone = get_zone(cls.apiClient, zone_id=cls.testdata[TestData.zoneId])
        template = get_template(cls.apiClient, cls.zone.id, hypervisor=TestData.hypervisor_type)
        cls.domain = get_domain(cls.apiClient, cls.testdata[TestData.domainId])

        # Create test account
        cls.account = Account.create(
            cls.apiClient,
            cls.testdata[TestData.account],
            admin=1
        )

        # Set up connection to make customized API calls
        user = User.create(
            cls.apiClient,
            cls.testdata[TestData.user],
            account=cls.account.name,
            domainid=cls.domain.id
        )

        url = cls.testdata[TestData.url]

        api_url = "http://" + url + ":8080/client/api"
        userkeys = User.registerUserKeys(cls.apiClient, user.id)

        cls.cs_api = SignedAPICall.CloudStack(api_url, userkeys.apikey, userkeys.secretkey)

        primarystorage = cls.testdata[TestData.primaryStorage]

        cls.primary_storage = StoragePool.create(
            cls.apiClient,
            primarystorage,
            scope=primarystorage[TestData.scope],
            zoneid=cls.zone.id,
            provider=primarystorage[TestData.provider],
            tags=primarystorage[TestData.tags],
            capacityiops=primarystorage[TestData.capacityIops],
            capacitybytes=primarystorage[TestData.capacityBytes],
            hypervisor=primarystorage[TestData.hypervisor]
        )

        compute_offering = ServiceOffering.create(
            cls.apiClient,
            cls.testdata[TestData.computeOffering]
        )

        cls.disk_offering = DiskOffering.create(
            cls.apiClient,
            cls.testdata[TestData.diskOffering]
        )

        # Create VM and volume for tests
        cls.virtual_machine = VirtualMachine.create(
            cls.apiClient,
            cls.testdata[TestData.virtualMachine],
            accountid=cls.account.name,
            zoneid=cls.zone.id,
            serviceofferingid=compute_offering.id,
            templateid=template.id,
            domainid=cls.domain.id,
            startvm=True
        )

        cls._cleanup = [
            compute_offering,
            cls.disk_offering,
            user,
            cls.account
        ]
예제 #46
0
def get_solid_fire():
    auth = AuthStack()
    sf = ElementFactory.create(auth.solid_fire_ip, auth.solid_fire_user, auth.solid_fire_password, print_ascii_art=False)
    return sf