Пример #1
0
    def create_s2_shared_target(self,
                                s2_server_id,
                                export_name,
                                target_type,
                                description=None,
                                volumes=None,
                                initiator_names=None,
                                **ignore):
        """ Create S2 shared target

        :param s2_server_id: the ID of s2 server.
        :param export_name: the name of shared target.
        :param target_type: valid values includes 'ISCSI', 'FCoE','NFS' and 'SMB'.
        :param description: the detailed description of the resource.
        :param volumes: the IDs of volumes will be attached as backstore.
        :param initiator_names: specify client IQN, available in vsan.
        """
        action = const.ACTION_CREATE_S2_SHARED_TARGET
        valid_keys = [
            's2_server_id', 'export_name', 'target_type',
            'description', 'volumes', 'initiator_names',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                list_params=['volumes', 'initiator_names'],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #2
0
    def create_s2_account(self,
                          account_type,
                          account_name=None,
                          smb_name=None,
                          smb_passwd=None,
                          nfs_ipaddr=None,
                          s2_groups=None,
                          opt_parameters=None,
                          description=None,
                          **ignore):
        """ Create S2 account

        :param account_type: valid values is NFS or SMB.
        :param account_name: the name of account.
        :param smb_name: the user name of smb.
        :param smb_passwd: the password of smb.
        :param nfs_ipaddr: ip address available in NFS.
        :param s2_groups: the JSON form of groups. e.g. '[{"group_id":"s2g-xxxx", "rw_flag": "rw"}]'
        :param opt_parameters: options parameters for NFS.
        :param description: the detailed description of the resource.
        """
        action = const.ACTION_CREATE_S2_ACCOUNT
        valid_keys = [
            'account_type', 'account_name', 'smb_name', 'smb_passwd',
            'nfs_ipaddr', 's2_groups', 'opt_parameters', 'description',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                list_params=["s2_groups"],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #3
0
    def reset_instances(self, instances,
                        login_mode=None,
                        login_passwd=None,
                        login_keypair=None,
                        need_newsid=False,
                        **ignore):
        """ Reset one or monre instances to its initial state.
        @param login_mode: login mode, only supported for linux instance, valid values are "keypair", "passwd".
        param login_passwd: if login_mode is "passwd", should be specified.
        @param login_keypair: if login_mode is "keypair", should be specified.
        @param instances : an array of instance ids you want to reset.
        @param need_newsid: Whether to generate new SID for the instance (True) or not
        (False). Only valid for Windows instance; Silently ignored
        for Linux instance.
        """
        action = const.ACTION_RESET_INSTANCES
        valid_keys = ['instances', 'login_mode',
                      'login_passwd', 'login_keypair', 'need_newsid']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=['instances'],
                                                  integer_params=['need_newsid'],
                                                  list_params=['instances']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #4
0
    def describe_vxnets(self, vxnets=None,
                        search_word=None,
                        verbose=0,
                        owner=None,
                        limit=None,
                        offset=None,
                        tags=None,
                        vxnet_type=None,
                        mode=None,
                        **ignore):
        """ Describe vxnets filtered by condition.
        @param vxnets: the IDs of vxnets you want to describe.
        @param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        @param tags : the array of IDs of tags.
        @param vxnet_type: the vxnet of type you want to describe.
        @param mode: the vxnet mode. 0: gre+ovs, 1: vxlan+bridge.
        """
        action = const.ACTION_DESCRIBE_VXNETS
        valid_keys = ['vxnets', 'search_word', 'verbose', 'limit', 'offset',
                      'tags', 'vxnet_type', 'owner', 'mode']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[],
                                                  integer_params=[
                                                      'limit', 'offset', 'verbose',
                                                      'vxnet_type', 'mode',
                                                  ],
                                                  list_params=['vxnets', 'tags']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #5
0
    def describe_security_groups(self, security_groups=None,
                                 security_group_name=None,
                                 search_word=None,
                                 owner=None,
                                 verbose=0,
                                 offset=None,
                                 limit=None,
                                 tags=None,
                                 **ignore):
        """ Describe security groups filtered by condition
        @param security_groups: IDs of the security groups you want to describe.
        @param security_group_name: the name of the security group.
        @param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        @param tags : the array of IDs of tags.
        """
        action = const.ACTION_DESCRIBE_SECURITY_GROUPS
        valid_keys = ['security_groups', 'security_group_name', 'search_word',
                      'verbose', 'offset', 'limit', 'tags', 'owner']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[],
                                                  integer_params=[
                                                      'offset', 'limit', 'verbose'],
                                                  list_params=[
                                                      'security_groups', 'tags']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #6
0
    def create_s2_server(self,
                         vxnet,
                         service_type,
                         s2_server_name=None,
                         s2_server_type=None,
                         private_ip=None,
                         description=None,
                         s2_class=None,
                         **ignore):
        """ Create S2 server

        :param vxnet: the ID of vxnet.
        :param service_type: valid values is vsan or vnas.
        :param s2_server_name: the name of s2 server.
        :param s2_server_type: valid values includes 0, 1, 2, 3.
        :param private_ip: you may specify the ip address of this server.
        :param description: the detailed description of the resource.
        :param s2_class: valid values includes 0, 1.
        """
        action = const.ACTION_CREATE_S2_SERVER
        valid_keys = [
            'vxnet', 'service_type', 's2_server_name', 's2_server_type',
            'private_ip', 'description', 's2_class',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                integer_params=["s2_server_type", "s2_class"],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #7
0
    def describe_clusters(self, clusters=None,
                          role=None,
                          status=None,
                          verbose=1,
                          search_word=None,
                          owner=None,
                          offset=None,
                          limit=None,
                          tags=None,
                          **ignore):
        """ Describe clusters filtered by condition.
        @param clusters: the array of cluster IDs.
        @param status: pending, active, stopped, deleted, suspended, ceased
        @param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
        @param search_word: search word column.
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        @param tags : the array of IDs of tags.
        """
        action = const.ACTION_DESCRIBE_CLUSTERS
        valid_keys = ['clusters', 'status', 'verbose', 'search_word',
                      'owner', 'offset', 'limit', 'tags', 'role']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[],
                                                  integer_params=[
                                                      'offset', 'limit'],
                                                  list_params=[
                                                      'clusters', 'status', 'tags']
                                                  ):
            return None

        return self.conn.send_request(action, body)
    def describe_instance_groups(self, instance_groups=[],
                                 relation=None,
                                 tags=None,
                                 owner=None,
                                 verbose=0,
                                 offset=0,
                                 limit=20,
                                 **ignore):
        """ Describe the instance groups filtered by conditions.
        @param instance_groups: If this param was given, only return the group(s) info in this given list.
        @param relation: Filter by the relation type.
        @param tags: Filter by the tag id.
        @param owner: Filter by the owner id.
        @param verbose: Whether return the verbose information.
        @param offset: The offset of the item cursor and its default value is 0.
        @param limit: The number of items that will be displayed. Default is 20, maximum is 100.
        """
        action = const.ACTION_DESCRIBE_INSTANCE_GROUPS
        valid_keys = ['instance_groups', 'relation', 'tags', 'owner',
                      'verbose', 'offset', 'limit']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  list_params=['instance_groups', 'tags'],
                                                  integer_params=['limit', 'verbose', 'offset']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #9
0
    def resize_instances(self, instances,
                         instance_type=None,
                         cpu=None,
                         memory=None,
                         os_disk_size=None,
                         **ignore):
        """ Resize one or more instances
        @param instances: the IDs of the instances you want to resize.
        @param instance_type: defined by qingcloud.
        See: https://docs.qingcloud.com/api/common/includes/instance_type.html
        @param cpu: cpu core number.
        @param memory: memory size in MB.
        @param os_disk_size: operation system disk size in GB.
        """
        action = const.ACTION_RESIZE_INSTANCES
        valid_keys = ['instances', 'instance_type', 'cpu', 'memory', 'os_disk_size']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=['instances'],
                                                  integer_params=['cpu', 'memory', 'os_disk_size'],
                                                  list_params=['instances']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #10
0
    def create_loadbalancer(self,
                            eips=None,
                            loadbalancer_name=None,
                            security_group=None,
                            node_count=None,
                            loadbalancer_type=const.LB_TYPE_MAXCONN_5k,
                            vxnet=None,
                            private_ip=None,
                            target_user=None,
                            **ignore):
        """ Create new load balancer.
        @param eips: the IDs of the eips that will be associated to load balancer.
        @param loadbalancer_name: the name of the loadbalancer.
        @param security_group: the id of the security_group you want to apply to loadbalancer,
        use `default security` group as default.
        @param target_user: ID of user who will own this resource, should be one of your sub-accounts
        """
        action = const.ACTION_CREATE_LOADBALANCER
        valid_keys = ['eips', 'loadbalancer_name', 'loadbalancer_type',
                      'security_group', 'node_count', 'vxnet', 'private_ip',
                      'target_user',
                      ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[],
                                                  integer_params=['node_count'],
                                                  list_params=['eips']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #11
0
    def modify_alarm_policy_rule_attributes(self, alarm_policy_rule,
                                            condition_type,
                                            thresholds=None,
                                            alarm_policy_rule_name=None,
                                            data_processor=None,
                                            consecutive_periods=None,
                                            **ignore):
        """ Modify alarm policy rule attributes.
        @param alarm_policy_rule: the ID of the alarm policy rule whose content you
                               want to update.
        @param condition_type: gt for greater than, lt for less than.
        @param thresholds: the thresholds of alarm.
        @param alarm_policy_rule_name: the name of the alarm policy rule.
        @param data_processor: raw for use the monitoring data raw value, percent only for IP bandwidth monitoring.
        @param consecutive_periods: during several consecutive inspection periods, the monitoring data reaches the alarm threshold,
                                    then will trigger the alarm behavior.
        """
        action = const.ACTION_MODIFY_ALARM_POLICY_RULE_ATTRIBUTES
        valid_keys = ['alarm_policy_rule', 'condition_type', 'thresholds',
                      'alarm_policy_rule_name', 'data_processor', 'consecutive_periods']
        body = filter_out_none(locals(), valid_keys)
        if not self.req_checker.check_params(body,
                                             required_params=['alarm_policy_rule', 'condition_type']
                                             ):
            return None

        return self.send_request(action, body)
Пример #12
0
    def describe_loadbalancer_policies(self, loadbalancer_policies=None,
                                       verbose=0,
                                       offset=None,
                                       limit=None,
                                       **ignore):
        """  Describe load balancer policies.
        @param loadbalancer_policies: filter by load balancer policy ID.
        @param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        """

        action = const.ACTION_DESCRIBE_LOADBALANCER_POLICIES
        valid_keys = ['loadbalancer_policies',
                      'verbose', 'offset', 'limit']
        body = filter_out_none(locals(), valid_keys)

        if not self.conn.req_checker.check_params(body,
                                                  required_params=[],
                                                  integer_params=['offset', 'limit'],
                                                  list_params=['loadbalancer_policies']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #13
0
    def modify_loadbalancer_backend_attributes(self, loadbalancer_backend,
                                               loadbalancer_backend_name=None,
                                               port=None,
                                               weight=None,
                                               disabled=None,
                                               **ignore):
        """ Modify load balancer backend attributes.
        @param loadbalancer_backend: the ID of backend.
        @param loadbalancer_backend_name: the name of the backend.
        @param port: backend server listen port.
        @param weight: backend server weight, valid range is from 1 to 100.
        """
        action = const.ACTION_MODIFY_LOADBALANCER_BACKEND_ATTRIBUTES
        valid_keys = ['loadbalancer_backend', 'loadbalancer_backend_name',
                      'port', 'weight', 'disabled']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[
                                                      'loadbalancer_backend'],
                                                  integer_params=[
                                                      'port', 'weight', 'disabled'],
                                                  list_params=[]
                                                  ):
            return None

        if 'port' in body:
            self.conn.req_checker.check_lb_backend_port(body['port'])
        if 'weight' in body:
            self.conn.req_checker.check_lb_backend_weight(body['weight'])

        return self.conn.send_request(action, body)
Пример #14
0
    def attach_tags(self, resource_tag_pairs, **ignore):
        """ Attach one or more tags to resources.
        @param resource_tag_pairs: the pair of resource and tag.
        it's a list-dict, such as:
        [{
        'tag_id': 'tag-hp55o9i5',
        'resource_type': 'instance',
        'resource_id': 'i-5yn6js06'
        }]
        """
        action = const.ACTION_ATTACH_TAGS
        valid_keys = ['resource_tag_pairs']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[
                                                      'resource_tag_pairs'],
                                                  list_params=['resource_tag_pairs']):
            return None
        for pair in resource_tag_pairs:
            if not isinstance(pair, dict):
                return None
            for key in ['tag_id', 'resource_id', 'resource_type']:
                if key not in pair:
                    return None

        return self.conn.send_request(action, body)
Пример #15
0
    def modify_security_group_attributes(self, security_group,
                                         security_group_name=None,
                                         description=None,
                                         **ignore):
        """ Modify security group attributes.
        @param security_group: the ID of the security group whose content you
        want to update.
        @param security_group_name: the new group name you want to update.
        @param description: The detailed description of the resource.
        """
        action = const.ACTION_MODIFY_SECURITY_GROUP_ATTRIBUTES
        valid_keys = ['security_group', 'security_group_name', 'description']
        body = filter_out_none(locals(), valid_keys)
        body['security_group'] = security_group
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[
                                                      'security_group'],
                                                  integer_params=[],
                                                  list_params=[]
                                                  ):
            return None

        if not self.conn.req_checker.check_sg_rules(body.get('rules', [])):
            return None

        return self.conn.send_request(action, body)
Пример #16
0
    def describe_security_group_ipsets(self,
                                       security_group_ipsets=None,
                                       ipset_type=None,
                                       security_group_ipset_name=None,
                                       offset=None,
                                       limit=None,
                                       **ignore):
        """ Describe security group ipsets filtered by condition.
        @param security_group_ipsets: the ID of the security group ipsets.
        @param ipset_type: 0 for ip; 1 for port
        @param security_group_ipset_name: filter by name
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_SECURITY_GROUP_IPSETS
        valid_keys = ['security_group_ipsets', 'ipset_type',
                      'security_group_ipset_name',
                      'offset', 'limit']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[],
                                                  integer_params=[
                                                      'ipset_type', 'offset', 'limit'],
                                                  list_params=[
                                                      'security_group_rules']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #17
0
    def describe_s2_accounts(self,
                             s2_accounts=None,
                             account_types=None,
                             account_name=None,
                             search_word=None,
                             verbose=None,
                             offset=None,
                             limit=None,
                             **ignore):
        """ Describe S2 accounts

        :param s2_accounts: the IDs of accounts.
        :param account_types: valid values is NFS or SMB.
        :param account_name: the name of account.
        :param search_word: you may use this field to search from id, account_name nfs_ipaddr or smb_name.
        :param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
        :param offset: the starting offset of the returning results.
        :param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_S2_ACCOUNTS
        valid_keys = [
            's2_accounts', 'account_types', 'account_name', 'search_word',
            'verbose', 'offset', 'limit',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                integer_params=["limit", "offset", "verbose"],
                list_params=["s2_accounts", "account_types"],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #18
0
    def describe_security_group_rules(self, security_group=None,
                                      security_group_rules=None,
                                      direction=None,
                                      offset=None,
                                      limit=None,
                                      **ignore):
        """ Describe security group rules filtered by condition.
        @param security_group: the ID of the security group whose rules you want to describe.
        @param security_group_rules: the IDs of the security group rules you want to describe.
        @param direction: 0 for inbound; 1 for outbound
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_SECURITY_GROUP_RULES
        valid_keys = ['security_group', 'security_group_rules', 'direction',
                      'offset', 'limit']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[],
                                                  integer_params=[
                                                      'direction', 'offset', 'limit'],
                                                  list_params=[
                                                      'security_group_rules']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #19
0
    def describe_s2_groups(self,
                           s2_groups=None,
                           group_types=None,
                           group_name=None,
                           search_word=None,
                           verbose=None,
                           offset=None,
                           limit=None,
                           **ignore):
        """ Describe S2 groups

        :param s2_groups: the IDs of s2 groups.
        :param group_types: valid values is NFS_GROUP or SMB_GROUP.
        :param group_name: the name of group.
        :param search_word: you may use this field to search from id or name.
        :param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
        :param offset: the starting offset of the returning results.
        :param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_S2_GROUPS
        valid_keys = [
            's2_groups', 'group_types', 'account_name', 'search_word',
            'verbose', 'offset', 'limit',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                integer_params=['offset', 'limit', 'verbose'],
                list_params=['s2_groups', 'group_types'],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #20
0
    def describe_s2_servers(self,
                            s2_servers=None,
                            service_types=None,
                            status=None,
                            search_word=None,
                            tags=None,
                            verbose=None,
                            offset=None,
                            limit=None,
                            **ignore):
        """ Describe S2 servers

        :param s2_servers: the IDs of s2 server you want to describe.
        :param service_types: the type of service, valid value is 'vsan' or 'vnas'.
        :param status: valid values include pending, active, poweroffed, suspended, deleted, ceased.
        :param search_word: you may use this field to search from id, name and description.
        :param tags: the array of IDs of tags.
        :param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
        :param offset: the starting offset of the returning results.
        :param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_S2_SERVERS
        valid_keys = [
            's2_servers', 'service_types', 'status', 'search_word',
            'tags', 'verbose', 'offset', 'limit',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                integer_params=["offset", "limit", "verbose"],
                list_params=["s2_servers", "service_types", "tags", "status"],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #21
0
    def modify_s2_group(self,
                        s2_group,
                        group_name=None,
                        s2_accounts=None,
                        description=None,
                        **ignore):
        """ Modify S2 group

        :param s2_group: the ID of group.
        :param group_name: the name of group.
        :param s2_accounts: the IDs of accounts.
        :param description: the new value of description.
        """
        action = const.ACTION_MODIFY_S2_GROUP
        valid_keys = [
            's2_group', 'group_name', 's2_accounts', 'description',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                list_params=['s2_accounts'],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #22
0
    def modify_s2_shared_target_attributes(self,
                                           shared_target,
                                           operation,
                                           parameters=None,
                                           initiator_names=None,
                                           s2_group=None,
                                           export_name=None,
                                           **ignore):
        """ Modify S2 shared target attributes

        :param shared_target: the ID of shared target.
        :param operation: valid values includes add, modify, delete, set.
        :param parameters: please refer https://docs.qingcloud.com/api/s2/describle_s2_default_parameters.html
        :param initiator_names: client IQN.
        :param s2_group: the ID of permission group.
        :param export_name: the name of shared target, available in vnas.
        """
        action = const.ACTION_MODIFY_S2_SHARED_TARGET
        valid_keys = [
            'shared_target', 'operation', 'parameters',
            'initiator_names', 's2_group', 'export_name',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                list_params=["initiator_names", "parameters"],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #23
0
    def describe_s2_default_parameters(self,
                                       service_type=None,
                                       target_type=None,
                                       offset=None,
                                       limit=None,
                                       **ignore):
        """ Describe S2 default parameters

        :param service_type: valid values is vsan or vnas.
        :param target_type: valid values is ISCSI, FCoE, NFS or SMB.
        :param offset: the starting offset of the returning results.
        :param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_S2_DEFAULT_PARAMETERS
        valid_keys = [
            'service_type', 'target_type', 'offset', 'limit',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                integer_params=['offset', 'limit'],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #24
0
    def modify_security_group_ipset_attributes(self,
                                               security_group_ipset,
                                               security_group_ipset_name=None,
                                               description=None,
                                               val=None,
                                               **ignore):
        """ Modify security group ipset attributes.
        @param security_group_ipset: the ID of the security group ipset whose attributes you
        want to update.
        @param security_group_ipset_name: name of the ipset.
        @param description: The detailed description of the resource.
        @param val1: for "ip", this field is like:  192.168.1.0/24
        for "port", this field is like: 10000-15000
        """
        action = const.ACTION_MODIFY_SECURITY_GROUP_IPSET_ATTRIBUTES
        valid_keys = ['security_group_ipset', 'security_group_ipset_name',
                      'description', 'val']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[
                                                      'security_group_ipset'],
                                                  integer_params=[],
                                                  list_params=[]
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #25
0
    def describe_s2_shared_targets(self,
                                   shared_targets=None,
                                   target_types=None,
                                   s2_server_id=None,
                                   export_name=None,
                                   search_word=None,
                                   verbose=None,
                                   offset=None,
                                   limit=None,
                                   **ignore):
        """ Describe S2 servers

        :param shared_targets: the IDs of shared targets.
        :param target_types: valid values includes 'ISCSI', 'FCoE','NFS' and 'SMB'.
        :param s2_server_id: the ID of s2 server.
        :param export_name: the name of shared target.
        :param search_word: you may use this field to search from export_name or description.
        :param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
        :param offset: the starting offset of the returning results.
        :param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_S2_SHARED_TARGETS
        valid_keys = [
            'shared_targets', 'target_types', 's2_server_id', 'export_name',
            'search_word', 'verbose', 'offset', 'limit',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                integer_params=["limit", "offset", "verbose"],
                list_params=["shared_targets", "target_types"],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #26
0
    def describe_alarms(self, alarms=None,
                        policy=None,
                        status=None,
                        resource=None,
                        offset=None,
                        limit=None,
                        **ignore):
        """ Describe alarms filtered by condition.
        @param alarms: an array including IDs of the alarms you want to list.
        @param policy: the ID of alarm policy.
        @param status: ok stand for normal, alarm stand for alarming, insufficient stand for monitoring data cannot be collected.
        @param resource: The ID of resource which associated with the alarm.
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_ALARMS
        valid_keys = ['alarms', 'policy', 'status', 'resource', 'offset', 'limit']
        body = filter_out_none(locals(), valid_keys)
        if not self.req_checker.check_params(body,
                                             integer_params=['offset', 'limit'],
                                             list_params=['alarms']
                                             ):
            return None

        return self.send_request(action, body)
Пример #27
0
    def describe_vxnet_instances(self, vxnet,
                                 instances=None,
                                 image=None,
                                 instance_type=None,
                                 status=None,
                                 limit=None,
                                 offset=None,
                                 **ignore):
        """ Describe instances in vxnet.
        @param vxnet: the ID of vxnet whose instances you want to describe.
        @param image: filter by image ID.
        @param instances: filter by instance ID.
        @param instance_type: filter by instance type
        See: https://docs.qingcloud.com/api/common/includes/instance_type.html
        @param status: filter by status
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_VXNET_INSTANCES
        valid_keys = ['vxnet', 'instances', 'image', 'instance_type', 'status',
                      'limit', 'offset']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=['vxnet'],
                                                  integer_params=[
                                                      'limit', 'offset'],
                                                  list_params=['instances']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #28
0
    def add_security_group_rules(self, security_group,
                                 rules,
                                 target_user=None,
                                 **ignore):
        """ Add rules to security group.
        @param security_group: the ID of the security group whose rules you
        want to add.
        @param rules: a list of rules you want to add,
        can be created by SecurityGroupRuleFactory.
        @param target_user: ID of user who will own this resource, should be one of your sub-accounts
        """
        action = const.ACTION_ADD_SECURITY_GROUP_RULES
        valid_keys = ['security_group', 'rules', 'target_user']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[
                                                      'security_group', 'rules'],
                                                  integer_params=[],
                                                  list_params=['rules']
                                                  ):
            return None

        if not self.conn.req_checker.check_sg_rules(body.get('rules', [])):
            return None

        return self.conn.send_request(action, body)
Пример #29
0
    def modify_s2_account(self,
                          s2_account,
                          opt_parameters=None,
                          account_name=None,
                          smb_passwd=None,
                          nfs_ipaddr=None,
                          description=None,
                          **ignore):
        """ Modify S2 account

        :param s2_account: the ID of account.
        :param opt_parameters: the options parameters.
        :param account_name: the new value of account name.
        :param smb_passwd: the new password.
        :param nfs_ipaddr: the new ip address.
        :param description: the new value of description.
        """
        action = const.ACTION_MODIFY_S2_ACCOUNT
        valid_keys = [
            's2_account', 'opt_parameters', 'account_name', 'smb_passwd',
            'nfs_ipaddr', 'description',
        ]
        body = filter_out_none(locals(), valid_keys)

        return self.conn.send_request(action, body)
Пример #30
0
 def describe_volumes(self, volumes=None,
                      volume_type=None,
                      instance_id=None,
                      status=None,
                      owner=None,
                      search_word=None,
                      verbose=0,
                      offset=None,
                      limit=None,
                      tags=None,
                      **ignore):
     """ Describe volumes filtered by conditions
     @param volumes : the array of IDs of volumes.
     @param volume_type : the type of volume, 0 is high performance, 1 is high capacity
     @param instance_id: ID of the instance that volume is currently attached to, if has.
     @param status: pending, available, in-use, deleted.
     @param search_word: the combined search column.
     @param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
     @param offset: the starting offset of the returning results.
     @param limit: specify the number of the returning results.
     @param tags : the array of IDs of tags.
     """
     valid_keys = ['volumes', 'instance_id', 'status', 'search_word',
                   'volume_type', 'verbose', 'offset', 'limit', 'tags', 'owner']
     body = filter_out_none(locals(), valid_keys)
     if not self.conn.req_checker.check_params(body,
                                               required_params=[],
                                               integer_params=[
                                                   'offset', 'limit', 'verbose'],
                                               list_params=[
                                                   'volumes', 'status', 'tags']
                                               ):
         return None
     return self.conn.send_request(const.ACTION_DESCRIBE_VOLUMES, body)
Пример #31
0
    def modify_alarm_policy_action_attributes(self,
                                              alarm_policy_action,
                                              trigger_action=None,
                                              trigger_status=None,
                                              **ignore):
        """ Modify alarm policy action attributes.
        @param alarm_policy_action: the ID of the alarm policy action whose content you
                                    want to update.
        @param trigger_action: the ID of the trigger action.
        @param trigger_status: when the monitor alarm state becomes 'ok' or 'alarm', the message will be sent to this trigger list.
        """
        action = const.ACTION_MODIFY_ALARM_POLICY_ACTION_ATTRIBUTES
        valid_keys = [
            'alarm_policy_action', 'trigger_action', 'trigger_status'
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.req_checker.check_params(
                body, required_params=['alarm_policy_action']):
            return None

        return self.send_request(action, body)
Пример #32
0
    def modify_image_attributes(self, image,
                                image_name=None,
                                description=None,
                                **ignore):
        """ Modify image attributes.
        @param image: the ID of image whose attributes you want to modify.
        @param image_name: Name of the image. It's a short name for the image
                           that more meaningful than image id.
        @param description: The detailed description of the image.
        """
        action = const.ACTION_MODIFY_IMAGE_ATTRIBUTES
        valid_keys = ['image', 'image_name', 'description']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=['image'],
                                                  integer_params=[],
                                                  list_params=[]
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #33
0
    def create_snapshots(self,
                         resources,
                         snapshot_name=None,
                         is_full=0,
                         **ignore):
        """ Create snapshots.
        @param resources: the IDs of resources you want to create snapshot for, the supported resource types are instance/volume.
        @param snapshot_name: the name of the snapshot.
        @param is_full: whether to create a full snapshot. 0: determined by the system. 1: should create full snapshot.
        """
        action = const.ACTION_CREATE_SNAPSHOTS
        valid_keys = ['resources', 'snapshot_name', 'is_full']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                required_params=["resources"],
                integer_params=["is_full"],
                list_params=["resources"]):
            return None

        return self.conn.send_request(action, body)
Пример #34
0
    def associate_s2_account_group(self,
                                   s2_group,
                                   s2_accounts,
                                   **ignore):
        """ Associate S2 account group

        :param s2_group: the ID of group.
        :param s2_accounts: the JSON form of accounts. e.g. '[{"account_id": "s2a-xxxx", "rw_flag": "rw"}]'
        """
        action = const.ACTION_ASSOCIATE_S2_ACCOUNT_GROUP
        valid_keys = [
            's2_group', 's2_accounts',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                list_params=['s2_accounts'],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #35
0
    def dissociate_s2_account_group(self,
                                    s2_groups,
                                    s2_accounts,
                                    **ignore):
        """ Dissociate S2 account group

        :param s2_groups: the IDs of groups.
        :param s2_accounts: the IDs of accounts.
        """
        action = const.ACTION_DISSOCIATE_S2_ACCOUNT_GROUP
        valid_keys = [
            's2_groups', 's2_accounts',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                list_params=['s2_groups', 's2_accounts'],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #36
0
    def detach_from_s2_shared_target(self,
                                     shared_target,
                                     volumes,
                                     **ignore):
        """ Detach from s2 shared target

        :param shared_target: the ID of shared target.
        :param volumes: the IDs of volumes.
        """
        action = const.ACTION_DETACH_FROM_S2_SHARED_TARGET
        valid_keys = [
            'shared_target', 'volumes',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                list_params=['volumes'],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #37
0
    def modify_nic_attributes(self,
                              nic,
                              nic_name=None,
                              private_ip=None,
                              **ignore):
        """ Modify one nic's attributes

        @param nic: the ID of nic you want to modify.
        @param nic_name: the new name of nic.
        @param private_ip: the new ip address for this nic.
        """
        action = const.ACTION_MODIFY_NIC_ATTRIBUTES
        valid_keys = ["nic", "nic_name", "private_ip"]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                required_params=["nic"],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #38
0
    def associate_alarm_policy(self,
                               alarm_policy,
                               resources,
                               related_resource=None,
                               **ignore):
        """ Associate an alarm_policy on one or more resources.
        @param alarm_policy: The id of alarm policy you want to associate with resources.
        @param resources: the id of resources you want to associate alarm policy.
        @param related_resource: when the network load balancer is bound,
                                 related_resource needs to specify a public network IP ID associated with this load balancer.
        """
        action = const.ACTION_ASSOCIATE_ALARM_POLICY
        valid_keys = ['alarm_policy', 'resources', 'related_resource']
        body = filter_out_none(locals(), valid_keys)
        if not self.req_checker.check_params(
                body,
                required_params=['alarm_policy', 'resources'],
                list_params=['resources']):
            return None

        return self.send_request(action, body)
Пример #39
0
    def modify_border_attributes(self,
                                 border,
                                 border_name=None,
                                 description=None,
                                 **params):
        """ Action: ModifyBorderAttributes
            @param border: border id.
            @param border_name: the short name of borders.
            @param description: the description of borders.
        """

        action = const.ACTION_MODIFY_BORDER_ATTRIBUTES
        valid_keys = ['border', 'border_name', 'description']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                required_params=['border'],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #40
0
    def create_s2_account(self,
                          account_type,
                          account_name=None,
                          smb_name=None,
                          smb_passwd=None,
                          nfs_ipaddr=None,
                          s2_groups=None,
                          opt_parameters=None,
                          description=None,
                          **ignore):
        """ Create S2 account

        :param account_type: valid values is NFS or SMB.
        :param account_name: the name of account.
        :param smb_name: the user name of smb.
        :param smb_passwd: the password of smb.
        :param nfs_ipaddr: ip address available in NFS.
        :param s2_groups: the JSON form of groups. e.g. '[{"group_id":"s2g-xxxx", "rw_flag": "rw"}]'
        :param opt_parameters: options parameters for NFS.
        :param description: the detailed description of the resource.
        """
        action = const.ACTION_CREATE_S2_ACCOUNT
        valid_keys = [
            'account_type',
            'account_name',
            'smb_name',
            'smb_passwd',
            'nfs_ipaddr',
            's2_groups',
            'opt_parameters',
            'description',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                list_params=["s2_groups"],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #41
0
    def delete_vpc_borders(self,
                           vpc_borders=None,
                           unlease=1,
                           project_id=None,
                           **params):
        """ Action: DeleteVpcBorders
            @param vpc_borders: IDs of vpc_borders you want to delete border.
            @param unlease: whether to unlease before terminate.
            @param project_id: the project ID of vpc borders.
        """

        action = const.ACTION_DELETE_VPC_BORDERS
        valid_keys = ['vpc_borders', 'unlease', 'project_id']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                required_params=['vpc_borders'],
                integer_params=['unlease'],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #42
0
    def describe_snapshots(self, snapshots=None,
                           resource_id=None,
                           snapshot_type=None,
                           root_id=None,
                           owner=None,
                           status=None,
                           verbose=0,
                           search_word=None,
                           offset=None,
                           limit=None,
                           tags=None,
                           **ignore):
        """ Describe snapshots filtered by condition.
        @param snapshots: an array including IDs of the snapshots you want to list.
        No ID specified means list all.
        @param resource_id: filter by resource ID.
        @param snapshot_type: filter by snapshot type. 0: incremantal snapshot, 1: full snapshot.
        @param root_id: filter by snapshot root ID.
        @param status: valid values include pending, available, suspended, deleted, ceased.
        @param verbose: the number to specify the verbose level,
        larger the number, the more detailed information will be returned.
        @param search_word: the search word.
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        @param tags : the array of IDs of tags.
        """
        action = const.ACTION_DESCRIBE_SNAPSHOTS
        valid_keys = ['snapshots', 'resource_id', 'snapshot_type', 'root_id', 'status',
                      'verbose', 'search_word', 'offset', 'limit', 'tags', 'owner']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[],
                                                  integer_params=[
                                                      "offset", "limit", "verbose", "snapshot_type"],
                                                  list_params=["snapshots", "tags"]
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #43
0
    def modify_alarm_policy_attributes(self,
                                       alarm_policy,
                                       alarm_policy_name=None,
                                       period=None,
                                       description=None,
                                       **ignore):
        """ Modify alarm policy attributes.
        @param alarm_policy : the ID of alarm_policy.
        @param alarm_policy_name : the name of alarm_policy.
        @param period: the check period of alarm_policy.
        @param description: the description of alarm_policy.
        """
        action = const.ACTION_MODIFY_ALARM_POLICY_ATTRIBUTES
        valid_keys = [
            'alarm_policy', 'alarm_policy_name', 'period', 'description'
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.req_checker.check_params(body,
                                             required_params=['alarm_policy']):
            return None

        return self.send_request(action, body)
Пример #44
0
    def create_loadbalancer(self,
                            eips=None,
                            loadbalancer_name=None,
                            security_group=None,
                            node_count=None,
                            loadbalancer_type=const.LB_TYPE_MAXCONN_5k,
                            vxnet=None,
                            private_ip=None,
                            target_user=None,
                            mode=0,
                            **ignore):
        """ Create new load balancer.
        @param eips: the IDs of the eips that will be associated to load balancer.
        @param loadbalancer_name: the name of the loadbalancer.
        @param security_group: the id of the security_group you want to apply to loadbalancer,
        use `default security` group as default.
        @param target_user: ID of user who will own this resource, should be one of your sub-accounts
        """
        action = const.ACTION_CREATE_LOADBALANCER
        valid_keys = [
            'eips',
            'loadbalancer_name',
            'loadbalancer_type',
            'mode',
            'security_group',
            'node_count',
            'vxnet',
            'private_ip',
            'target_user',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                required_params=[],
                integer_params=['node_count', 'mode'],
                list_params=['eips']):
            return None

        return self.conn.send_request(action, body)
Пример #45
0
    def modify_security_group_rule_attributes(self,
                                              security_group_rule,
                                              priority=None,
                                              security_group_rule_name=None,
                                              rule_action=None,
                                              direction=None,
                                              protocol=None,
                                              val1=None,
                                              val2=None,
                                              val3=None,
                                              **ignore):
        """ Modify security group rule attributes.
        @param security_group_rule: the ID of the security group rule whose attributes you
        want to update.
        @param priority: priority [0 - 100].
        @param security_group_rule_name: name of the rule.
        @param rule_action: "accept" or "drop".
        @param direction: 0 for inbound; 1 for outbound.
        @param protocol: supported protocols are "icmp", "tcp", "udp", "gre".
        @param val1: for "icmp" protocol, this field is "icmp type";
        for "tcp/udp", it's "start port", empty means all.
        @param val2: for "icmp" protocol, this field is "icmp code";
        for "tcp/udp", it's "end port", empty means all.
        @param val3: ip network, e.g "1.2.3.0/24"
        """
        action = const.ACTION_MODIFY_SECURITY_GROUP_RULE_ATTRIBUTES
        valid_keys = [
            'security_group_rule', 'priority', 'security_group_rule_name',
            'rule_action', 'direction', 'protocol', 'val1', 'val2', 'val3'
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                required_params=['security_group_rule'],
                integer_params=['priority'],
                list_params=[]):
            return None

        return self.conn.send_request(action, body)
Пример #46
0
    def describe_alarm_history(self,
                               alarm,
                               history_type=None,
                               offset=None,
                               limit=None,
                               **ignore):
        """ Describe alarm history filtered by condition.
        @param alarm: the ID of the resource alarm entity.
        @param history_type: the types including trigger_action, status_change, config_update.
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_ALARM_HISTORY
        valid_keys = ['alarm', 'history_type', 'offset', 'limit']
        body = filter_out_none(locals(), valid_keys)
        if not self.req_checker.check_params(
                body,
                required_params=['alarm'],
                integer_params=['offset', 'limit']):
            return None

        return self.send_request(action, body)
Пример #47
0
    def describe_alarm_policy_rules(self,
                                    alarm_policy=None,
                                    alarm_policy_rules=None,
                                    offset=None,
                                    limit=None,
                                    **ignore):
        """ Describe alarm policy rules filtered by conditions.
        @param alarm_policy : the ID of alarm_policy.
        @param alarm_policy_rules : the array of IDs of alarm policy rules.
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_ALARM_POLICY_RULES
        valid_keys = ['alarm_policy', 'alarm_policy_rules', 'offset', 'limit']
        body = filter_out_none(locals(), valid_keys)
        if not self.req_checker.check_params(
                body,
                integer_params=['offset', 'limit'],
                list_params=['alarm_policy_rules']):
            return None

        return self.send_request(action, body)
Пример #48
0
    def describe_s2_groups(self,
                           s2_groups=None,
                           group_types=None,
                           group_name=None,
                           search_word=None,
                           verbose=None,
                           offset=None,
                           limit=None,
                           **ignore):
        """ Describe S2 groups

        :param s2_groups: the IDs of s2 groups.
        :param group_types: valid values is NFS_GROUP or SMB_GROUP.
        :param group_name: the name of group.
        :param search_word: you may use this field to search from id or name.
        :param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
        :param offset: the starting offset of the returning results.
        :param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_S2_GROUPS
        valid_keys = [
            's2_groups',
            'group_types',
            'account_name',
            'search_word',
            'verbose',
            'offset',
            'limit',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                integer_params=['offset', 'limit', 'verbose'],
                list_params=['s2_groups', 'group_types'],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #49
0
    def describe_nics(self,
                      nics=None,
                      nic_name=None,
                      status=None,
                      vxnets=None,
                      vxnet_type=None,
                      offset=None,
                      limit=None,
                      **ignore):
        """ Describe nics

        @param nics: the IDs of nic you want to describe.
        @param nic_name: the name of nic.
        @param status: valid values include available, in-use.
        @param vxnets: the IDs of vxnet.
        @param vxnet_type: vxnet type, 0: unmanaged, 1: managed.
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_NICS
        valid_keys = [
            "nics",
            "nic_name",
            "status",
            "vxnets",
            "vxnet_type",
            "offset",
            "limit",
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                integer_params=["offset", "limit"],
                list_params=["nics", "vxnets"],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #50
0
    def describe_instances(self, instances=None,
                           image_id=None,
                           instance_type=None,
                           status=None,
                           owner=None,
                           search_word=None,
                           verbose=0,
                           offset=None,
                           limit=None,
                           tags=None,
                           instance_name=None,
                           **ignore):
        """ Describe instances filtered by conditions
        @param instances : the array of IDs of instances
        @param image_id : ID of the image which is used to launch this instance.
        @param instance_type: The instance type.
                              See: https://docs.qingcloud.com/api/common/includes/instance_type.html
        @param status : Status of the instance, including pending, running, stopped, terminated.
        @param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
        @param search_word: the combined search column.
        @param offset: the starting offset of the returning results.
        @param limit: specify the number of the returning results.
        @param tags : the array of IDs of tags.
        """
        action = const.ACTION_DESCRIBE_INSTANCES
        valid_keys = ['instances', 'image_id', 'instance_type', 'status',
                      'search_word', 'verbose', 'offset', 'limit', 'tags', 'owner','instance_name']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[],
                                                  integer_params=[
                                                      'offset', 'limit', 'verbose'],
                                                  list_params=[
                                                      'instances', 'status', 'tags']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #51
0
    def describe_s2_accounts(self,
                             s2_accounts=None,
                             account_types=None,
                             account_name=None,
                             search_word=None,
                             verbose=None,
                             offset=None,
                             limit=None,
                             **ignore):
        """ Describe S2 accounts

        :param s2_accounts: the IDs of accounts.
        :param account_types: valid values is NFS or SMB.
        :param account_name: the name of account.
        :param search_word: you may use this field to search from id, account_name nfs_ipaddr or smb_name.
        :param verbose: the number to specify the verbose level, larger the number, the more detailed information will be returned.
        :param offset: the starting offset of the returning results.
        :param limit: specify the number of the returning results.
        """
        action = const.ACTION_DESCRIBE_S2_ACCOUNTS
        valid_keys = [
            's2_accounts',
            'account_types',
            'account_name',
            'search_word',
            'verbose',
            'offset',
            'limit',
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                integer_params=["limit", "offset", "verbose"],
                list_params=["s2_accounts", "account_types"],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #52
0
    def modify_loadbalancer_attributes(self, loadbalancer,
                                       security_group=None,
                                       loadbalancer_name=None,
                                       description=None,
                                       **ignore):
        """ Modify load balancer attributes.
        @param loadbalancer: the ID of loadbalancer you want to modify.
        @param security_group: the ID of the security_group.
        @param loadbalancer_name: the name of the loadbalancer.
        @param description: the description of the loadbalancer.
        """
        action = const.ACTION_MODIFY_LOADBALANCER_ATTRIBUTES
        valid_keys = ['loadbalancer', 'security_group', 'loadbalancer_name',
                      'description']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=['loadbalancer'],
                                                  integer_params=[],
                                                  list_params=[]
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #53
0
    def create_s2_group(self,
                        group_type,
                        group_name=None,
                        s2_accounts=None,
                        description=None,
                        **ignore):
        """ Create S2 group

        :param group_type: valid values is NFS_GROUP or SMB_GROUP.
        :param group_name: the name of group.
        :param s2_accounts: the IDs of s2 accounts.
        :param description: the detailed description of the resource.
        """
        action = const.ACTION_CREATE_S2_GROUP
        valid_keys = [
            'group_type',
            'group_name',
            's2_accounts',
            'description',
        ]
        body = filter_out_none(locals(), valid_keys)

        return self.conn.send_request(action, body)
Пример #54
0
    def add_listeners_to_loadbalancer(self,
                                      loadbalancer,
                                      listeners,
                                      target_user=None,
                                      **ignore):
        """ Add listeners to load balancer.
        @param loadbalancer: The ID of loadbalancer.
        @param listeners: the listeners to add.
        @param target_user: ID of user who will own this resource, should be one of your sub-accounts
        """
        action = const.ACTION_ADD_LOADBALANCER_LISTENERS
        valid_keys = ['listeners', 'loadbalancer', 'target_user']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                required_params=['loadbalancer', 'listeners'],
                integer_params=[],
                list_params=['listeners']):
            return None

        self.conn.req_checker.check_lb_listeners(listeners)

        return self.conn.send_request(action, body)
Пример #55
0
    def resize_s2_servers(self,
                          s2_servers,
                          s2_server_type,
                          **ignore):
        """ Resize S2 servers

        :param s2_servers: the IDs of s2 servers you want to resize.
        :param s2_server_type: valid values includes 0, 1, 2, 3.
        """
        action = const.ACTION_RESIZE_S2_SERVERS
        valid_keys = [
            's2_servers', 's2_server_type'
        ]
        body = filter_out_none(locals(), valid_keys)

        if not self.conn.req_checker.check_params(
                body,
                integer_params=['s2_server_type'],
                list_params=['s2_servers'],
        ):
            return None

        return self.conn.send_request(action, body)
Пример #56
0
    def modify_instance_attributes(self, instance,
                                   instance_name=None,
                                   description=None,
                                   nic_mqueue=None,
                                   **ignore):
        """ Modify instance attributes.
        @param instance:  the ID of instance whose attributes you want to modify.
        @param instance_name: Name of the instance. It's a short name for the instance
        that more meaningful than instance id.
        @param nic_mqueue: Enable or disable multiqueue.
        @param description: The detailed description of the resource.
        """
        action = const.ACTION_MODIFY_INSTANCE_ATTRIBUTES
        valid_keys = ['instance', 'instance_name', 'description', 'nic_mqueue']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=['instance'],
                                                  integer_params=['nic_mqueue'],
                                                  list_params=[]
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #57
0
    def add_cluster_nodes(self,
                          cluster,
                          node_count,
                          owner=None,
                          node_name=None,
                          node_role=None,
                          resource_conf=None,
                          **params):
        """ Add one or more cluster nodes
        """
        action = const.ACTION_ADD_CLUSTER_NODES
        valid_keys = [
            'cluster', 'node_count', 'owner', 'node_name', 'node_role',
            'resource_conf'
        ]
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                required_params=['cluster', 'node_count'],
                integer_params=['node_count']):
            return None

        return self.conn.send_request(action, body)
Пример #58
0
    def resize_cluster(self,
                       cluster,
                       node_role=None,
                       cpu=None,
                       memory=None,
                       storage_size=None,
                       **ignore):
        """ Resize cluster
        @param cluster: the ID of the cluster you want to resize.
        @param cpu: cpu core number.
        @param memory: memory size in MB.
        @param storage_size: The new larger size of the storage_size, unit is GB.
        """
        action = const.ACTION_RESIZE_CLUSTER
        valid_keys = ['cluster', 'node_role', 'cpu', 'memory', 'storage_size']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(
                body,
                required_params=['cluster'],
                integer_params=['cpu', 'memory']):
            return None

        return self.conn.send_request(action, body)
Пример #59
0
    def run_instances_by_configuration(self, launch_configuration,
                                       instance_name='',
                                       count=1,
                                       volumes=None,
                                       **ignore):
        """ Run one or more instances by launch configuration.
        @param launch_configuration: ID of launch configuration you want to use
        @param instance_name: a meaningful short name of instance.
        @param count : The number of instances to launch, default 1.
        @param volumes: the ids of volumes will be attached.
        """
        action = const.ACTION_RUN_INSTANCES_BY_CONFIGURATION
        valid_keys = ['launch_configuration', 'instance_name', 'count', 'volumes']
        body = filter_out_none(locals(), valid_keys)
        if not self.conn.req_checker.check_params(body,
                                                  required_params=[
                                                      'launch_configuration'],
                                                  integer_params=['count'],
                                                  list_params=['volumes']
                                                  ):
            return None

        return self.conn.send_request(action, body)
Пример #60
0
 def apply_security_group(self,
                          security_group,
                          instances=None,
                          target_user=None,
                          **ignore):
     """ Apply a security group with current rules.
     If `instances` specified, apply the security group to them,
     or will affect all instances that has applied this security group.
     @param security_group: the ID of the security group that you
     want to apply to instances.
     @param instances: the IDs of the instances you want to apply the security group.
     @param target_user: ID of user who will own this resource, should be one of your sub-accounts
     """
     action = const.ACTION_APPLY_SECURITY_GROUP
     valid_keys = ['security_group', 'instances', 'target_user']
     body = filter_out_none(locals(), valid_keys)
     if not self.conn.req_checker.check_params(
             body,
             required_params=['security_group'],
             integer_params=[],
             list_params=['instances']):
         return None
     return self.conn.send_request(action, body)