Esempio n. 1
0
    def factory(object_type, customization_func=None, **kwargs):
        """Factory to create specific type object
        
        Args:
            object_type (string): Object type to create as defined in the business_models section of the configuration file
            customization_func (func, optional): Defaults to None. For 'payload' type only. Post customization payload processing function
        
        Returns:
            object: object of the 'object_type' type specified in args
        """

        config = VraConfig().config_file

        if object_type == 'payload':
            if all(k in kwargs for k in ("payload_version", "payload_type")):
                str_version = str(kwargs['payload_version'])
                payload_type = kwargs['payload_type']
                object_path = f'vra_sdk.models.vra_payload_{str_version}.{payload_type}'
            else:
                raise VraSdkFactoryException(
                    "Error creating payload object. Missing required parameters"
                )
        elif object_type in config['business_models']:
            object_path = config.get('business_models').get(object_type).get(
                'path')
            if not object_path:
                raise VraSdkFactoryException(
                    f"Error retrieving module_class for {object_type} object type."
                )
        else:
            raise VraSdkConfigException(
                'Error building vraObject, unknown type')

        _, object_class = get_module_class(object_path)
        id_cards = inspect.signature(object_class).parameters
        cleaned_kwargs = clean_kwargs_key(**kwargs)

        if object_type != 'payload':
            for kwarg in cleaned_kwargs:
                if kwarg not in id_cards:
                    raise VraSdkConfigException(
                        f"Error creating vraObject {object_type}, {kwarg} not authorized by the id card of {object_path}"
                    )

        if object_type == 'payload':
            return object_class(customization_func, **cleaned_kwargs)

        return object_class(**cleaned_kwargs)
    def test_validate_payload_v6(self, mock_session):
        mock_session.return_value.get.side_effect = get_side_effect
        mock_session.return_value.post.side_effect = post_side_effect

        VraConfig(get_test_config_file_path())
        auth = VraAuthenticate('PRD').auth_login_password(
            'fake_login', 'fake_password', 'foo.fuu.com')
        sdk = VraSdk(auth, 'fake_bg')

        data = {
            "payload_version": 6,
            "provider-fake_data1": "fake_value1",
            "fake_data2": 122
        }

        fake_item_request = sdk.request_catalog_item("fake_catalog_item",
                                                     **data)
        self.assertTrue(
            self.validator.catalog_item(fake_item_request.payload.customized))

        fake_action_request = sdk.request_resource_action(
            "fake_action_name", "fake_resource_id", **data)
        self.assertTrue(
            self.validator.resource_action(
                fake_action_request.payload.customized))
Esempio n. 3
0
    def __init__(self, authentication_object, business_group, **kwargs):
        """Init the VraSdk object
        
        Args:
            authentication_object (VraAuthenticate): authentication object
            business_group (string): business group to work on
        """

        urllib3.disable_warnings()
        self.authentication_object = authentication_object
        self.config = VraConfig()
        self.business_group_id = ''
        self.business_group = business_group
        self.catalog = self.get_catalog()
Esempio n. 4
0
    def __init__(self, environment, **kwargs):
        """Init VraAuthenticate
        
        Args:
            environment (string): requested vRa server environment

        Returns:
            VraAuthenticate: self
        """

        urllib3.disable_warnings()
        self.config = VraConfig()
        self.login = None
        self.requestedFor = None
        self.token = None
        self.domain = None
        self.environment = environment
Esempio n. 5
0
 def test_init(self, mock_oppen):
     result = VraConfig('fake.json')
     self.assertEqual(result.config_file, {'fake_config': ''})
Esempio n. 6
0
 def teardown_method(self, methodf):
     config = VraConfig()
     config._sealed = False
Esempio n. 7
0
from vra_sdk.vra_config import VraConfig
from vra_sdk.vra_authenticate import VraAuthenticate
from vra_sdk.vra_sdk import VraSdk
import os
from pprint import pprint as pprint

# credential loading from environment var
domain = "foo.fuu.com"
environment = os.environ['vra_environment']
login = os.environ['vra_login']
password = os.environ['vra_password']
######

# authentication part
VraConfig('config.json')
auth = VraAuthenticate(environment).auth_login_password(
    login, password, domain)
my_business_group = 'my_bg_name'
my_client = VraSdk(auth, my_business_group)
######

# get data on one vm from name
vm_name = 'my_vm_name'
vm_data = my_client.get_data('vm', 'name', vm_name)[0]
print(vm_data.id)
######

# get data on one vm from id
vm_id = 'my_vm_id'
vm_data = my_client.get_data('vm', 'id', vm_id)
print(vm_data.name)
Esempio n. 8
0
 def __init__(self):
     self.config = VraConfig()