Beispiel #1
0
    def add(self, group, description=''):
        """Add one group.

        Args:
            group (str): The group name to add.
            description (str): The group description to add.

        Returns:
            int: The new group id from Skytap.

        Example:

        .. code-block:: python

            groups = skytap.Groups()
            new_group = groups.add('muppets', 'felt covered friends')
            print(groups[new_group].name)
        """
        Utils.info('Adding group: ' + group)
        api = ApiClient()
        data = {"name": group,
                "description": description}
        url = self.url + '.json'
        response = api.rest(url, data, 'POST')
        new_group = json.loads(response)
        self.refresh()
        if 'id' in new_group:
            return int(new_group['id'])
        Utils.warning('Trying to create group (' + group + '), but ' +
                      'got an unexpected return from Skytap. Response:\n' +
                      response)
        return 0
Beispiel #2
0
    def add(self, login_name, email=None):
        """Add one user.

        Args:
            login_name (str): The login id of the account, usually an email.
            email (str): The email of the account. If blank, will use
                login_name.

        Returns:
            int: The new user id from Skytap.

        Example:

        .. code-block:: python

            users = skytap.Users()
            new_user = users.add('*****@*****.**')
            print(users[new_user].login_name)
        """
        Utils.info('Adding user: '******'.json'
        response = api.rest(url, data, 'POST')
        new_user = json.loads(response)
        self.refresh()
        if 'id' in new_user:
            return int(new_user['id'])
        Utils.warning('Trying to create user (' + login_name + '), but ' +
                      'got an unexpected return from Skytap. Response:\n' +
                      response)
        return 0
Beispiel #3
0
    def add(self, login_name, email=None):
        """Add one user.

        Args:
            login_name (str): The login id of the account, usually an email.
            email (str): The email of the account. If blank, will use
                login_name.

        Returns:
            int: The new user id from Skytap.

        Example:

        .. code-block:: python

            users = skytap.Users()
            new_user = users.add('*****@*****.**')
            print(users[new_user].login_name)
        """
        Utils.info('Adding user: '******'.json'
        response = api.rest(url, data, 'POST')
        new_user = json.loads(response)
        self.refresh()
        if 'id' in new_user:
            return int(new_user['id'])
        Utils.warning('Trying to create user (' + login_name + '), but ' +
                      'got an unexpected return from Skytap. Response:\n' +
                      response)
        return 0
Beispiel #4
0
    def create(self, vmid):
        """Create an export job from a vm in a template."""
        if type(vmid) is not int:
            raise TypeError('vmid must be an int')

        Utils.info('creating export job for VM ' + str(vmid))
        api = ApiClient()
        data = {"vm_id": vmid}
        url = self.url + '.json'
        response = api.rest(url, data, "POST")
        exports = json.loads(response)
        self.refresh()
        if 'id' in exports:
            return int(exports['id'])
        Utils.warning('Trying to create new export job from VM ' + vmid +
                      ', but got an unexpected response from Skytap. ' +
                      'Response:\n' + response)
        return 0
Beispiel #5
0
    def create(self, vmid):
        """Create an export job from a vm in a template."""
        if type(vmid) is not int:
            raise TypeError('vmid must be an int')

        Utils.info('creating export job for VM ' + str(vmid))
        api = ApiClient()
        data = {"vm_id": vmid}
        url = self.url + '.json'
        response = api.rest(url, data, "POST")
        exports = json.loads(response)
        self.refresh()
        if 'id' in exports:
            return int(exports['id'])
        Utils.warning('Trying to create new export job from VM ' + vmid +
                      ', but got an unexpected response from Skytap. ' +
                      'Response:\n' + response)
        return 0
Beispiel #6
0
    # for most things you'd want to do.
    config_data = INITIAL_CONFIG

# Load config values and set up the class.

for key in Config:
    env_val = "SKYTAP_" + key.upper()
    if env_val in os.environ:
        Config.config_data[key] = os.environ[env_val]
        try:
            Config.config_data[key] = int(Config.config_data[key])
        except ValueError:
            pass

if os.environ.get('READTHEDOCS', None) != 'True':
    if Config.base_url != 'https://cloud.skytap.com':
        Utils.warning('Base URL is not Skytap\'s recommended value. ' +
                      'This very likely will break things.')

    if len(Config.token) == 0:
        Utils.error('No environment variable SKYTAP_TOKEN found. ' +
                    'Set this variable and try again.')
        raise ValueError

    if len(Config.user) == 0:
        Utils.error('No environment variable SKYTAP_USER found. ' +
                    'Set this variable and try again.')
        raise ValueError

Utils.log_level(Config.log_level)