def create_tag(self, name, description=None, servers=[]): """ Create a new Tag. Only name is mandatory. Returns the created Tag object. """ servers = [str(server) for server in servers] body = {'tag': Tag(name, description, servers).to_dict()} res = self.request('POST', '/tag', body) return Tag(cloud_manager=self, **res['tag'])
def create_tag(self, name, description=None, servers=[]): tag = {"name": name} if description: tag["description"] = description if servers: tag["servers"] = servers return Tag(cloud_manager=self, **tag)
def _modify_tag(self, name, description, servers, new_name): """ PUT /tag/name. Returns a dict that can be used to create a Tag object. Private method used by the Tag class and TagManager.modify_tag. """ body = Tag._prepare_tag_body(new_name, description, servers) res = self.request('PUT', '/tag/' + name, body) return res['tag']
def _modify_tag(self, name, description, servers, new_name): """ PUT /tag/name. Returns a dict that can be used to create a Tag object. Private method used by the Tag class and TagManager.modify_tag. """ body = {'tag': Tag(new_name, description, servers).to_dict()} res = self.request('PUT', '/tag/' + name, body) return res['tag']
def create_tag(self, name, description=None, servers=[]): """ Create a new Tag. Only name is mandatory. Returns the created Tag object. """ servers = [str(server) for server in servers] body = Tag._prepare_tag_body(name, description, servers) res = self.request('POST', '/tag', body) return Tag(cloud_manager=self, **res['tag'])
def test_assign_tags_to_server(self, manager): data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531') server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531') responses.add( responses.POST, Mock.base_url + '/server/00798b85-efdc-41ca-8021-f6ef457b8531/tag/tag1,tag2', body=json.dumps({'foo': 'bar'}), content_type='application/json', status=200) server.add_tags(['tag1', Tag('tag2')]) for tag in ['web1', 'tag1', 'tag2']: assert tag in server.tags
def modify_tag(self, name, description=None, servers=None, new_name=None): """ PUT /tag/name. Returns a new Tag object based on the API response. """ res = self._modify_tag(name, description, servers, new_name) return Tag(cloud_manager=self, **res['tag'])
def get_tag(self, name): """Return the tag as Tag object.""" res = self.get_request('/tag/' + name) return Tag(cloud_manager=self, **res['tag'])
def get_tags(self): """List all tags as Tag objects.""" res = self.get_request('/tag') return [Tag(cloud_manager=self, **tag) for tag in res['tags']['tag']]
FirewallRule( position='1', direction='in', family='IPv4', protocol='tcp', source_address_start='192.168.1.1', source_address_end='192.168.1.255', destination_port_start='22', destination_port_end='22', action='accept' ), FirewallRule( position='2', direction='in', family='IPv4', protocol='tcp', source_address_start='192.168.1.1', source_address_end='192.168.1.255', destination_port_start='21', destination_port_end='21', action='accept' ) ] TAGS = [ Tag('testlb'), Tag('testdb'), Tag('testweb') ]
password_delivery='none', storage_devices=[Storage(os='Debian 10.0', size=30)], login_user=login_user_block( 'testuser', ['ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x [email protected]'], True), ) } FIREWALL_RULES = [ FirewallRule(position='1', direction='in', family='IPv4', protocol='tcp', source_address_start='192.168.1.1', source_address_end='192.168.1.255', destination_port_start='22', destination_port_end='22', action='accept'), FirewallRule(position='2', direction='in', family='IPv4', protocol='tcp', source_address_start='192.168.1.1', source_address_end='192.168.1.255', destination_port_start='21', destination_port_end='21', action='accept') ] TAGS = [Tag('testlb'), Tag('testdb'), Tag('testweb')]
def get_tags(self): data = self.read_json_data("tag") return [Tag(cloud_manager=self, **tag) for tag in data["tags"]["tag"]]